-
Notifications
You must be signed in to change notification settings - Fork 854
103 lines (90 loc) · 2.89 KB
/
pr-tests.yml
File metadata and controls
103 lines (90 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: pr-tests
on:
pull_request:
types:
- "opened"
- "reopened"
- "synchronize"
paths:
- "src/**"
- "build.mjs"
- "tests/**"
- "package.json"
- "package-lock.json"
- ".github/workflows/scripts/**"
- ".github/workflows/pr-tests.yml"
push:
branches:
- "master"
paths:
- "src/**"
- "build.mjs"
- "tests/**"
- "package.json"
- "package-lock.json"
- ".github/workflows/scripts/**"
- ".github/workflows/pr-tests.yml"
jobs:
tests:
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
- run: npm ci
- run: npm run test:coverage
- run: npm run lint
- run: npm run build
update_coverage_badge:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: tests
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: 22
- run: npm ci
- run: npm run test:coverage
- run: node .github/workflows/scripts/update-coverage-badge.mjs
- name: Commit coverage badge
run: |
branch="${GITHUB_REF#refs/heads/}"
max_retries=3
if git diff --quiet -- badges/coverage.json; then
echo "Coverage badge unchanged"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add badges/coverage.json
git commit -m "Update coverage badge [skip ci]"
for attempt in $(seq 1 "${max_retries}"); do
echo "Attempt ${attempt}/${max_retries}: pushing coverage badge update to ${branch}"
if git push origin "HEAD:${branch}"; then
echo "Coverage badge push succeeded"
exit 0
fi
if [ "${attempt}" -eq "${max_retries}" ]; then
echo "::warning::Failed to push coverage badge after ${max_retries} attempts due to concurrent updates. Skipping without failing CI."
exit 0
fi
echo "Push rejected. Fetching latest origin/${branch} and retrying with rebase..."
if ! git fetch origin "${branch}"; then
echo "::warning::Failed to fetch origin/${branch} while retrying coverage badge push. Skipping without failing CI."
exit 0
fi
if ! git rebase "origin/${branch}"; then
git rebase --abort || true
echo "::warning::Rebase conflict while retrying coverage badge push. Skipping without failing CI."
exit 0
fi
sleep $((attempt * 2))
done