-
Notifications
You must be signed in to change notification settings - Fork 7
243 lines (226 loc) · 6.99 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
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
# renovate: datasource=npm packageName=npm
NPM_VERSION: 10.8.2
# renovate: datasource=npm packageName=renovate
RENOVATE_VERSION: 37.438.2
jobs:
build-node:
name: Build / Node ${{ matrix.node }}
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18, 20, 22 ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- name: Install latest npm
run: |
npm install --global npm@${{ env.NPM_VERSION }}
npm -v
- name: Install dependencies
run: npm ci
- name: Cache turbo
uses: actions/cache@v4
with:
path: ./.turbo/cache
key: turbo2-cache-build-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo2-cache-build-${{ runner.os }}-
- name: Run Build
run: npm run build
docker:
name: Docker (${{ matrix.platform }})
strategy:
matrix:
platform: [ amd64, arm64 ]
uses: ./.github/workflows/docker-build-and-test.yml
with:
platform: ${{ matrix.platform }}
test-unit:
name: Test / Unit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install latest npm
run: |
npm install --global npm@${{ env.NPM_VERSION }}
npm -v
- name: Install dependencies
run: npm ci
- name: Cache turbo
uses: actions/cache@v4
with:
path: ./.turbo/cache
key: turbo2-cache-test-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo2-cache-test-${{ runner.os }}-
- name: Run Test
run: npm run test
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install latest npm
run: |
npm install --global npm@${{ env.NPM_VERSION }}
npm -v
- name: Install dependencies
run: npm ci
- name: Cache turbo
uses: actions/cache@v4
with:
path: ./.turbo/cache
key: turbo2-cache-lint-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo2-cache-lint-${{ runner.os }}-
- name: Run Lint
run: npm run lint
renovate:
name: Validate renovate config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install renovate
run: npm i -g renovate@${{ env.RENOVATE_VERSION }}
- name: Validate config
run: renovate-config-validator --strict
success:
name: Success
needs: [docker, test-unit, build-node, lint, renovate]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check job status
run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
- name: Success
run: exit 0
publish-docker:
name: Publish / Docker / ${{ matrix.target }}
runs-on: ubuntu-latest
if: github.event_name != 'merge_group'
needs: [success]
strategy:
matrix:
target: [ web, worker, legacy-importer, database-migration ]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Generate image name
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/${{ matrix.target }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV"
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: docker-digests-*
merge-multiple: true
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_ID }}
flavor: |
latest=false
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=tag
type=ref,event=pr
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Merge and push image
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(find /tmp/digests/${{ matrix.target }} -type f -printf '${{ env.IMAGE_ID }}@sha256:%f ')
- name: Inspect image
run: docker buildx imagetools inspect $(jq -cr '.tags[0]' <<< "$DOCKER_METADATA_OUTPUT_JSON")
publish-npm:
name: Publish / npm / ${{ matrix.target }}
runs-on: ubuntu-latest
if: github.event_name != 'merge_group'
needs: [success]
permissions:
contents: read
id-token: write
pull-requests: write
strategy:
matrix:
target: [ ui, icons, helper, tsconfig, publish-package, eslint-plugin-nextjs ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
registry-url: 'https://registry.npmjs.org'
- name: Install latest npm
run: |
npm install --global npm@${{ env.NPM_VERSION }}
npm -v
- name: Install dependencies
run: npm ci
- name: Run Publish
run: npm run publish-package -- --filter=@gw2treasures/${{ matrix.target }} --env-mode=loose
id: publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
GITHUB_EVENT_NAME: ${{ github.event_name }}
- name: Find Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Publish / npm / ${{ matrix.target }}
- name: Delete comment if found but nothing will be published
if: github.event_name == 'pull_request' && steps.fc.outputs.comment-id && !steps.publish.outputs.publish
uses: actions/github-script@v7
with:
script: |
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.fc.outputs.comment-id }}
})
- name: Add comment with packages to be published
if: github.event_name == 'pull_request' && steps.publish.outputs.publish
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
**Publish / npm / ${{ matrix.target }}**
Merging this PR will publish the npm package `${{ steps.publish.outputs.publish }}`