-
Notifications
You must be signed in to change notification settings - Fork 2
172 lines (148 loc) · 5.34 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
# 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.event.pull_request.head.repo.fork == false) ||
(github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.fork == true && contains(github.event.label.name, '🚀request-ci'))
}}
steps:
- name: 🛎 Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: 🏗 Setup node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
cache: yarn
cache-dependency-path: yarn.lock
- 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: 👨🏻💻 Install dependencies
run: yarn install --frozen-lockfile
- name: 👀 Run linter
if: steps.package-json.outputs.lint == 'true'
run: yarn lint
- name: 🎁 Run package
if: steps.package-json.outputs.package == 'true'
run: yarn package
- name: 🏃 Run compile
if: steps.package-json.outputs.compile == 'true'
run: yarn compile
- name: 🏗️ Run build & generate (Nuxt.js)
if: >-
steps.package-json.outputs.build == 'true' &&
steps.package-json.outputs.disabled-build == 'false' &&
steps.package-json.outputs.generate == 'true' &&
steps.package-json.outputs.disabled-generate == 'false'
run: |
yarn build
yarn generate
- name: 🧪 Run tests
if: steps.package-json.outputs.test == 'true'
run: yarn test
env:
PIXIV_REFRESH_TOKEN: ${{ secrets.PIXIV_REFRESH_TOKEN }}
- 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@v3
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@v3
with:
name: output
path: output
- name: 👀 Check git status
run: |
git status
git diff --exit-code || (echo "Git status is not clean." && exit 1)
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@v6
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']
})