-
Notifications
You must be signed in to change notification settings - Fork 0
244 lines (208 loc) · 7.43 KB
/
checks.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Project Health
on:
#testing
push:
branches:
- master
- 'maint-*'
paths:
- 'src/**.jsx?'
- 'src/**.mjs'
- 'src/**.cjs'
- 'src/**.snap'
- 'src/**.json'
- 'package.json'
pull_request:
branches:
- master
repository_dispatch:
types: [snapshot]
env:
CI: true
jobs:
setup:
runs-on: ubuntu-latest
outputs:
time: ${{ steps.data.outputs.time }}
sha: ${{ steps.data.outputs.sha }}
snapshot: ${{ steps.data.outputs.snapshot }}
snapshot_id: ${{steps.prepare.outputs.SNAPSHOT_ID}}
version: ${{steps.prepare.outputs.version}}
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: clone
uses: actions/checkout@v2
- name: setup nodejs
uses: actions/setup-node@v2
with:
node-version: '16'
- name: 'Gather Data'
id: data
run: |
# Data Gathering
echo "::set-output name=time::$(/bin/date -u "+%FT%T")"
if [ `git rev-parse --abbrev-ref HEAD` = "master" ]; then
# nesting if blocks for readability
if cat package.json | grep -E "(app-scripts |@nti\/)snapshot" &> /dev/null; then
echo "::set-output name=snapshot::true";
fi
fi;
echo "::set-output name=sha::$(git rev-list HEAD | head -1)"
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/cache@v2
with:
path: |
node_modules
package.json
key: ${{ runner.os }}-node-modules-${{steps.data.outputs.sha}}-${{steps.data.outputs.time}}
- name: install SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.ACTIONS_REPO_ACCESS }}
- name: configure npm
env:
NPM_REGISTRY: ${{ secrets.NPM_REGISTRY }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm config set loglevel error
npm config set progress false
npm config set '@nti:registry' "$NPM_REGISTRY"
npm config set "${NPM_REGISTRY/https:/}/:_authToken" "$NPM_TOKEN"
git config --global url."[email protected]:".insteadOf "https://github.com/"
- name: prepare install
id: prepare
run: |
npx @nti/ci-scripts prepare
if [ "snapshot" == "${{github.event.action}}" ]; then
rm -rf node_modules
fi;
- name: install dependencies
run: |
COMMAND='install'
if [ -f package-lock.json ]; then COMMAND="ci"; fi;
if [ ! -d node_modules ]; then
npm $COMMAND --package-lock --no-progress --no-audit;
fi;
- name: notify if failure
if: ${{ failure() && github.event_name != 'pull_request' }}
env:
LINK: ${{ format('<https://github.com/{0}/actions|{0}>', github.repository) }}
run: |
MESSAGE="{\"text\": \":stop_sign: preflight failure for $LINK, registry down?\" }"
curl -i -X POST -H 'Content-Type: application/json' -d "$MESSAGE" ${{secrets.MM_HOOK}}
lint:
needs: setup
runs-on: ubuntu-latest
if: github.event.action != 'snapshot'
steps:
- name: clone
uses: actions/checkout@v2
- name: setup nodejs
uses: actions/setup-node@v2
with:
node-version: '16'
- uses: actions/cache@v2
with:
path: |
node_modules
package.json
key: ${{ runner.os }}-node-modules-${{needs.setup.outputs.sha}}-${{needs.setup.outputs.time}}
- name: lint
run: npm run check --if-present
- name: notify if failure
if: ${{ failure() && github.event_name != 'pull_request' }}
env:
LINK: ${{ format('<https://github.com/{0}/actions|{0}>', github.repository) }}
run: |
MESSAGE="{\"text\": \":stop_sign: :eyes: lint failure in $LINK\" }"
curl -i -X POST -H 'Content-Type: application/json' -d "$MESSAGE" ${{secrets.MM_HOOK}}
test:
needs: setup
runs-on: ubuntu-latest
if: github.event.action != 'snapshot'
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: clone
uses: actions/checkout@v2
- name: setup nodejs
uses: actions/setup-node@v2
with:
node-version: '16'
- uses: actions/cache@v2
with:
path: |
node_modules
package.json
key: ${{ runner.os }}-node-modules-${{needs.setup.outputs.sha}}-${{needs.setup.outputs.time}}
- name: test
run: npm test
- name: notify if failure
if: ${{ failure() && github.event_name != 'pull_request' }}
env:
LINK: ${{ format('<https://github.com/{0}/actions|{0}>', github.repository) }}
run: |
MESSAGE="{\"text\": \":stop_sign: :eyes: tests failed in $LINK\" }"
curl -i -X POST -H 'Content-Type: application/json' -d "$MESSAGE" ${{secrets.MM_HOOK}}
snapshot:
needs: setup
runs-on: ubuntu-latest
if: needs.setup.outputs.snapshot == 'true' && github.event_name != 'pull_request'
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: clone
uses: actions/checkout@v2
- name: setup nodejs
uses: actions/setup-node@v2
with:
node-version: '16'
- name: install SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.ACTIONS_REPO_ACCESS }}
- name: configure npm
env:
NPM_REGISTRY: ${{ secrets.NPM_REGISTRY }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm config set loglevel error
npm config set progress false
npm config set '@nti:registry' "$NPM_REGISTRY"
npm config set "${NPM_REGISTRY/https:/}/:_authToken" "$NPM_TOKEN"
git config --global url."[email protected]:".insteadOf "https://github.com/"
- uses: actions/cache@v2
with:
path: |
node_modules
package.json
key: ${{ runner.os }}-node-modules-${{needs.setup.outputs.sha}}-${{needs.setup.outputs.time}}
- name: publish
run: npx @nti/ci-scripts publish
- name: notify if failure
if: failure()
env:
LINK: ${{ format('<https://github.com/{0}/actions|{1} snapshot failed>', github.repository, needs.setup.outputs.snapshot_id) }}
run: |
MESSAGE="{\"text\": \":stop_sign: $LINK\" }"
curl -i -X POST -H 'Content-Type: application/json' -d "$MESSAGE" ${{secrets.MM_HOOK}}
- name: notify if new snap
if: success()
env:
LINK: ${{ format('<https://github.com/{0}/actions|New snapshot {1}>', github.repository, needs.setup.outputs.snapshot_id) }}
run: |
MESSAGE="{\"text\": \":white_check_mark: $LINK\", \"channel\":\"Jenkins\" }"
curl -i -X POST -H 'Content-Type: application/json' -d "$MESSAGE" ${{secrets.MM_HOOK}}
[ "" != "${{secrets.WEB_SNAPSHOT_URL}}" ] && curl -X POST ${{secrets.WEB_SNAPSHOT_URL}} || true