Skip to content

Commit af6ff95

Browse files
talgalilifacebook-github-bot
authored andcommitted
Fix GitHub Actions coverage badge workflow git operations
Summary: The coverage badge workflow was failing in GitHub Actions when the remote `badges` branch didn't exist. The flawed conditional logic would create an orphan branch but then fail on the subsequent checkout. This fix uses an idempotent approach that always creates a fresh orphan branch and force-pushes to the remote, avoiding racy conditional checks and working reliably whether the remote branch exists or not. Differential Revision: D90937254
1 parent ab550c9 commit af6ff95

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

.github/workflows/coverage.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ jobs:
5959
git config --local user.email "github-actions[bot]@users.noreply.github.com"
6060
git config --local user.name "github-actions[bot]"
6161
62-
# Fetch the badges branch or create it as an orphan
63-
git fetch origin badges:badges 2>/dev/null || git checkout --orphan badges
64-
git checkout badges
62+
# Always start fresh with orphan branch
63+
git checkout --orphan badges-temp
64+
git rm -rf . 2>/dev/null || true
6565
6666
# Create badge directory and file
6767
mkdir -p .github/badges
68+
cat > README.md << 'EOF'
69+
# Coverage Badges
70+
71+
This branch stores dynamically generated coverage badges.
72+
EOF
73+
6874
python -c "
6975
import os, json
7076
coverage = float(os.environ['COVERAGE'])
@@ -74,6 +80,6 @@ jobs:
7480
json.dump(badge, f)
7581
"
7682
77-
git add .github/badges/coverage.json
78-
git diff --staged --quiet || git commit -m "Update coverage badge [skip ci]"
79-
git push origin badges
83+
git add .
84+
git commit -m "Update coverage badge to ${COVERAGE}% [skip ci]"
85+
git push -f origin badges-temp:badges

0 commit comments

Comments
 (0)