https://docs.github.com/actions
Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you'd like, including CI/CD, and combine actions in a completely customized workflow.
Github Actions are open-ended workflows you can run from repositories. A common use case is CICD.
Most of the minutiae is in here: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
Tips and Tricks
Triggering workflows based on subdirectory changes
You can use on.push.paths
and associated keywords to filter on changes within a particular path. You can also use path-ignore
, which would be for changes anywhere except an ignored path.
You must pay attention to glob patterns if you want to correctly match file paths to patterns. For example, if you only want to run tests when the sub/
folder has changed, no matter how deeply nested the files, you need to match against sub/**
.
on:
push:
paths:
- 'sub/**'
It also seems important to use single quotes and not double quotes. I haven't confirmed why but I suspect it's a yaml thing.
Workflows
Triggers
Workflow triggers begin with on
in the yaml file. It can be as simple as on: push
or can be more complex, such as triggering on particular branch PRs. The example below would trigger on pushes to main
and on pull requests targeting main
.
on:
push:
branches: main
pull_request:
branches: main
Triggering jobs from other jobs
Use jobs.<job_id>.needs to have job b
run only after the success of job a
.
jobs:
test:
deploy:
needs: test
Triggering workflows from other workflows
Use on: workflow_run
. The example below runs every time the 'Run Tests' workflow completes regardless of success or failure.
on:
workflow_run:
workflows:
- Run Tests
types:
- completed
To run a workflow conditioned on the success of the previous workflow, checking the previous workflow's conclusion outcome,
on:
workflow_run:
workflows:
- Build
types:
- completed
jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: echo 'The triggering workflow passed'
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo 'The triggering workflow failed'