Last week, somewhere I recall someone (maybe @kzantow ) suggesting that there might be use in being able to iterate on, and debug GitHub actions locally, rather than wait for the GitHub runners. I suspect this was in the context of a bug, but this weekโs brain has swapped out last weeks context, sorry.
Anyway, I just stumbled on act which may be of use. Itโs a tool written in Go which does pretty much what you expect. It leverages your local Docker setup to spin up GHA-like containers in which to run the actions.
As a test I grabbed sbom-action to give it a shake. Iโm using an M1 mac, so it recommended I add the --container-architecture linux/amd64
and pointed it at the test.yml
action, thus:
act -W ./.github/workflows/test.yml --container-architecture linux/amd64
Any of you lot tried this before? Itโs super quick (on my M3 Pro), feels pretty handy, and could speed up some iteration, assuming the tests work locally in docker.
Hereโs the top of the output:
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
[build-test/build ] ๐ Start image=catthehacker/ubuntu:act-latest
[build-test/test-as-action ] ๐ Start image=catthehacker/ubuntu:act-latest
[build-test/test ] ๐ Start image=catthehacker/ubuntu:act-latest
[build-test/test-on-fixture-dirs-2] ๐ง Skipping unsupported platform -- Try running with `-P ubuntu-latest=...`
[build-test/test-on-fixture-dirs-1] ๐ Start image=catthehacker/ubuntu:act-latest
[build-test/build ] ๐ณ docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[build-test/test-as-action ] ๐ณ docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[build-test/test-on-fixture-dirs-1] ๐ณ docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[build-test/test ] ๐ณ docker pull image=registry:2 platform=linux/amd64 username= forcePull=true
[build-test/test ] ๐ณ docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[build-test/build ] ๐ณ docker create image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
Hereโs the bottom of the output:
| PASS tests/integration/GitHubSnapshot.test.ts
| GitHub Snapshot
| โ runs with default inputs (272 ms)
|
----------------------|---------|----------|---------|---------|---------------------------------------------------------------------------------------------------
| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
| ----------------------|---------|----------|---------|---------|---------------------------------------------------------------------------------------------------
| All files | 88.11 | 75 | 91.42 | 88.33 |
| src | 100 | 100 | 100 | 100 |
| SyftVersion.ts | 100 | 100 | 100 | 100 |
| src/github | 86 | 72.32 | 89.47 | 86.3 |
| Executor.ts | 100 | 100 | 100 | 100 |
| GithubClient.ts | 82.03 | 54.16 | 89.28 | 82.25 | 107-111,157,168-169,305,384,388-389,419-420,447,454-457,477-490
| SyftGithubAction.ts | 87.89 | 77.27 | 92 | 88.18 | 65-66,124,134,148,193-194,205-210,220,246-247,289-290,420,429,433-436,509,535,545-546,563,590-593
| Util.ts | 66.66 | 100 | 0 | 66.66 | 4
| tests | 96.8 | 90 | 93.75 | 96.73 |
| mocks.ts | 96.8 | 90 | 93.75 | 96.73 | 90,155,208
| ----------------------|---------|----------|---------|---------|---------------------------------------------------------------------------------------------------
| Test Suites: 1 failed, 3 passed, 4 total
| Tests: 12 failed, 37 passed, 49 total
| Snapshots: 9 passed, 9 total
| Time: 18.588 s
| Ran all test suites.
[build-test/test ] โ Failure - Main npm test
[build-test/test ] โ ::set-env:: ANCHORE_SBOM_ACTION_PRIOR_ARTIFACT=test-repo-a_job.cyclonedx.json
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] โ ::add-path:: /tmp/actions/cache/syft/1.9.0/x64
[build-test/test ] exitcode '1': failure
[build-test/test ] ๐ Job failed
A useful tool for the armoury? Anyone else tried this?
(I did have to patch the workflow I used above, because port 5000 is in use by some macOS thing):
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 89aae24..48e53a9 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -62,14 +62,14 @@ jobs:
registry:
image: registry:2
ports:
- - 5000:5000
+ - 5001:5000
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Build images
run: |
for distro in alpine centos debian; do
- docker build -t localhost:5000/match-coverage/$distro ./tests/fixtures/image-$distro-match-coverage
- docker push localhost:5000/match-coverage/${distro}:latest
+ docker build -t localhost:5001/match-coverage/$distro ./tests/fixtures/image-$distro-match-coverage
+ docker push localhost:5001/match-coverage/${distro}:latest
done
- run: npm ci
- run: npm test