brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gh run watch with an exit status waits for a workflow and fails when it fails

CLI
~/tips/tip-cli-gh-run-watch-exit-status

gh run watch --exit-status

Follows a running Actions workflow in the terminal and returns its result.

After a push it’s tempting to keep a browser tab open on the Actions page and refresh it. gh run watch follows the run in the terminal instead.

Run it inside the repository. Without a run ID it lets you pick one of the runs in progress, then shows each job and step as it moves along:

gh run watch --exit-status

--exit-status is the part that makes it useful in scripts. Normally the command exits 0 when the run ends, whatever the result. With the flag it exits non-zero when the run failed, so you can chain the next step:

id=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
gh run watch "$id" --exit-status --compact && ./deploy.sh

--compact shows only the relevant or failed steps, which keeps the screen calm for workflows with many steps. -i changes the refresh interval from the default of 3 seconds.

I like ending it with a notification command, so you can look at something else and still hear when the build is done.

The help notes that it does not work with fine grained personal access tokens, because those can’t get the checks permission it needs. A classic token or the normal gh auth login works. Picking the latest run with gh run list can also grab a run from another branch or workflow, so add --branch or --workflow when the repository is busy.

Further reading: gh run watch (GitHub CLI manual), gh run list (GitHub CLI manual)

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link