-
Notifications
You must be signed in to change notification settings - Fork 19
313 lines (292 loc) · 12 KB
/
Copy pathbuild-router.yaml
File metadata and controls
313 lines (292 loc) · 12 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
name: build-router
on:
push:
branches:
- main
pull_request:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
actions: write
contents: write
issues: read
checks: write
pull-requests: write
packages: write
id-token: write
env:
DOCKER_IMAGE_NAME: ghcr.io/graphql-hive/router
DOCKER_LICENSE: MIT
DOCKER_VENDOR: theguild
DOCKER_PLATFORMS: linux/amd64,linux/arm64
ZIG_VERSION: 0.15.1
BINARY_NAME: hive_router
jobs:
config:
name: check / config
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router/v'))
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2
with:
shared-key: ${{ hashFiles('**/Cargo.lock') }}
- name: generate config schema
run: cargo router-config
- name: setup node
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: generate documentation
working-directory: docs/generator
run: npm run generate
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
name: upload config artifact
with:
name: router-config.schema.json
path: router-config.schema.json
if-no-files-found: error
- name: Upload config to release
uses: svenstaro/upload-release-action@6b7fa9f267e90b50a19fef07b3596790bb941741 # v2
if: ${{ github.event_name == 'release' }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: router-config.schema.json
asset_name: router-config.schema.json
tag: ${{ github.ref }}
- name: check config docs changes
run: git diff --exit-code ./docs/README.md
binary:
name: publish / binary / ${{ matrix.name }}
if: |
github.event_name == 'push' || github.event_name == 'pull_request' || (
github.event_name == 'release' &&
(
startsWith(github.event.release.tag_name, 'hive-router/v') ||
startsWith(github.event.release.tag_name, 'node-addon/v')
)
)
runs-on: ${{ matrix.action_runner }}
strategy:
matrix:
include:
- name: linux_arm64
rust_target: aarch64-unknown-linux-gnu
zigbuild: true
zigbuild_target: aarch64-unknown-linux-gnu.2.28
action_runner: ubuntu-latest
- name: linux_amd64
rust_target: x86_64-unknown-linux-gnu
zigbuild: true
zigbuild_target: x86_64-unknown-linux-gnu.2.28
action_runner: ubuntu-latest
- name: macos_arm64
zigbuild: false
rust_target: aarch64-apple-darwin
action_runner: macos-15
- name: macos_amd64
zigbuild: false
rust_target: x86_64-apple-darwin
action_runner: macos-15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
name: checkout
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
name: rust toolchain (${{ matrix.rust_target }})
with:
target: ${{ matrix.rust_target }}
cache-key: ${{ matrix.name }}
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2
with:
shared-key: ${{ hashFiles('**/Cargo.lock') }}
# Only if using Zigbuild
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2
name: setup zig
if: ${{ matrix.zigbuild }}
with:
version: ${{ env.ZIG_VERSION }}
- run: cargo install cargo-zigbuild
name: install zigbuild
if: ${{ matrix.zigbuild }}
- name: zigbuild (${{ matrix.zigbuild_target }})
if: ${{ matrix.zigbuild }}
run: cargo zigbuild --release --target ${{ matrix.zigbuild_target }}
# Only if NOT using Zigbuild
- name: cargo build (${{ matrix.rust_target }})
run: cargo build --release --target ${{ matrix.rust_target }}
if: ${{ !matrix.zigbuild }}
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
name: upload router artifact
with:
name: hive_router_${{ matrix.name }}
path: |
target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
if-no-files-found: error
# napi build will use zigbuild when cross compiling
- name: setup node
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: node-addon build (${{ matrix.rust_target }})
working-directory: lib/node-addon
env:
CROSS_COMPILE: ${{ matrix.zigbuild }}
TARGET: ${{ matrix.rust_target }}
run: npm run build
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
name: upload node addon artifact
with:
name: node_addon_${{ matrix.name }}
path: |
lib/node-addon/*.node
if-no-files-found: error
- name: Upload binaries to router release
uses: svenstaro/upload-release-action@6b7fa9f267e90b50a19fef07b3596790bb941741 # v2
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router/v')
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
asset_name: hive_router_${{ matrix.name }}
tag: ${{ github.ref }}
# NOTE: would publish from release.yaml but we need the artifacts. doing it from here is simpler
npm-publish:
name: publish / node-addon
runs-on: ubuntu-latest
needs:
- binary
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'node-addon/v')
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: setup node
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: download node addon artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
pattern: node_addon_*
path: lib/node-addon
- name: prepare artifacts
working-directory: lib/node-addon
run: |
mv ./node_addon_linux_arm64/* .
mv ./node_addon_linux_amd64/* .
mv ./node_addon_macos_arm64/* .
mv ./node_addon_macos_amd64/* .
- name: publish
working-directory: lib/node-addon
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --provenance
- name: pack
working-directory: lib/node-addon
run: npm pack
- name: upload pack to release
uses: svenstaro/upload-release-action@6b7fa9f267e90b50a19fef07b3596790bb941741 # v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file_glob: true
file: lib/node-addon/*.tgz
tag: ${{ github.ref }}
docker:
name: build / docker
runs-on: ubuntu-latest
needs:
- binary
outputs:
docker_image_digest: ${{ steps.docker.outputs.digest }}
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: setup qemu
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: setup buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: setup docker tags
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
labels: |
org.opencontainers.image.licenses=${{ env.DOCKER_LICENSE }}
org.opencontainers.image.vendor=${{ env.DOCKER_VENDOR }}
tags: |
type=ref,event=pr
type=semver,pattern={{version}},value=${{ github.event.release.name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=match,group=1,pattern=router/v(.*),value=${{ github.event.release.tag_name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=sha
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
- name: download binary artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
path: artifacts
pattern: hive_router_*
- name: prepare artifacts
run: |
mkdir -p ./target/linux/arm64
mkdir -p ./target/linux/amd64
mv ./artifacts/${{ env.BINARY_NAME }}_linux_arm64/${{ env.BINARY_NAME }} ./target/linux/arm64/${{ env.BINARY_NAME }}
mv ./artifacts/${{ env.BINARY_NAME }}_linux_amd64/${{ env.BINARY_NAME }} ./target/linux/amd64/${{ env.BINARY_NAME }}
ls -ltra ./target/linux/arm64/
ls -ltra ./target/linux/amd64/
- uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build and push
id: docker
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
file: ./docker/router.Dockerfile
context: .
platforms: ${{ env.DOCKER_PLATFORMS }}
push: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || github.event_name == 'release' || github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: docker pr comment
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
with:
header: ${{ github.workflow }}
message: |
🐋 This PR was built and pushed to the following [Docker images](https://github.com/graphql-hive?ecosystem=container&tab=packages&visibility=public):
**Image Names**: `${{ env.DOCKER_IMAGE_NAME }}`
**Platforms**: `${{ env.DOCKER_PLATFORMS }}`
**Image Tags**: `${{ steps.meta.outputs.tags }}`
<details>
<summary>Docker metadata</summary>
```json
${{ steps.docker.outputs.metadata }}
```
</details>
test-docker-image:
name: test / docker
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
needs:
- docker
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: run router image in background
run: |
echo "Docker image: ${{ env.DOCKER_IMAGE_NAME }}@${{ needs.docker.outputs.docker_image_digest }}"
docker run -d --name router -p 4000:4000 \
-e SUPERGRAPH_FILE_PATH="/app/supergraph.graphql" \
-v ./bench/supergraph.graphql:/app/supergraph.graphql \
${{ env.DOCKER_IMAGE_NAME }}@${{ needs.docker.outputs.docker_image_digest }}
sleep 5
- name: dump router logs
run: |
docker logs router
- name: test dummy request
run: |
TEST_RESPONSE=$(curl --fail -v -H "Content-Type: application/json" -d '{"query": "{ __typename }"}' http://localhost:4000/graphql)
echo $TEST_RESPONSE