-
Notifications
You must be signed in to change notification settings - Fork 2
230 lines (197 loc) · 7.2 KB
/
nodejs-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
# Node.js でビルド・テストを実行する。バージョンは .node-version に記載されているものを利用する
name: Node CI
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
types:
- opened
- synchronize
pull_request_target:
branches:
- main
- master
types:
- labeled
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
node-ci:
runs-on: ubuntu-latest
if: ${{
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'schedule' ||
(github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name) ||
(github.event_name == 'pull_request_target' && github.repository != github.event.pull_request.head.repo.full_name && contains(github.event.label.name, '🚀request-ci'))
}}
services:
mysql:
image: mysql:9.1
env:
MYSQL_ROOT_PASSWORD: rootPassword
MYSQL_USER: pixiv-ts
MYSQL_PASSWORD: pixiv-ts-test
MYSQL_DATABASE: pixiv-ts
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: 🛎 Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: 🏗 Setup node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
- name: Setup pnpm
uses: pnpm/action-setup@v2
id: pnpm-install
with:
run_install: false
- name: 📃 Check package.json definition
id: package-json
run: |
compile=$(jq '.scripts | has("compile")' package.json)
build=$(jq '.scripts | has("build")' package.json)
generate=$(jq '.scripts | has("generate")' package.json)
package=$(jq '.scripts | has("package")' package.json)
lint=$(jq '.scripts | has("lint")' package.json)
test=$(jq '.scripts | has("test")' package.json)
echo "compile: $compile"
echo "build: $build"
echo "generate: $generate"
echo "package: $package"
echo "lint: $lint"
echo "test: $test"
echo "compile=$compile" >> $GITHUB_OUTPUT
echo "build=$build" >> $GITHUB_OUTPUT
echo "generate=$generate" >> $GITHUB_OUTPUT
echo "package=$package" >> $GITHUB_OUTPUT
echo "lint=$lint" >> $GITHUB_OUTPUT
echo "test=$test" >> $GITHUB_OUTPUT
- name: 📂 Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: 📂 Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: 👨🏻💻 Install dependencies
run: |
pnpm install --frozen-lockfile --prefer-frozen-lockfile
- name: 👀 Run linter
if: steps.package-json.outputs.lint == 'true'
run: pnpm run lint
- name: 🎁 Run package
if: steps.package-json.outputs.package == 'true'
run: pnpm run package
- name: 🏃 Run compile
if: steps.package-json.outputs.compile == 'true'
run: pnpm run compile
- name: 🧪 Run tests
if: steps.package-json.outputs.test == 'true'
run: pnpm run test
env:
PIXIV_REFRESH_TOKEN: ${{ secrets.PIXIV_REFRESH_TOKEN }}
NODE_ENV: test
RESPONSE_DB_HOSTNAME: localhost
RESPONSE_DB_USERNAME: pixiv-ts
RESPONSE_DB_PASSWORD: pixiv-ts-test
RESPONSE_DB_DATABASE: pixiv-ts
RESPONSE_DB_PORT: 3306
- name: ☑️ Check Dependencies
if: steps.package-json.outputs.disabled-depcheck == 'false'
run: npx depcheck
- name: Check exists dist directory
id: check-dist
run: |
IS_DIRECTORY=$(test -d dist && echo true || echo false)
IS_SYMLINK=$(test -L dist && echo true || echo false)
echo "exists=$(test $IS_DIRECTORY = true && $IS_NOT_SYMLINK = false && echo true || echo false)" >> $GITHUB_OUTPUT
- name: 📦 Upload dist artifact
if: steps.check-dist.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
- name: Check exists output directory
id: check-output
run: |
IS_DIRECTORY=$(test -d output && echo true || echo false)
IS_SYMLINK=$(test -L output && echo true || echo false)
echo "exists=$(test $IS_DIRECTORY = true && $IS_NOT_SYMLINK = false && echo true || echo false)" >> $GITHUB_OUTPUT
- name: 📦 Upload output artifact
if: steps.check-output.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: output
path: output
- name: 👀 Check git status
run: |
git status
git diff --exit-code || (echo "Git status is not clean." && exit 1)
comment:
name: Comment
runs-on: ubuntu-latest
if: ${{
github.event_name == 'pull_request_target' &&
github.event.action == 'opened' &&
github.repository != github.event.pull_request.head.repo.full_name
}}
steps:
- name: Create PR comment
run: |
cat << EOF > comment.md
# ⚠️ CIの実行には \`🚀request-ci\` ラベルが必要です
このリポジトリはフォークされたリポジトリです。
セキュリティ上の理由から、フォークされたリポジトリからのCI実行は自動的に行われません。
CI実行をリクエストするには、このプルリクエストに \`🚀request-ci\` ラベルを追加してください。
(ラベルを追加できるのは一部のメンバーのみです)
EOF
gh pr comment ${{ github.event.number }} -R ${{ github.repository }} -F comment.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
finished-node-ci:
name: Check finished Node CI
runs-on: ubuntu-latest
if: always()
needs:
- node-ci
steps:
- name: Workflow conclusion
uses: technote-space/workflow-conclusion-action@v3
- name: Check finished Node CI
run: |
if [ "${{ env.WORKFLOW_CONCLUSION }}" != "success" ]; then
echo "Build failed"
exit 1
fi
- name: Remove label
if: ${{ github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀request-ci') }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['🚀request-ci']
})