GitHub released its new CI/CD platform called ""Actions"" on the 13th of November this year. Since then it was rumored to be the ""be-all, end-all"" of build automation tools for open source developers.
In this talk we'll look at what GitHub Actions offers us as a maintainer of an OSS project, what benefits (and drawbacks?) it has compared to established platforms such as AppVeyor, TravisCI, CircleCI, and how easy (or hard?) is it to get started today.
We'll also take a look at how you can author your own custom automation scenarios (i.e. actions) to create complex pipelines and see how that helps with maintainability.
3. GitHub Actions at a glance
• Globally available since November 13, 2019
• Based on Azure Pipelines
• Native integration with GitHub API
• YAML-based configuration
• Modular architecture & community-driven
• Runners on Windows, Linux, macOS, or self-hosted
• Available with Free, Pro, Team, Enterprise Cloud, One
Speaker: Alexey Golub @Tyrrrz
4. Product Storage Minutes
(monthly)
GitHub Free 500 MB 2,000
GitHub Pro 1 GB 3,000
GitHub Team 2 GB 10,000
GitHub Enterprise Cloud 50 GB 50,000
Speaker: Alexey Golub @Tyrrrz
Free! ✨
Operating
system
Minute
multiplier
Windows 2
Linux 1
macOS 10
Private repositoriesPublic repositories
Operating
system
Per-minute
rate
Windows $0.016
Linux $0.008
macOS $0.080
6. Speaker: Alexey Golub @Tyrrrz
Add positional arguments (fixes #26)
Use ValueTask in ICommand
Include shared props file
Add support for autocompletion
How can I implement a custom converter?
Add required options to help text
Trigger CI build
Label issue
Tag reviewers
Released v1.7.2 Post a message in Slack
EVENT
EVENT
EVENT
EVENT
13. Triggers
• GitHub API events ⚡
push, pull_request, issues, release, and 20 others
• Schedule 🕒
Cron syntax, e.g.: */15 * * * *
• Manual 🌐️
POST to /repos/:owner/:repo/dispatches
Speaker: Alexey Golub @Tyrrrz
14. Speaker: Alexey Golub @Tyrrrz
# Trigger on push events on
specific branches
on:
push:
branches:
- 'master'
- 'release/*'
# Trigger every midnight UTC
on:
schedule:
- cron: '0 0 * * *'
# Trigger on manual dispatch
on: repository_dispatch
# Trigger when an issue is opened
or labeled
on:
issues:
types: [opened, labeled]
15. Referencing actions
• By GitHub repository 📚
{owner}/{repo}@{ref} john/cleanup-action@master
{owner}/{repo}/{path}@{ref} myorg/actions/push-image@v1
• By file path 📁
./path/to/dir ./.github/actions/my-action
• By Docker image 🐳
docker://{image}:{tag} docker://hello-world:latest
Speaker: Alexey Golub @Tyrrrz
18. Docker containers
Speaker: Alexey Golub @Tyrrrz
jobs:
build:
services:
redis:
image: redis
ports:
- 6379/tcp
options: --entrypoint redis-server
steps:
env:
REDIS_HOST: localhost
REDIS_PORT: ${{ job.services.redis.ports[6379] }}
Image from the Docker registry
Bind port 6379 in container to a random port on host
Exposed port is resolved dynamically
Custom arguments passed to docker create
22. Action to action I/O
Speaker: Alexey Golub @Tyrrrz
- name: Create release
id: create_release
uses: actions/create-release@v1
- name: Upload release asset
uses: actions/upload-release-asset@v1.0.1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
Actions can be referenced by their ID
Resolved from the outputs of another action
24. Running workflows locally
Speaker: Alexey Golub @Tyrrrz
📚 nektos/act
- Can replicate the exact GitHub Actions
virtual environment
- Simulates events with custom
payloads
- Supports secrets, environment
variables, etc.
- Only works with Ubuntu-based jobs
(for now)
25. GitHub Actions enables us to…
• Run build & tests on every commit
• Publish Docker image when a tag is pushed
• Label an issue by content when it’s created
• Run nightly E2E tests
• Automatically close issues or PRs without activity
• Automatically format code on push
• Integrate with various third-party services
• …
Speaker: Alexey Golub @Tyrrrz
32. Action you need doesn’t exist?
Write it yourself!
Speaker: Alexey Golub @Tyrrrz
33. JavaScript-based actions
• Supported by all runners
• Can only use JavaScript
• Requires a single self-contained .js file as the entry point
• Built-in modules @actions/core & @actions/github
Speaker: Alexey Golub @Tyrrrz
action.yml index.js
+
34. Speaker: Alexey Golub @Tyrrrz
name: 'Hello World'
description: 'Greet someone and record time'
inputs:
who-to-greet:
description: 'Who to greet'
required: true
default: 'World'
outputs:
time:
description: 'The time we greeted you'
runs:
using: 'node12'
main: 'index.js'
~/action.yml
Metadata associated with an action
Inputs & outputs
Entry point
35. Speaker: Alexey Golub @Tyrrrz
const core = require('@actions/core');
const github = require('@actions/github');
try {
// `who-to-greet` input defined in action metadata file
const nameToGreet = core.getInput('who-to-greet');
console.log(`Hello ${nameToGreet}!`);
const time = (new Date()).toTimeString();
core.setOutput("time", time);
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
~/index.js
36. Docker-based actions
• Supported only by Linux-based runners (for now)
• Can use any language or runtime
• Typically runs slower
Speaker: Alexey Golub @Tyrrrz
action.yml Dockerfile
+
37. Speaker: Alexey Golub @Tyrrrz
name: 'Hello World'
description: 'Greet someone and record time'
inputs:
who-to-greet:
description: 'Who to greet'
required: true
default: 'World'
outputs:
time:
description: 'The time we greeted you'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.who-to-greet }}
~/action.yml
FROM ubuntu:18.04
COPY entrypoint.sh ./
ENTRYPOINT ["/entrypoint.sh"]
~/Dockerfile
#!/bin/sh -l
echo "Hello $1"
time=$(date)
echo #:set-output name=time#:$time
~/entrypoint.sh
41. Summary
• GitHub Actions is an automation platform (not just CI/CD)
• Workflows can be triggered on various API events
• Workflows can also be triggered on schedule or on demand
• Actions are building blocks sourced by the community
• Custom actions can be written in JS or using Docker
• Simple to configure & easy to get started
• Free for all public repos & pay-as-you-go for private repos
Speaker: Alexey Golub @Tyrrrz
42. For the curious
• Awesome Actions by Sarah Drasner
https://github.com/sdras/awesome-actions
• GitHub Actions Advent Calendar by Edward Thomson
https://edwardthomson.com/blog/github_actions_advent_calendar.html
• Comprehensive Introduction to GitHub Actions by Tierney Cyren
https://dev.to/bnb/an-unintentionally-comprehensive-introduction-to-
github-actions-ci-blm
• Official documentation
https://help.github.com/en/actions
Speaker: Alexey Golub @Tyrrrz