generated from technote-space/gh-actions-template
-
-
Notifications
You must be signed in to change notification settings - Fork 29
245 lines (233 loc) · 7.64 KB
/
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
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
245
on: push
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
name: CI
jobs:
eslint:
name: ESLint
runs-on: ubuntu-latest
timeout-minutes: 5
env:
LINT: 1
steps:
- name: Set running flag
run: echo "RUNNING=1" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: technote-space/get-git-comment-action@v1
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: +(src|__tests__)/**/*.+(js|ts)
FILES: |
yarn.lock
.eslintrc
if: "! contains(env.COMMIT_MESSAGE, '[skip ci]') && ! contains(env.COMMIT_MESSAGE, '[ci skip]')"
- name: Set running flag
run: echo "RUNNING=" >> $GITHUB_ENV
if: "! env.GIT_DIFF"
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
if: env.RUNNING
- name: Install Package dependencies
run: yarn install
if: env.RUNNING
- name: Check code style
run: yarn eslint ${{ env.GIT_DIFF_FILTERED }}
if: env.RUNNING && !env.MATCHED_FILES
- name: Check code style
run: yarn lint
if: env.RUNNING && env.MATCHED_FILES
cover:
name: Coverage
needs: eslint
runs-on: ${{matrix.os}}
timeout-minutes: 10
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-latest]
steps:
- name: Set running flag
run: echo "RUNNING=1" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: technote-space/get-git-comment-action@v1
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: +(src|__tests__)/**/*.+(js|ts|snap)
FILES: |
yarn.lock
jest.config.js
vite.config.ts
if: "! contains(env.COMMIT_MESSAGE, '[skip ci]') && ! contains(env.COMMIT_MESSAGE, '[ci skip]')"
- name: Set running flag
run: echo "RUNNING=" >> $GITHUB_ENV
if: "! env.GIT_DIFF"
- name: Set running flag
if: "matrix.os == 'ubuntu-latest' && ! startsWith(github.ref, 'refs/tags/') && github.event.base_ref == format('refs/heads/{0}', github.event.repository.default_branch)"
run: echo "RUNNING=1" >> $GITHUB_ENV
- name: Set running flag
if: "matrix.os == 'ubuntu-latest' && ! startsWith(github.ref, 'refs/tags/') && startsWith(github.base_ref, 'refs/heads/develop/v')"
run: echo "RUNNING=1" >> $GITHUB_ENV
- name: Set running flag
if: matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/v')
run: echo "RUNNING=1" >> $GITHUB_ENV
- name: Set running flag
run: |
if [[ ! -f package.json ]] || ! < package.json jq -r '.scripts | keys[]' | grep -qe '^cover$'; then
echo "RUNNING=" >> $GITHUB_ENV
fi
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
if: env.RUNNING
- name: Install Package dependencies
run: yarn install
if: env.RUNNING
- name: Run tests
run: yarn cover
if: env.RUNNING
- name: Codecov
run: |
if [ -n "$CODECOV_TOKEN" ]; then
curl -s https://codecov.io/bash | bash -s -- -t $CODECOV_TOKEN -f $COVERAGE_FILE
fi
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
COVERAGE_FILE: ./coverage/lcov.info
if: env.RUNNING && matrix.os == 'ubuntu-latest'
release:
name: Release GitHub Actions
needs: cover
runs-on: ubuntu-latest
timeout-minutes: 5
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
- uses: technote-space/load-config-action@v1
with:
CONFIG_FILENAME: workflow-settings.json, workflow-details.json
IGNORE_WARNING: 'true'
- name: Release GitHub Actions
uses: technote-space/release-github-actions@v8
with:
OUTPUT_BUILD_INFO_FILENAME: build.json
TEST_TAG_PREFIX: test/
ORIGINAL_TAG_PREFIX: original/
CLEAN_TEST_TAG: true
DELETE_NODE_MODULES: ${{ env.RELEASE_GA_DELETE_NODE_MODULES }}
package:
name: Publish Package
needs: cover
runs-on: ubuntu-latest
timeout-minutes: 5
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
target: ['npm', 'gpr']
steps:
- name: Set running flag
run: echo "RUNNING=1" >> $GITHUB_ENV
- name: Set running flag
run: |
if [ -z "$NPM_AUTH_TOKEN" ]; then
echo "RUNNING=" >> $GITHUB_ENV
fi
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- uses: actions/checkout@v3
if: env.RUNNING
- name: Check package version
uses: technote-space/package-version-check-action@v1
with:
COMMIT_DISABLED: 1
if: env.RUNNING
- name: Set running flag
run: npx can-npm-publish || echo "RUNNING=" >> $GITHUB_ENV
if: env.RUNNING && matrix.target == 'npm'
- name: Set running flag
run: |
LATEST=`npm view . version` 2> /dev/null || :
CURRENT=`cat package.json | jq -r .version`
if [ "$LATEST" = "$CURRENT" ]; then
echo "RUNNING=" >> $GITHUB_ENV
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.RUNNING && matrix.target == 'gpr'
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
cache: yarn
if: env.RUNNING && matrix.target == 'npm'
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com
cache: yarn
if: env.RUNNING && matrix.target == 'gpr'
- name: Install Package dependencies
run: yarn install
if: env.RUNNING
- name: Build
run: yarn build
if: env.RUNNING
- name: Publish
run: |
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
npm publish
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
if: env.RUNNING && matrix.target == 'npm'
- name: Publish
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.RUNNING && matrix.target == 'gpr'
publishRelease:
name: Create Release
needs: [release, package]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Get version
run: echo "TAG_NAME=${HEAD_REF#refs/tags/}" >> $GITHUB_ENV
env:
HEAD_REF: ${{ github.ref }}
- name: Create Release
id: drafter
uses: technote-space/release-drafter@v6
with:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
DRAFT: false
NAME: ${{ env.TAG_NAME }}
TAG: ${{ env.TAG_NAME }}
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
text: ${{ format('<{0}>', steps.drafter.outputs.html_url) }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: success() && env.SLACK_WEBHOOK_URL
slack:
name: Slack
needs: publishRelease
runs-on: ubuntu-latest
timeout-minutes: 3
if: always()
steps:
- uses: technote-space/workflow-conclusion-action@v3
- uses: 8398a7/action-slack@v3
with:
status: failure
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: env.WORKFLOW_CONCLUSION == 'failure' && env.SLACK_WEBHOOK_URL