CI: scratch directories per run, not per commit
Test and publish / test (push) Successful in 22s
Test and publish / publish (push) Successful in 25s
Test and publish / deploy (push) Successful in 0s

The build runner takes two jobs at once, so the same commit pushed to
two branches (main and a feature branch) ran its test job twice in
parallel against one src-<sha> directory, and each run's clean-up
deleted the other's source mid-test. Suffix the scratch directories
(and activity-tracker's throwaway Postgres and network) with the run id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:14:44 +00:00
co-authored by Claude Opus 5.5
parent 0c54e01106
commit a5fabc02d6
+13 -9
View File
@@ -37,12 +37,16 @@ jobs:
env: env:
SHA: ${{ github.sha }} SHA: ${{ github.sha }}
REF: ${{ github.ref }} REF: ${{ github.ref }}
# Names this run's Postgres and network (see SRC below).
RUN: ${{ github.run_id }}
# Over HTTP with the job's own token (read access to this repo while # Over HTTP with the job's own token (read access to this repo while
# the job runs), so the runner needs no SSH key or Gitea user. # the job runs), so the runner needs no SSH key or Gitea user.
REMOTE: http://git.adam-french.co.uk:3000/adamf/ccp.git REMOTE: http://git.adam-french.co.uk:3000/adamf/ccp.git
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git
SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }} # Per run, not just per commit: the build runner takes two jobs at
# once, and the same commit pushed to two branches runs twice.
SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }}-${{ github.run_id }}
steps: steps:
- name: Export the pushed commit to a scratch directory - name: Export the pushed commit to a scratch directory
shell: bash shell: bash
@@ -67,14 +71,14 @@ jobs:
shell: bash shell: bash
run: | run: |
set -eu set -eu
docker network create "ci-$SHA" docker network create "ci-$RUN"
docker run -d --name "ci-pg-$SHA" --network "ci-$SHA" --network-alias pg \ docker run -d --name "ci-pg-$RUN" --network "ci-$RUN" --network-alias pg \
-e POSTGRES_PASSWORD=ci postgres:17 -e POSTGRES_PASSWORD=ci postgres:17
for i in $(seq 1 30); do for i in $(seq 1 30); do
docker exec "ci-pg-$SHA" pg_isready -U postgres -h localhost && exit 0 docker exec "ci-pg-$RUN" pg_isready -U postgres -h localhost && exit 0
sleep 1 sleep 1
done done
docker logs "ci-pg-$SHA" docker logs "ci-pg-$RUN"
exit 1 exit 1
# Read-only source, and named volumes for the module and build # Read-only source, and named volumes for the module and build
@@ -90,7 +94,7 @@ jobs:
-v "$SRC":/src:ro -w /src \ -v "$SRC":/src:ro -w /src \
-v activity_tracker_ci_gomod:/go/pkg/mod \ -v activity_tracker_ci_gomod:/go/pkg/mod \
-v activity_tracker_ci_gobuild:/root/.cache/go-build \ -v activity_tracker_ci_gobuild:/root/.cache/go-build \
--network "ci-$SHA" \ --network "ci-$RUN" \
-e TEST_DATABASE_URL='postgres://postgres:ci@pg:5432/postgres?sslmode=disable' \ -e TEST_DATABASE_URL='postgres://postgres:ci@pg:5432/postgres?sslmode=disable' \
golang:1.27 \ golang:1.27 \
sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -count=1 ./...' sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -count=1 ./...'
@@ -112,8 +116,8 @@ jobs:
shell: bash shell: bash
run: | run: |
rm -rf "$SRC" rm -rf "$SRC"
docker rm -f "ci-pg-$SHA" || true docker rm -f "ci-pg-$RUN" || true
docker network rm "ci-$SHA" || true docker network rm "ci-$RUN" || true
publish: publish:
needs: test needs: test
@@ -122,7 +126,7 @@ jobs:
env: env:
SHA: ${{ github.sha }} SHA: ${{ github.sha }}
CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git
SRC: /home/adamf/.cache/activity-tracker-ci/publish-${{ github.sha }} SRC: /home/adamf/.cache/activity-tracker-ci/publish-${{ github.sha }}-${{ github.run_id }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
steps: steps: