diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 80c41c2..f55809d 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -37,12 +37,16 @@ jobs: env: SHA: ${{ github.sha }} 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 # the job runs), so the runner needs no SSH key or Gitea user. REMOTE: http://git.adam-french.co.uk:3000/adamf/ccp.git GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} 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: - name: Export the pushed commit to a scratch directory shell: bash @@ -67,14 +71,14 @@ jobs: shell: bash run: | set -eu - docker network create "ci-$SHA" - docker run -d --name "ci-pg-$SHA" --network "ci-$SHA" --network-alias pg \ + docker network create "ci-$RUN" + docker run -d --name "ci-pg-$RUN" --network "ci-$RUN" --network-alias pg \ -e POSTGRES_PASSWORD=ci postgres:17 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 done - docker logs "ci-pg-$SHA" + docker logs "ci-pg-$RUN" exit 1 # Read-only source, and named volumes for the module and build @@ -90,7 +94,7 @@ jobs: -v "$SRC":/src:ro -w /src \ -v activity_tracker_ci_gomod:/go/pkg/mod \ -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' \ golang:1.27 \ sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -count=1 ./...' @@ -112,8 +116,8 @@ jobs: shell: bash run: | rm -rf "$SRC" - docker rm -f "ci-pg-$SHA" || true - docker network rm "ci-$SHA" || true + docker rm -f "ci-pg-$RUN" || true + docker network rm "ci-$RUN" || true publish: needs: test @@ -122,7 +126,7 @@ jobs: env: SHA: ${{ github.sha }} 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_TOKEN: ${{ secrets.REGISTRY_TOKEN }} steps: