Debug Github Actions with act
Leave a project’s unconstrained CI workflow unattended for long enough and it will start failing…
I find myself once again discovering that the Deluge project’s CI pipeline is in an inexplicably broken state. It has been several months since I last checked in on GitHub Actions but it seemed like the pytest run was stalling until the job timed-out or manually cancelled. With no readily available error output and pytest running fine locally this was rather puzzling.
I thought about setting up an GitHub Action via SSH session or perhaps enabling debug logging. However I saw this as a good opportunity to try act that enables running GitHub Actions locally. It would be useful here to enable faster iteration of any changes locally than on GitHub servers.
Setup⌗
Installing act
is straightforward: https://github.com/nektos/act#installation
To get setup run the act
list jobs command:
act -l
The first run of act
will request which Docker image size to use. Since this is a Python project I picked medium.
Run job⌗
act -j test-linux
Disable cache service⌗
The main issue I ran into was a failure to setup the cache service with the job stopping with this error:
"::error::Cache service responded with 404".
I was looking for a quick way to resolve this issue so temporarily added the following to disable cache when using act
:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- cache: "pip"
+ cache: ${{ !env.ACT && 'pip' || ''}}
cache-dependency-path: "requirements*.txt"
Further details on cache issue: https://github.com/nektos/act/issues/1034
Docker shell⌗
To debug the stalled job directly you can open a bash shell to the running container:
docker exec -it act-CI-test-linux bash
The installed python version is located here:
/opt/hostedtoolcache/Python/3.10.8/x64/bin/python
All commands to run pip
or pytest
require using this version of python.
Conclusion⌗
Thanks to act
I was able to quickly track down the stalling tests issue. The result of test code being unable to find Deluge distribution resource files. This was caused by new releases of setuptools
and pip
that deprecated legacy editable installs.
Using act is not ideal, it’s rather fragile with Github Actions and I will only be using it for debugging workflows rather than as a frequent local runner. The more poignant takeaway is that pinning your dependencies will avoid untimely surprises. Oh and update fragile, legacy code sooner than later!
This post was inspired by https://blog.harshcasper.com/debugging-github-actions-workflows-effectively