|
| 1 | +# GitHub Action Tests |
| 2 | + |
| 3 | +This directory contains necessary files to allow local testing of GitHub Actions workflows, composite actions, etc. You will need to install [act](https://github.com/nektos/act) to perform tests. |
| 4 | + |
| 5 | +## Workflow tests |
| 6 | + |
| 7 | +Trigger specific workflow files by specifying their full path: |
| 8 | + |
| 9 | +``` |
| 10 | +act -W .github/workflow/release.yml |
| 11 | +``` |
| 12 | + |
| 13 | +You will likely need to override any custom runners we use, e.g. buildjet. For example: |
| 14 | + |
| 15 | +``` |
| 16 | +override=catthehacker/ubuntu:act-latest |
| 17 | +
|
| 18 | +act -W .github/workflow/release.yml \ |
| 19 | + -P buildjet-8vcpu-ubuntu-2204=$override |
| 20 | +
|
| 21 | +# override multiple images at the same time |
| 22 | +act -W .github/workflow/release.yml \ |
| 23 | + -P buildjet-8vcpu-ubuntu-2204=$override \ |
| 24 | + -P buildjet-16vcpu-ubuntu-2204=$override |
| 25 | +``` |
| 26 | + |
| 27 | +Trigger with specific event payloads to test pushing to branches or tags: |
| 28 | + |
| 29 | +``` |
| 30 | +override=catthehacker/ubuntu:act-latest |
| 31 | +
|
| 32 | +# simulate push to main |
| 33 | +act -W .github/workflow/publish.yml \ |
| 34 | + -P buildjet-8vcpu-ubuntu-2204=$override \ |
| 35 | + -P buildjet-16vcpu-ubuntu-2204=$override \ |
| 36 | + -e .github/events/push-tag-main.json |
| 37 | +
|
| 38 | +# simulate a `build-` prefixed tag |
| 39 | +act -W .github/workflow/publish.yml \ |
| 40 | + -P buildjet-8vcpu-ubuntu-2204=$override \ |
| 41 | + -P buildjet-16vcpu-ubuntu-2204=$override \ |
| 42 | + -e .github/events/push-tag-buld.json |
| 43 | +``` |
| 44 | + |
| 45 | +By default, `act` will send a push event. To trigger a different event: |
| 46 | + |
| 47 | +``` |
| 48 | +# basic syntax |
| 49 | +act <EVENT> ... |
| 50 | +
|
| 51 | +# simulate a pull request |
| 52 | +act pull_request |
| 53 | +
|
| 54 | +# only trigger a specific workflow |
| 55 | +act pull_request -W .github/workflow/pr_checks.yml |
| 56 | +``` |
| 57 | + |
| 58 | +## Composite action tests |
| 59 | + |
| 60 | +The composite (custom) action tests can be run by triggering the `test-actions` workflow: |
| 61 | + |
| 62 | +``` |
| 63 | +act -W .github/test/test-actions.yml |
| 64 | +``` |
| 65 | + |
| 66 | +## Helpful flags |
| 67 | + |
| 68 | +- `--pull=false` - perform fully offline tests if all images are already present |
| 69 | +- `-j <job_name>` - run the specified job only |
| 70 | +- `-l push` - list all workflows with push triggers |
0 commit comments