build: use self-hosted runner for tests #379
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "tests" | |
on: | |
# I don't think it's important for correctness to run the tests on main. | |
# I'm doing it to make GitHub Actions caches available across pull requests. | |
# See https://github.com/LightAndLight/ipso/issues/338 | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
env: | |
# Avoid [rate | |
# limiting](https://discourse.nixos.org/t/flakes-provide-github-api-token-for-rate-limiting/18609) | |
# by allowing Nix to make authenticated GitHub requests. | |
NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" | |
jobs: | |
tests: | |
runs-on: nixos | |
steps: | |
- uses: actions/[email protected] | |
with: | |
# `./scripts/recheck` uses `git diff` which accesses the repo's history. `fetch-depth: 0` fetches all branches and history. | |
fetch-depth: 0 | |
- name: Run tests (pull request) | |
if: github.event_name == 'pull_request' | |
run: | | |
nix build .#test-package --option post-build-hook "$RUNNER_TEMP/postBuildHook-$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER" | |
export CARGO_HOME=$STATE_DIRECTORY/.cargo | |
export CARGO_TARGET_DIR=$(realpath --relative-to "$PWD" $STATE_DIRECTORY/target) | |
nix develop .#tests \ | |
--post-build-hook "$RUNNER_TEMP/postBuildHook-$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER" \ | |
-c ./scripts/recheck origin/$GITHUB_BASE_REF $GITHUB_REF_NAME | |
# `tests.yml` is currently set to run on pushes to `main`. When that happens, `$GITHUB_BASE_REF` | |
# isn't set because it's not a pull request. Instead we use the most recent commit before the | |
# push | |
# (https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#push) | |
# as the "old" commit for `./scripts/recheck`. | |
# | |
# If it's a force push (which it really shouldn't be for main) then we skip this step. | |
- name: Run tests (push) | |
if: github.event_name == 'push' && !github.event.forced | |
run: > | |
nix develop .#tests | |
--post-build-hook "$RUNNER_TEMP/postBuildHook-$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER" | |
-c ./scripts/recheck ${{ github.event.before }} $GITHUB_REF_NAME | |
- name: Wait for uploads to finish | |
# This used to be always(), which can't be cancelled: <https://github.com/orgs/community/discussions/26303> | |
if: ${{ !cancelled() }} | |
run: pueue log --json | jq '.[].task | select(.label == "'$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER'") | .id' | xargs -r pueue wait | |
- name: Log all uploads | |
if: ${{ !cancelled() }} | |
run: pueue log --json | jq 'select(.[].task.label == "'$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER'") | .[].task.original_command' -r | |
- name: Log failed uploads | |
if: ${{ !cancelled() }} | |
run: pueue log --json | jq 'select(.[].task.label == "'$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER'") | to_entries[] | select(.value.task.status.Done != "Success") | .key' -r | xargs -r pueue log | |
- name: Check uploads succeeded | |
if: ${{ !cancelled() }} | |
run: "[ \"$(pueue log --json | jq 'select (.[].task.label == \"'$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER'\") | to_entries[] | select(.value.task.status.Done != \"Success\") | .key' -r)\" == \"\" ]" |