Skip to content

Commit 7736045

Browse files
committed
improve support for restricted runners
1 parent cb99bdc commit 7736045

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Therefore, use **Git 2.15.0 or newer**.
1919

2020
You need to have given write permissions for the for the workflow.
2121
If the 'coverage' branch does not exist, it will be created as an orphan (without main repo history).
22+
The action creates bot commits with signing disabled (`commit.gpgsign=false`) for compatibility with runners that enforce local signing config but have no key.
23+
If your `coverage` branch requires signed commits, configure signing keys on the runner or relax that branch rule.
2224
Reference the generated badge in your README.md like this:
2325

2426
```md

action.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@ runs:
3535
shell: bash
3636
run: |
3737
set -euo pipefail
38-
git config --global --add safe.directory "$GITHUB_WORKSPACE"
38+
# Trust only this workspace. If the default global config is not writable,
39+
# use a temporary global config file and persist it for subsequent steps.
40+
if ! git config --global --add safe.directory "$GITHUB_WORKSPACE" >/dev/null 2>&1; then
41+
if [[ -n "${RUNNER_TEMP:-}" ]]; then
42+
SAFE_GLOBAL="${RUNNER_TEMP}/gitcoverage-global.gitconfig"
43+
else
44+
SAFE_GLOBAL="${GITHUB_WORKSPACE}/.gitcoverage-global.gitconfig"
45+
fi
46+
touch "$SAFE_GLOBAL"
47+
export GIT_CONFIG_GLOBAL="$SAFE_GLOBAL"
48+
echo "GIT_CONFIG_GLOBAL=$SAFE_GLOBAL" >> "$GITHUB_ENV"
49+
if ! git config --global --add safe.directory "$GITHUB_WORKSPACE"; then
50+
echo "Failed to configure safe.directory for '$GITHUB_WORKSPACE'." >&2
51+
exit 1
52+
fi
53+
fi
3954
git config --local user.email "action@github.com"
4055
git config --local user.name "GitHub Action"
4156
@@ -261,7 +276,7 @@ runs:
261276
git rm -rf --cached . >/dev/null 2>&1 || true
262277
echo '# Coverage branch' > README.md
263278
git add README.md
264-
git commit -m 'Add README.md'
279+
git -c commit.gpgsign=false commit -m 'Add README.md'
265280
# Push with auth via checkout action's token/remote config.
266281
# If another concurrent run creates 'coverage' first, treat that as success.
267282
if git push origin coverage; then
@@ -472,7 +487,7 @@ runs:
472487
git add -A -- "${BRANCH}"
473488
# Only proceed when this step actually staged changes for the target path.
474489
if ! git diff --cached --quiet -- "${BRANCH}"; then
475-
git commit -m "update"
490+
git -c commit.gpgsign=false commit -m "update"
476491
477492
max_attempts=5
478493
attempt=1

0 commit comments

Comments
 (0)