-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (228 loc) · 7.48 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
name: CI
on:
push:
branches: [ "main" ]
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
IMAGE_VERSION: ci-run-${{ github.run_id }}
jobs:
build-node:
name: Build / Node ${{ matrix.node }}
runs-on: ubuntu-24.04
strategy:
matrix:
node: [ 18, 20, 22 ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node
name: Setup Node.js environment
with:
node-version: ${{ matrix.node }}
turbo-cache-key: build
- name: Run Build
run: pnpm run build
lint:
name: Lint
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node
name: Setup Node.js environment
with:
node-version: 20
turbo-cache-key: lint
- name: Run Lint
run: pnpm run lint
build-docker:
name: Build / Docker / ${{ matrix.target }}
runs-on: ubuntu-24.04
strategy:
matrix:
target: [ web, demo, database-migration ]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the Docker image
uses: docker/[email protected]
with:
source: .
files: ./docker-compose.yml
targets: ${{ matrix.target }}
set: |
${{ matrix.target }}.output=type=image,push=true
*.platform=linux/amd64,linux/arm64
*.cache-from=type=gha,scope=build-${{ matrix.target }}
*.cache-to=type=gha,scope=build-${{ matrix.target }},mode=max
test-compose:
name: Test / docker compose
runs-on: ubuntu-24.04
needs: build-docker
steps:
- uses: actions/checkout@v4
- name: Pull images
run: docker compose pull
- run: docker images
- name: Start docker compose
run: docker compose up -d
- name: Wait 15s
run: sleep 15
- run: docker compose ps -a
- run: docker compose logs
- name: Verify docker containers are running
run: docker inspect --format "{{.ID}} {{.Name}} {{.State.Status}} {{.RestartCount}}" $(docker compose ps -aq) | node .github/actions/docker-compose-status.js
- name: Stop docker compose
run: docker compose down
test-kubernetes:
name: Test / kubernetes
runs-on: ubuntu-24.04
needs: build-docker
steps:
- uses: actions/checkout@v4
- uses: nolar/setup-k3d-k3s@v1
with:
version: v1.26
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: build temporary kustomization.yaml
run: |
mkdir -p .temp
cat <<EOF > .temp/kustomization.yaml
resources:
- ../kubernetes/local
images:
- name: ghcr.io/gw2treasures/gw2.me/web
newTag: ${{ env.IMAGE_VERSION }}
- name: ghcr.io/gw2treasures/gw2.me/demo
newTag: ${{ env.IMAGE_VERSION }}
- name: ghcr.io/gw2treasures/gw2.me/database-migration
newTag: ${{ env.IMAGE_VERSION }}
EOF
- run: kubectl kustomize .temp
- run: kubectl apply -k .temp
- run: kubectl rollout status deployment web demo database-pg17 -n gw2me --timeout=120s
- run: kubectl get deployment -n gw2me
if: success() || failure()
- run: kubectl get job -n gw2me
if: success() || failure()
- run: kubectl logs -l app.kubernetes.io/part-of=gw2me -n gw2me --all-containers --ignore-errors
if: failure() || runner.debug == '1'
test-unit:
name: Test / Unit
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node
name: Setup Node.js environment
with:
node-version: 20
turbo-cache-key: test
- name: Run Tests
run: pnpm run test
success:
name: Success
needs: [build-node, lint, test-compose, test-kubernetes, test-unit]
runs-on: ubuntu-24.04
if: always()
steps:
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
- run: exit 0
publish-docker:
name: Publish / Docker / ${{ matrix.target }}
runs-on: ubuntu-24.04
if: github.event_name == 'push'
needs: [success]
strategy:
matrix:
target: [ web, demo, database-migration ]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag image version
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/${{ matrix.target }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
CI_TAG=ci-run-${{ github.run_id }}
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker buildx imagetools create $IMAGE_ID:$CI_TAG --tag $IMAGE_ID:$VERSION
publish-npm:
name: Publish / npm / ${{ matrix.target }}
runs-on: ubuntu-24.04
needs: [success]
permissions:
contents: read
id-token: write
pull-requests: write
strategy:
matrix:
target: [ client ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node
name: Setup Node.js environment
with:
node-version: 20
turbo-cache-key: publish
- name: Run Publish
run: pnpm run publish-package --filter=@gw2me/${{ 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 }}`