Skip to content

Commit 115dc93

Browse files
fix(go-ci): take coverage report ownership without sudo (#29)
The 'Augment coverage report with cyclomatic complexity' step ran 'sudo chown' to reclaim code-coverage-results.md (written as root by the irongut/CodeCoverageSummary Docker action). Self-hosted runners lack passwordless sudo, so the step failed with 'sudo: a password is required', breaking every Go consumer's build-and-test job. Replace the file with a runner-owned copy via cp + mv -f when it is not writable; this needs only workspace-directory permissions and is a no-op on GitHub-hosted runners.
1 parent 796fb81 commit 115dc93

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

.github/workflows/go-ci.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,15 @@ jobs:
208208
echo "::error::CodeCoverageSummary did not produce code-coverage-results.md"
209209
exit 1
210210
fi
211-
# Workaround: CodeCoverageSummary runs inside a Docker container
212-
# that writes code-coverage-results.md as root, so chown it back
213-
# before editing.
214-
sudo chown "$(id -un)" code-coverage-results.md
211+
# Workaround: irongut/CodeCoverageSummary runs inside a Docker
212+
# container that may write code-coverage-results.md as root. Self-hosted
213+
# runners lack passwordless sudo, so take ownership without sudo by
214+
# replacing the file with a runner-owned copy when it is not already
215+
# writable (a same-directory rename only needs workspace dir perms).
216+
if [ ! -w code-coverage-results.md ]; then
217+
cp code-coverage-results.md code-coverage-results.md.owned
218+
mv -f code-coverage-results.md.owned code-coverage-results.md
219+
fi
215220
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.6.0
216221
GOCYCLO="$(go env GOPATH)/bin/gocyclo"
217222

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fix `go-ci.yaml` failing the `Augment coverage report with cyclomatic complexity` step on self-hosted runners. The step ran `sudo chown "$(id -un)" code-coverage-results.md` to take back a file that `irongut/CodeCoverageSummary` (a Docker action) writes as root, but self-hosted runners (e.g. the Hetzner pool) lack passwordless sudo, so the step died with `sudo: a password is required` — breaking every Go consumer's `build-and-test` job once it compiled far enough to reach coverage. Ownership is now taken without sudo: when the report is not writable it is replaced with a runner-owned copy via a same-directory `cp` + `mv -f`, which needs only workspace-directory permissions and is a no-op on GitHub-hosted runners where the file is already writable. Reported by `peacefulstudio/terraform-provider-canton-internal`.
13+
1014
## [2.3.1] - 2026-06-19
1115

1216
### Fixed

0 commit comments

Comments
 (0)