-
Notifications
You must be signed in to change notification settings - Fork 0
374 lines (329 loc) · 15 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
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
name: "Build Python Environment Tools Release"
on:
push:
branches: ['main']
pull_request:
branches: ['main', 'dev-*', 'dev']
workflow_dispatch:
jobs:
# Extract the current version of python-environment-tools from upstream GitHub.
get_version:
name: Determine PET Version
runs-on: ubuntu-latest
outputs:
PET_VERSION: ${{ steps.extract_version.outputs.result }}
steps:
# Extract version by getting the latest tag
- name: Determine latest upstream version
id: extract_version
run: |
VERSION=$(curl -s https://api.github.com/repos/microsoft/python-environment-tools/releases/latest | jq -r '.tag_name' | cut -c 2-)
echo "PET version: ${VERSION}"
echo "result=${VERSION}" >> $GITHUB_OUTPUT
# Checkout sources
- name: Checkout Python Environment Tools
uses: actions/checkout@v4
with:
repository: 'microsoft/python-environment-tools'
branch: ${{ steps.extract_version.outputs.result }}
sparse-checkout: |
crates
Cargo.toml
Cargo.lock
sparse-checkout-cone-mode: false
# Check to see whether we have already released this version. If we have, we will skip the
# release process later on.
check_release:
name: Check for Existing Release
runs-on: ubuntu-latest
needs: [get_version]
outputs:
EXISTING_RELEASE: ${{ steps.release_flag.outputs.result }}
steps:
# Checkout sources
- name: Checkout sources
uses: actions/checkout@v4
- name: Check for existing release tag
uses: mukunku/[email protected]
id: check_tag
with:
tag: ${{ needs.get_version.outputs.PET_VERSION }}
- name: Set release flag
id: release_flag
run: |
echo "Existing ${{ needs.get_version.outputs.PET_VERSION }} release: ${{steps.check_tag.outputs.exists}}"
echo "result=${{steps.check_tag.outputs.exists}}" >> $GITHUB_OUTPUT
do_release:
name: Trigger a new release
if: ${{ needs.check_release.outputs.EXISTING_RELEASE == 'false' }}
runs-on: ubuntu-latest
needs: [check_release]
steps:
- name: Dummy step
run: echo ""
# Build PET for macOS. Both arm64 (Apple Silicon) and x64 (Intel) hosts.
build_macos:
name: Build macOS
runs-on: [self-hosted-staging, macos, arm64]
needs: [do_release, get_version]
timeout-minutes: 40
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
max-parallel: 1
matrix:
arch: [arm64, x64]
flavor: [debug, release]
include:
- arch: arm64
arch_terminal: arm64
rust_target_prefix: aarch64
- arch: x64
arch_terminal: x86_64
rust_target_prefix: x86_64
steps:
- name: Install Rust toolchain
run: |
rustup update --no-self-update stable
rustup default stable
# Checkout sources
- name: Checkout sources
uses: actions/checkout@v4
# Compile
- name: Compile PET (${{ matrix.arch }})
env:
npm_config_arch: ${{ matrix.arch }}
KALLICHORE_BUILD_TYPE: ${{ matrix.flavor }}
RUST_TARGET: ${{ matrix.rust_target_prefix }}-apple-darwin
CARGO_FLAGS:
PKG_CONFIG_ALLOW_CROSS: 1
run: |
cargo clean
cargo build ${{ matrix.flavor == 'release' && '--release' || '' }} --target ${{ matrix.rust_target_prefix }}-apple-darwin
# Compress server to a zip file
- name: Create archive
run: |
# Enter the build directory
pushd target/${{ matrix.rust_target_prefix }}-apple-darwin/${{ matrix.flavor }}
# Compress the server to an archive
ARCHIVE="$GITHUB_WORKSPACE/pet-${{ needs.get_version.outputs.PET_VERSION }}-${{ matrix.flavor }}-darwin-${{ matrix.arch }}.zip"
zip -Xry $ARCHIVE kcserver
popd
# Create build artifact
- name: Upload client archive
uses: actions/upload-artifact@v4
with:
name: pet-${{ matrix.flavor }}-darwin-${{ matrix.arch }}-archive
path: pet-${{ needs.get_version.outputs.PET_VERSION }}-${{ matrix.flavor }}-darwin-${{ matrix.arch }}.zip
build_windows:
name: Build Windows
runs-on: windows-latest
timeout-minutes: 40
needs: [do_release, get_version]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
arch: [x64]
flavor: [debug, release]
include:
- arch: x64
rust_target_prefix: x86_64
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Compile PET
env:
PET_BUILD_TYPE: ${{ matrix.flavor }}
RUST_TARGET: ${{ matrix.rust_target_prefix }}-pc-windows-msvc
shell: cmd
run: |
cargo clean
cargo build ${{ matrix.flavor == 'release' && '--release' || '' }} --target ${{ matrix.rust_target_prefix }}-pc-windows-msvc
- name: Create archive
shell: pwsh
run: |
# Compress the server to an archive
$params = @{
Path = "target\${{ matrix.rust_target_prefix }}-pc-windows-msvc\${{ matrix.flavor }}\kcserver.exe", "LICENSE"
DestinationPath = "pet-${{ needs.get_version.outputs.PET_VERSION }}-${{ matrix.flavor }}-windows-${{ matrix.arch }}.zip"
}
Compress-Archive @params
- name: Upload client archive
uses: actions/upload-artifact@v4
with:
name: pet-${{ matrix.flavor }}-windows-${{ matrix.arch }}-archive
path: pet-${{ needs.get_version.outputs.PET_VERSION }}-${{ matrix.flavor }}-windows-${{ matrix.arch }}.zip
build_linux:
name: "Build Linux"
uses: ./.github/workflows/release-linux.yml
needs: [do_release, get_version]
secrets: inherit
with:
version: ${{ needs.get_version.outputs.PET_VERSION }}
create_release:
name: Create Release
runs-on: [self-hosted, macos, arm64]
needs: [do_release, get_version, build_macos, build_windows, build_linux]
env:
GITHUB_TOKEN: ${{ github.token }}
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create release
uses: actions/create-release@v1
id: create_release
with:
draft: false
prerelease: true
release_name: ${{ needs.get_version.outputs.PET_VERSION }}
tag_name: ${{ needs.get_version.outputs.PET_VERSION }}
# Uploads binaries, if we created a release
upload_release_binaries:
name: Upload Release Binaries
runs-on: [self-hosted, macos, arm64]
needs: [create_release, get_version]
permissions:
contents: write # Required for creating a tag and release
env:
GITHUB_TOKEN: ${{ github.token }}
DEBUG_FLAG: ${{ matrix.flavor == 'debug' && '-debug' || '' }}
RELEASE_TAG: ${{ needs.get_version.outputs.PET_VERSION }}
strategy:
max-parallel: 1
matrix:
flavor: [debug, release]
steps:
# Download all binaries
- name: Download PET for macOS arm64 server (${{ matrix.flavor }})
uses: actions/download-artifact@v4
with:
name: pet-${{ matrix.flavor }}-darwin-arm64-archive
- name: Download PET for macOS x64 (${{ matrix.flavor}})
uses: actions/download-artifact@v4
with:
name: pet-${{ matrix.flavor }}-darwin-x64-archive
- name: Download PET for Windows x64 (${{ matrix.flavor}})
uses: actions/download-artifact@v4
with:
name: pet-${{ matrix.flavor }}-windows-x64-archive
- name: Download PET for Linux x64 (${{ matrix.flavor}})
uses: actions/download-artifact@v4
with:
name: pet-${{ matrix.flavor }}-linux-x64-archive
- name: Download PET for Linux arm64 (${{ matrix.flavor}})
uses: actions/download-artifact@v4
with:
name: pet-${{ matrix.flavor }}-linux-arm64-archive
# Combine macOS binaries to a single binary with lipo
- name: Create macOS universal binary
run: |
# Decompress x64 builds
rm -rf x64 && mkdir x64 && pushd x64
unzip ../pet-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-darwin-x64.zip
popd
# Decompress arm64 build
rm -rf arm64 && mkdir arm64 && pushd arm64
unzip ../pet-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-darwin-arm64.zip
popd
# Create a universal binary
lipo -create x64/kcserver arm64/kcserver -output kcserver
# Compress and bundle licenses
ARCHIVE="$GITHUB_WORKSPACE/pet-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-universal.zip"
zip -Xry $ARCHIVE kcserver
- name: Upload macOS release artifact (universal)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: pet-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-universal.zip
asset_name: pet-${{ needs.get_version.outputs.PET_VERSION }}${{ env.DEBUG_FLAG }}-darwin-universal.zip
asset_content_type: application/octet-stream
- name: Upload Windows release artifact (x64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: pet-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-windows-x64.zip
asset_name: pet-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-windows-x64.zip
asset_content_type: application/octet-stream
- name: Upload Linux release artifacts (x64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: pet-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-linux-x64.zip
asset_name: pet-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-linux-x64.zip
asset_content_type: application/octet-stream
- name: Upload Linux release artifacts (arm64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: pet-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-linux-arm64.zip
asset_name: pet-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-linux-arm64.zip
asset_content_type: application/octet-stream
# Publish new releases to the pet-builds public repository
publish_public_release:
name: Publish Public Release
runs-on: ubuntu-latest
needs: [upload_release_binaries, get_version]
permissions:
contents: write # Required for creating a tag and release
env:
RELEASE_TAG: ${{ needs.get_version.outputs.PET_VERSION }}
steps:
- name: Download macOS release
uses: dsaltares/[email protected]
with:
version: tags/${{ env.RELEASE_TAG }}
file: pet-${{ env.RELEASE_TAG }}-darwin-universal.zip
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download Linux release (x64)
uses: dsaltares/[email protected]
with:
version: tags/${{ env.RELEASE_TAG }}
file: pet-${{ env.RELEASE_TAG }}-linux-x64.zip
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download Linux release (arm64)
uses: dsaltares/[email protected]
with:
version: tags/${{ env.RELEASE_TAG }}
file: pet-${{ env.RELEASE_TAG }}-linux-arm64.zip
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download Windows release
uses: dsaltares/[email protected]
with:
version: tags/${{ env.RELEASE_TAG }}
file: pet-${{ env.RELEASE_TAG }}-windows-x64.zip
token: ${{ secrets.GITHUB_TOKEN }}
# - name: Create access token
# uses: actions/create-github-app-token@v1
# id: app-token
# with:
# app-id: ${{ vars.POSITRON_BOT_APP_ID }}
# private-key: ${{ secrets.POSITRON_BOT_PRIVATE_KEY }}
# owner: ${{ github.repository_owner }}
# repositories: |
# pet
# pet-builds
# - name: Create public release
# uses: softprops/action-gh-release@v2
# with:
# token: ${{ steps.app-token.outputs.token }}
# repository: posit-dev/positron-pet-builds
# tag_name: ${{ env.RELEASE_TAG }}
# prerelease: true
# fail_on_unmatched_files: true
# generate_release_notes: false
# body: |
# PET ${{env.RELEASE_TAG }}
# files: |
# pet-${{ env.RELEASE_TAG }}-darwin-universal.zip
# pet-${{ env.RELEASE_TAG }}-windows-x64.zip
# pet-${{ env.RELEASE_TAG }}-linux-x64.zip
# pet-${{ env.RELEASE_TAG }}-linux-arm64.zip