-
Notifications
You must be signed in to change notification settings - Fork 10
234 lines (225 loc) · 9.75 KB
/
release.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
name: Release
on:
push:
branches:
- main
pull_request:
concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
NODE_NO_WARNINGS: 1
CI: true
jobs:
dependencies:
if: github.event_name == 'pull_request' && github.event.pull_request.title != 'Upcoming Release Changes'
name: Dependencies
uses: the-guild-org/shared-config/.github/workflows/changesets-dependencies.yml@v1
with:
node-version-file: .node-version
secrets:
githubToken: ${{ secrets.BOT_GITHUB_TOKEN }}
snapshot:
if: github.event_name == 'pull_request'
name: Snapshot
permissions:
contents: read
id-token: write
pull-requests: write
uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@v1
with:
node-version-file: .node-version
npmTag: ${{ github.event.pull_request.title == 'Upcoming Release Changes' && 'rc' || 'alpha' }}
restoreDeletedChangesets: ${{ github.event.pull_request.title == 'Upcoming Release Changes' && true || false }}
secrets:
githubToken: ${{ secrets.BOT_GITHUB_TOKEN }}
npmToken: ${{ secrets.NPM_TOKEN }}
stable:
if: github.ref == 'refs/heads/main'
name: Stable
permissions:
contents: read
id-token: write
pull-requests: write
uses: the-guild-org/shared-config/.github/workflows/release-stable.yml@v1
with:
node-version-file: .node-version
releaseScript: changeset publish
versionScript: changeset version
secrets:
githubToken: ${{ secrets.BOT_GITHUB_TOKEN }}
npmToken: ${{ secrets.NPM_TOKEN }}
ghcr:
runs-on: ubuntu-latest
strategy:
matrix:
runtime: [Node, Bun]
name: ${{ matrix.runtime }} Docker image
needs: [stable, snapshot]
if: always() && (
contains(needs.stable.outputs.publishedPackages, '@graphql-hive/gateway') ||
contains(needs.snapshot.outputs.publishedPackages, '@graphql-hive/gateway')
)
steps:
- name: Version
uses: actions/github-script@v7
id: ver-gateway
with:
script: |
const publishedPackages = ${{ needs.stable.outputs.publishedPackages || needs.snapshot.outputs.publishedPackages }};
const gateway = publishedPackages.find((p) => p.name === '@graphql-hive/gateway');
if (!gateway) {
return core.setFailed('@graphql-hive/gateway was not published!');
}
const { version } = gateway;
let r;
if (context.eventName === 'pull_request') {
r = { version, tags: version };
} else {
const [major, minor] = version.split('.');
if (!major || !minor) {
return core.setFailed(`Unknown major or minor in version "${version}"!`);
}
r = { version, tags: `latest,${major},${major}.${minor},${version}` };
}
console.log(r);
return r;
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up env
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: Build
run: yarn build
- name: Bundle
run: yarn workspace @graphql-hive/gateway bundle
- name: Inject version
run: yarn workspace @graphql-hive/gateway tsx scripts/inject-version ${{ fromJSON(steps.ver-gateway.outputs.result).version }}
- name: Bake and Push
uses: docker/bake-action@v5
env:
GATEWAY_TAGS: ${{ fromJSON(steps.ver-gateway.outputs.result).tags }}
with:
targets: gateway${{ matrix.runtime == 'Bun' && '_bun' || '' }}
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
push: true
- if: github.event_name == 'pull_request'
name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
# match pr comment like with changesets-snapshot-action from the guild's shared-config
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
header: snapshot-release-${{ matrix.runtime == 'Bun' && 'bun-' || '' }}docker-image
message: |
### 🚀 Snapshot Release (${{matrix.runtime}} Docker Image)
The latest changes of this PR are available as image on GitHub Container Registry (based on the declared `changesets`):
```
ghcr.io/graphql-hive/gateway:${{ fromJSON(steps.ver-gateway.outputs.result).version }}${{ matrix.runtime == 'Bun' && '-bun' || '' }}
```
bin:
name: Binary built on ${{ matrix.os }}
needs: [stable, snapshot]
if: always() && (
contains(needs.stable.outputs.publishedPackages, '@graphql-hive/gateway') ||
contains(needs.snapshot.outputs.publishedPackages, '@graphql-hive/gateway')
)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
steps:
- name: Version
uses: actions/github-script@v7
id: ver-gateway
with:
result-encoding: string
script: |
const publishedPackages = ${{ needs.stable.outputs.publishedPackages || needs.snapshot.outputs.publishedPackages }};
const gateway = publishedPackages.find((p) => p.name === '@graphql-hive/gateway');
if (!gateway) {
return core.setFailed('@graphql-hive/gateway was not published!');
}
const { version } = gateway;
console.log({ version });
return version;
- name: Checkout
uses: actions/checkout@v4
- if: runner.os == 'Windows'
name: Install Windows SDK
run: scripts\install-winsdk.ps1
- name: Set up env
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: Build
run: yarn build
- name: Bundle
run: yarn workspace @graphql-hive/gateway bundle
- name: Inject version
run: yarn workspace @graphql-hive/gateway tsx scripts/inject-version "${{ steps.ver-gateway.outputs.result }}"
- name: Package binary
run: yarn workspace @graphql-hive/gateway tsx scripts/package-binary
- name: Set binary info
id: binary
run: |
echo "name=hive-gateway-${{ runner.os }}-${{ runner.arch }}${{ runner.os == 'Windows' && '.exe' || ''}}" >> ${{ runner.os == 'Windows' && '$ENV:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }}
echo "path=packages/gateway/hive-gateway${{ runner.os == 'Windows' && '.exe' || '' }}" >> ${{ runner.os == 'Windows' && '$ENV:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }}
- if: github.ref == 'refs/heads/main'
name: Compress binary
id: compressed-binary
run: |
gzip -9 ${{ steps.binary.outputs.path }}
echo "name=${{ steps.binary.outputs.name }}.gz" >> ${{ runner.os == 'Windows' && '$ENV:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }}
echo "path=${{ steps.binary.outputs.path }}.gz" >> ${{ runner.os == 'Windows' && '$ENV:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }}
- if: github.ref == 'refs/heads/main'
name: Upload release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.BOT_GITHUB_TOKEN }}
tag: hive-gateway@${{ steps.ver-gateway.outputs.result }}
release_name: hive-gateway@${{ steps.ver-gateway.outputs.result }}
asset_name: ${{ steps.compressed-binary.outputs.name }}
file: ${{ steps.compressed-binary.outputs.path }}
body: Pre-built binaries of the Hive Gateway for the **@graphql-hive/gateway@${{ steps.ver-gateway.outputs.result }}** release.
overwrite: true
- if: github.event_name == 'pull_request'
name: Upload artifact
id: upload
uses: actions/upload-artifact@v4
with:
name: ${{ steps.binary.outputs.name }}
path: ${{ steps.binary.outputs.path }}
- if: github.event_name == 'pull_request'
name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
# match pr comment like with changesets-snapshot-action from the guild's shared-config
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
header: snapshot-release-binary-${{ runner.os }}-${{ runner.arch }}
message: |
### 🚀 Snapshot Release (Binary for `${{ runner.os }}-${{ runner.arch }}`)
The latest changes of this PR are available for download (based on the declared `changesets`).
[![Download](https://custom-icon-badges.demolab.com/badge/-Download-blue?style=for-the-badge&logo=download&logoColor=white "Download")](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.upload.outputs.artifact-id }})
examples:
name: Examples
needs: [stable, snapshot]
if: always() && github.event.pull_request.title != 'Upcoming Release Changes'
uses: graphql-hive/gateway/.github/workflows/examples.yml@main
# NOTE: it's possible to use snapshot releases in examples on PRs but we dont because
# want the main branch to always use examples of stable releases. yeah sure, the examples
# workflow will open a PR to update the examples to stable ones - but there will be some window
# during which the examples on main will use snapshots and we want to avoid that
# with:
# publishedPackages: ${{needs.stable.outputs.publishedPackages || needs.snapshot.outputs.publishedPackages}}
secrets:
token: ${{secrets.BOT_GITHUB_TOKEN}}