-
Notifications
You must be signed in to change notification settings - Fork 10
200 lines (194 loc) · 8.35 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
name: Release
on:
push:
branches:
- main
pull_request:
concurrency: ${{ github.workflow }}-${{ github.ref }}
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
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
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:
name: GitHub Container Registry
runs-on: ubuntu-latest
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: 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
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-docker-image
message: |
### 🚀 Snapshot Release (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 }}
```
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:
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
uses: fbactions/setup-winsdk@v2
with:
# we want exact version because the signtool path depends on it in package-binary.ts
winsdk-build-version: 18362
- name: Set up env
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- 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 "path=packages/gateway/hive-gateway${{ runner.os == 'Windows' && '.exe.gz' || '.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.binary.outputs.name }}
file: ${{ steps.compressed-binary.outputs.path }}
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 }})