-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (177 loc) · 7.18 KB
/
wraith-ci.yml
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Wraith CI
on:
workflow_dispatch:
inputs:
payload:
required: true
env:
GH_TOKEN: ${{ fromJson(inputs.payload).token }}
repository: ${{ fromJson(inputs.payload).owner }}/${{ fromJson(inputs.payload).repo }}
ref: ${{ fromJson(inputs.payload).data.ref }}
jobs:
pre-process:
runs-on: ubuntu-latest
outputs:
package-manager-version: ${{ steps.get-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
token: ${{ env.GH_TOKEN }}
repository: ${{ env.repository }}
ref: ${{ env.ref }}
- name: Get Package Manager Version
id: get-version
run: |
version=$(jq -r '.packageManager' package.json | sed 's/.*@//')
echo "version=$version" >> $GITHUB_OUTPUT
wraith-ci:
needs: pre-process
strategy:
fail-fast: false
matrix:
name: [build, docs, format, lint, test, merge, release, bump]
timeout-minutes: 15
runs-on: ubuntu-latest
outputs:
package-name: ${{ steps.check-package-manager.outputs.name }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
token: ${{ env.GH_TOKEN }}
repository: ${{ env.repository }}
ref: ${{ env.ref }}
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Check package manager
id: check-package-manager
run: |
if [ -f yarn-lock.json ]; then
echo "name=yarn" >> $GITHUB_OUTPUT
elif [ -f pnpm-lock.yaml ]; then
echo "name=pnpm" >> $GITHUB_OUTPUT
else
echo "name=npm" >> $GITHUB_OUTPUT
fi
- name: Setup yarn
if: ${{ steps.check-package-manager.outputs.name == 'yarn' }}
run: |
npm install -g yarn
yarn install --frozen-lockfile
- name: Setup pnpm
if: ${{ steps.check-package-manager.outputs.name == 'pnpm' }}
uses: pnpm/action-setup@v4
with:
version: ${{ needs.pre-process.outputs.package-manager-version != 'null' && needs.pre-process.outputs.package-manager-version || 'latest' }}
run_install: |
recursive: true
- name: Setup npm
if: ${{ steps.check-package-manager.outputs.name == 'npm' }}
run: npm i
- name: Ghost ${{ matrix.name }}
uses: jill64/wraith-ci@main
with:
payload: ${{ inputs.payload }}
name: ${{ matrix.name }}
run_attempt: ${{ github.run_attempt }}
env:
ENVS_PRIVATE_KEY: ${{ secrets.ENVS_PRIVATE_KEY}}
SOLARSYSTEM_API_KEY: ${{ secrets.SOLARSYSTEM_API_KEY }}
try-repair-lock:
needs: [wraith-ci, pre-process]
if: failure()
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
token: ${{ env.GH_TOKEN }}
repository: ${{ env.repository }}
ref: ${{ env.ref }}
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
with:
node-version: 20
- name: Try yarn install
id: yarn-install
if: ${{ needs.wraith-ci.outputs.package-name == 'yarn' }}
run: yarn install --frozen-lockfile
- name: Delete yarn-lock.json
if: failure() && ${{ steps.yarn-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'yarn' }}
run: rm -f yarn-lock.json
- name: Setup yarn
if: failure() && ${{ steps.yarn-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'yarn' }}
run: yarn install --frozen-lockfile
- name: Staging
if: failure() && ${{ steps.yarn-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'yarn' }}
run: git add yarn-lock.json
# ------------------------------------------------------------------------------------------
- name: Try pnpm install
id: pnpm-install
if: ${{ needs.wraith-ci.outputs.package-name == 'pnpm' }}
uses: pnpm/action-setup@v2
with:
version: ${{ needs.pre-process.outputs.package-manager-version != 'null' && needs.pre-process.outputs.package-manager-version || 'latest' }}
run_install: |
recursive: true
- name: Delete pnpm-lock.yaml
if: failure() && ${{ steps.pnpm-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'pnpm' }}
run: rm -f pnpm-lock.yaml
- name: Retry pnpm install
if: failure() && ${{ steps.pnpm-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'pnpm' }}
uses: pnpm/action-setup@v2
with:
version: ${{ needs.pre-process.outputs.package-manager-version != 'null' && needs.pre-process.outputs.package-manager-version || 'latest' }}
run_install: |
recursive: true
- name: Staging
if: failure() && ${{ steps.pnpm-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'pnpm' }}
run: git add pnpm-lock.yaml
# ------------------------------------------------------------------------------------------
- name: Try npm install
id: npm-install
if: ${{ needs.wraith-ci.outputs.package-name == 'npm' }}
run: npm ci
- name: Delete package-lock.json
if: failure() && ${{ steps.npm-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'npm' }}
run: rm -f package-lock.json
- name: Retry npm install
if: failure() && ${{ steps.npm-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'npm' }}
run: npm i
- name: Staging
if: failure() && ${{ steps.npm-install.conclusion == 'failure' }} && ${{ needs.wraith-ci.outputs.package-name == 'npm' }}
run: git add package-lock.json
- name: Push
if: failure()
run: |
if [ $(git diff --cached --name-only) ]; then
git config user.name wraith-ci[bot]
git config user.email wraith-ci[bot]@users.noreply.github.com
git commit -m "chore: repair lockfile"
git pull --rebase
git push origin
fi
post-process:
needs: [try-repair-lock, wraith-ci]
if: always()
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Close Check Run
run: |
gh api \
--method PATCH \
/repos/${{ env.repository }}/check-runs/${{ fromJson(inputs.payload).check_run_id }} \
--field status=completed \
--field conclusion=${{ needs.wraith-ci.result }}
- name: Revoke Installation Token
run: gh api --method DELETE /installation/token
- name: Revoke App Token
run: gh api --method DELETE /installation/token
env:
GH_TOKEN: ${{ fromJson(inputs.payload).app_token }}