forked from bradygaster/squad
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (138 loc) · 5.21 KB
/
ci-rerun.yml
File metadata and controls
153 lines (138 loc) · 5.21 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# CI Rerun — Manual workflow for re-running CI on fork PRs or PRs that need
# a fresh CI pass without push. Useful when:
# - Fork PRs don't trigger CI automatically (security restriction)
# - A PR needs re-testing after an infrastructure flake
# - You need to validate a PR against current base branch state
# Usage: Actions → CI Rerun (Manual) → enter PR number → Run workflow
name: CI Rerun (Manual)
on:
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to test'
required: true
type: string
permissions:
contents: read
statuses: write
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Fetch PR metadata
id: pr
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_DATA=$(gh api repos/${{ github.repository }}/pulls/${{ inputs.pr_number }})
HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha')
HEAD_REF=$(echo "$PR_DATA" | jq -r '.head.ref')
HEAD_REPO=$(echo "$PR_DATA" | jq -r '.head.repo.full_name')
BASE_REF=$(echo "$PR_DATA" | jq -r '.base.ref')
echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT"
echo "head_ref=$HEAD_REF" >> "$GITHUB_OUTPUT"
echo "head_repo=$HEAD_REPO" >> "$GITHUB_OUTPUT"
echo "base_ref=$BASE_REF" >> "$GITHUB_OUTPUT"
echo "Testing PR #${{ inputs.pr_number }}: $HEAD_REPO/$HEAD_REF → $BASE_REF (SHA: $HEAD_SHA)"
- name: Set pending status
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ steps.pr.outputs.head_sha }} \
--method POST \
--field state=pending \
--field context="Squad CI / rerun" \
--field description="Running CI rerun..." \
--field target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- uses: actions/checkout@v4
with:
ref: refs/pull/${{ inputs.pr_number }}/merge
continue-on-error: true
id: checkout_merge
- name: Fallback — checkout PR head directly
if: steps.checkout_merge.outcome == 'failure'
uses: actions/checkout@v4
with:
repository: ${{ steps.pr.outputs.head_repo }}
ref: ${{ steps.pr.outputs.head_ref }}
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: Fix stale lockfile entries
run: |
node -e "
const fs = require('fs');
const lock = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'));
const pkgs = lock.packages || {};
const stale = Object.keys(pkgs).filter(k =>
k.includes('/node_modules/@cargom98/squad-') &&
pkgs[k].resolved && pkgs[k].resolved.startsWith('https://')
);
if (stale.length) {
stale.forEach(k => { console.log('Removing: ' + k); delete pkgs[k]; });
fs.writeFileSync('package-lock.json', JSON.stringify(lock, null, 2) + '\n');
} else {
console.log('Lockfile clean');
}
"
- name: Install dependencies
run: |
success=false
for i in 1 2 3; do
if npm install; then
success=true
break
fi
echo "Retry $i/3 — npm install failed, retrying in 5s..."
sleep 5
done
if [ "$success" = false ]; then
echo "::error::npm install failed after 3 attempts"
exit 1
fi
- name: Install docs dependencies
run: |
success=false
for i in 1 2 3; do
if npm ci; then
success=true
break
fi
echo "Retry $i/3 — npm ci failed, retrying in 5s..."
sleep 5
done
if [ "$success" = false ]; then
echo "::error::npm ci failed after 3 attempts"
exit 1
fi
working-directory: docs
- name: Install Playwright browsers
run: npx playwright install chromium --with-deps
- name: Build
run: npm run build
- name: Run tests
run: npm test
- name: Set success status
if: success()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ steps.pr.outputs.head_sha }} \
--method POST \
--field state=success \
--field context="Squad CI / rerun" \
--field description="All checks passed" \
--field target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Set failure status
if: failure()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ steps.pr.outputs.head_sha }} \
--method POST \
--field state=failure \
--field context="Squad CI / rerun" \
--field description="CI rerun failed — check logs" \
--field target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"