@@ -149,19 +149,24 @@ runs:
149149 shell : bash
150150 run : |
151151 set -euo pipefail
152- # Use a worktree so we don't disturb current checkout
153- rm -rf coverage
152+ # Use an isolated worktree path so we don't clobber project dirs (e.g. ./coverage reports)
153+ if [[ -n "${RUNNER_TEMP:-}" ]]; then
154+ WORKTREE_DIR="$(mktemp -d "${RUNNER_TEMP}/gitcoverage-worktree.XXXXXX")"
155+ else
156+ WORKTREE_DIR="$(mktemp -d "${PWD}/.gitcoverage-worktree.XXXXXX")"
157+ fi
154158 git worktree prune || true
155- git worktree add -B coverage coverage origin/coverage
156- echo "Using worktree at ./coverage"
159+ git worktree add -B coverage "$WORKTREE_DIR" origin/coverage
160+ echo "WORKTREE_DIR=$WORKTREE_DIR" >> "$GITHUB_ENV"
161+ echo "Using worktree at $WORKTREE_DIR"
157162
158163 - name : Prepare coverage/<branch> directory
159164 shell : bash
160165 env :
161166 BRANCH : ${{ steps.branch.outputs.branch }}
162167 run : |
163168 set -euo pipefail
164- mkdir -p "coverage /${BRANCH}"
169+ mkdir -p "${WORKTREE_DIR} /${BRANCH}"
165170
166171 - name : Parse coverage input and generate SVG badge
167172 shell : bash
@@ -278,7 +283,7 @@ runs:
278283 EOF
279284 )"
280285
281- echo "$SVG" > "coverage /${BRANCH}/badge.svg"
286+ echo "$SVG" > "${WORKTREE_DIR} /${BRANCH}/badge.svg"
282287
283288 - name : Copy optional report.html
284289 if : ${{ inputs.report != '' }}
@@ -292,15 +297,15 @@ runs:
292297 echo "Report file not found at: $SRC" >&2
293298 exit 1
294299 fi
295- cp -f "$SRC" "coverage /${BRANCH}/report.html"
300+ cp -f "$SRC" "${WORKTREE_DIR} /${BRANCH}/report.html"
296301
297302 - name : Commit & push changes to coverage branch
298303 env :
299304 BRANCH : ${{ steps.branch.outputs.branch }}
300305 shell : bash
301306 run : |
302307 set -euo pipefail
303- pushd coverage >/dev/null
308+ pushd "$WORKTREE_DIR" >/dev/null
304309 git config --local user.email "action@github.com"
305310 git config --local user.name "GitHub Action"
306311 test ! -f "${BRANCH}/badge.svg" || git add "${BRANCH}/badge.svg"
@@ -337,6 +342,6 @@ runs:
337342 set -euo pipefail
338343 echo "Published:"
339344 echo " - ${BRANCH}/badge.svg"
340- if [[ -f "coverage /${BRANCH}/report.html" ]]; then
345+ if [[ -f "${WORKTREE_DIR} /${BRANCH}/report.html" ]]; then
341346 echo " - ${BRANCH}/report.html"
342347 fi
0 commit comments