Skip to content

Commit 52c7956

Browse files
author
Release Manager
committed
gh-36117: run GitHub actions locally using gh act document how to run GitHub actions locally using `gh` and `docker` `gh` has an extension called `act`, which allows to run Actions locally (subject to the usual Docker restrictions, e.g. no macOS on Linux) Still it's very useful, e.g. for debugging purposes. URL: #36117 Reported by: Dima Pasechnik Reviewer(s): Dima Pasechnik, Kwankyu Lee, Matthias Köppe, Tobias Diez
2 parents 5f56ed5 + 6a6e5ec commit 52c7956

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/doc/en/developer/github.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ and check::
7373

7474
which will show the default repo along with its readme, which is quite long.
7575

76+
``gh`` extensions
77+
-----------------
78+
79+
``gh`` is extendable; e.g. a useful extension to ``gh`` allows testing of
80+
Sage's GitHub Actions locally, using Docker. It is called ``act`` and can be
81+
installed by running::
82+
83+
[alice@localhost sage]$ gh extension install https://github.com/nektos/gh-act
84+
85+
Append ``--force`` flag to the command above to force an upgrade of the extension.
86+
More details on configuring and using ``gh act`` are in :ref:`chapter-portability_testing`.
87+
7688

7789
Linking Git to your GitHub account
7890
==================================

src/doc/en/developer/portability_testing.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,58 @@ are available:
11521152
ptest`` has not been run yet.
11531153

11541154

1155+
Testing GitHub Actions locally
1156+
==============================
1157+
1158+
`act <https://github.com/nektos/act>`_ is a tool, written in Go, and using Docker,
1159+
to run GitHub Actions locally; in particular, it speeds up developing Actions.
1160+
We recommend using ``gh extension`` facility to install ``act``. ::
1161+
1162+
[alice@localhost sage]$ gh extension install https://github.com/nektos/gh-act
1163+
1164+
Extra steps needed for configuration of Docker to run Actions locally can be found on
1165+
`act's GitHub <https://github.com/nektos/act>`_
1166+
1167+
Here we give a very short sampling of ``act``'s capabilities. If you installed standalone
1168+
``act``, it should be invoked as ``act``, not as ``gh act``.
1169+
After the set up, one can e.g. list all the available linting actions::
1170+
1171+
[alice@localhost sage]$ gh act -l | grep lint
1172+
0 lint-pycodestyle Code style check with pycodestyle Lint lint.yml push,pull_request
1173+
0 lint-relint Code style check with relint Lint lint.yml push,pull_request
1174+
0 lint-rst Validate docstring markup as RST Lint lint.yml push,pull_request
1175+
[alice@localhost sage]$
1176+
1177+
run a particular action ``lint-rst`` ::
1178+
1179+
[alice@localhost sage]$ gh act -j lint-rst
1180+
...
1181+
1182+
and so on.
1183+
1184+
By default, ``act`` pulls all the data needed from the next, but it can also cache it,
1185+
speeding up repeated runs quite a lot. The following repeats running of ``lint-rst`` using cached data::
1186+
1187+
[alice@localhost sage]$ gh act -p false -r -j lint-rst
1188+
[Lint/Validate docstring markup as RST] Start image=catthehacker/ubuntu:act-latest
1189+
...
1190+
| rst: commands[0] /home/alice/work/software/sage/src> flake8 --select=RST
1191+
| rst: OK (472.60=setup[0.09]+cmd[472.51] seconds)
1192+
| congratulations :) (474.10 seconds)
1193+
...
1194+
[Lint/Validate docstring markup as RST] Success - Main Lint using tox -e rst
1195+
[Lint/Validate docstring markup as RST] Run Post Set up Python
1196+
[Lint/Validate docstring markup as RST] docker exec cmd=[node /var/run/act/actions/actions-setup-python@v4/dist/cache-save/index.js] user= workdir=
1197+
[Lint/Validate docstring markup as RST] Success - Post Set up Python
1198+
[Lint/Validate docstring markup as RST] Job succeeded
1199+
1200+
Here ``-p false`` means using already pulled Docker images, and ``-r`` means do not remove Docker images
1201+
after a successful run which used them. This, and many more details, can be found by running ``gh act -h``, as well
1202+
as reading ``act``'s documentation.
1203+
1204+
.. This sectuion is a stub.
1205+
More Sage-specfic details for using ``act`` should be added. PRs welcome!
1206+
11551207
Using our pre-built Docker images for development in VS Code
11561208
============================================================
11571209

0 commit comments

Comments
 (0)