From f5ad422c179595c385099bf4a48e4cc734ad7375 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 2 Dec 2026 22:07:27 -0500 Subject: [PATCH] ci: keep go test's status when it fails under -e (#8372) Break run 11328 went red for the wrong reason. The step shell runs with -e, so a failing go test ended the brace group before `echo $?` wrote its status; the step then died on `exit ""` ("numeric argument required"). `|| rc=$?` keeps the group alive to record the status, and a missing status file now exits 1 rather than relying on that error. Breaks from 8af3c41b are still in place, so this run must be red with go test's own exit code. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/release.yml | 15 +++++++++------ ci/testcount/main.go | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 1bb6b67e..fa3bbac6 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -168,12 +168,14 @@ jobs: # ci/testcount prints what plain go test would, plus how many tests # ran. The step exits with go test's own status, kept aside in a file - # because the shell has no pipefail. + # because the shell has no pipefail. The `|| rc=$?` matters: under + # `-e` a bare failing go test ends the group before its status is + # written, and a missing file fails the step as 1, never as a pass. - name: go test (short, race) run: | go build -o /tmp/testcount ./ci/testcount - { go test -short -race -json ./...; echo $? > /tmp/go-test-rc; } | /tmp/testcount - exit "$(cat /tmp/go-test-rc)" + { rc=0; go test -short -race -json ./... || rc=$?; echo "$rc" > /tmp/go-test-rc; } | /tmp/testcount + exit "$(cat /tmp/go-test-rc 2>/dev/null || echo 1)" # Full `go test -race` against an ephemeral Postgres. # @@ -310,10 +312,11 @@ jobs: echo "database test packages: $(echo "$PKGS" | wc -l)" go test -race -run '^$' $PKGS # ci/testcount prints the usual go test output plus how many tests - # ran; the step exits with go test's own status (no pipefail). + # ran; the step exits with go test's own status (no pipefail, and + # `|| rc=$?` so -e cannot end the group before the status is kept). go build -o /tmp/testcount ./ci/testcount - { go test -p 1 -race -timeout 20m -json $PKGS; echo $? > /tmp/go-test-rc; } | /tmp/testcount - exit "$(cat /tmp/go-test-rc)" + { rc=0; go test -p 1 -race -timeout 20m -json $PKGS || rc=$?; echo "$rc" > /tmp/go-test-rc; } | /tmp/testcount + exit "$(cat /tmp/go-test-rc 2>/dev/null || echo 1)" web: runs-on: go-ci diff --git a/ci/testcount/main.go b/ci/testcount/main.go index 9f89de7e..3404cfbc 100644 --- a/ci/testcount/main.go +++ b/ci/testcount/main.go @@ -6,8 +6,8 @@ // It never decides whether the run passed. The lane exits with go test's own // status, which is why the pipe keeps it aside: // -// { go test -json ./...; echo $? > /tmp/go-test-rc; } | testcount -// exit "$(cat /tmp/go-test-rc)" +// { rc=0; go test -json ./... || rc=$?; echo "$rc" > /tmp/go-test-rc; } | testcount +// exit "$(cat /tmp/go-test-rc 2>/dev/null || echo 1)" package main import (