-
Notifications
You must be signed in to change notification settings - Fork 1.5k
320 lines (277 loc) · 11.8 KB
/
publish.yml
File metadata and controls
320 lines (277 loc) · 11.8 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
314
315
316
317
318
319
320
name: "publish"
# change this when ready to release if you want CI/CD
on:
workflow_dispatch:
inputs:
interactionId:
description: "Discord Interaction ID"
required: false
type: string
env:
CN_APPLICATION: cap/cap
APP_CARGO_TOML: apps/desktop/src-tauri/Cargo.toml
SENTRY_ORG: cap-s2
SENTRY_PROJECT: cap-desktop
jobs:
draft:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read_version.outputs.value }}
needs_release: ${{ steps.create_tag.outputs.tag_existed != 'true' }}
cn_release_stdout: ${{ steps.create_cn_release.outputs.stdout }}
gh_release_url: ${{ steps.create_gh_release.outputs.url }}
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Read version number
uses: SebRollen/toml-action@v1.0.2
id: read_version
with:
file: ${{ env.APP_CARGO_TOML }}
field: "package.version"
- name: Create tag
id: create_tag
if: ${{ steps.create_tag.outputs.tag_existed != 'true' }}
uses: actions/github-script@v7
with:
script: |
const tag = "cap-v${{ steps.read_version.outputs.value }}";
const tagRef = `tags/${tag}`;
const TAG_EXISTED = "tag_existed";
const TAG_NAME = "tag_name";
core.setOutput(TAG_NAME, tag);
async function main() {
let tagExisted = true;
try {
await github.rest.git.getRef({
ref: tagRef,
owner: context.repo.owner,
repo: context.repo.repo,
});
tagExisted = true;
core.notice(`Release skipped as tag '${tag}' already exists. Update the version in '${{ env.APP_CARGO_TOML }}' before starting another release.`);
} catch (error) {
if ("status" in error && error.status === 404) tagExisted = false;
else throw error;
}
core.setOutput(TAG_EXISTED, tagExisted);
if (!tagExisted)
await github.rest.git.createRef({
ref: `refs/${tagRef}`,
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
});
}
main();
- name: Create draft CN release
id: create_cn_release
uses: crabnebula-dev/cloud-release@v0
with:
command: release draft ${{ env.CN_APPLICATION }} ${{ steps.read_version.outputs.value }} --framework tauri
api-key: ${{ secrets.CN_API_KEY }}
- name: Create draft GH release
id: create_gh_release
# TODO: Change to stable version when available
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.read_version.outputs.value }}
tag_name: ${{ steps.create_tag.outputs.tag_name }}
draft: true
generate_release_notes: true
- name: Update Discord interaction
if: ${{ inputs.interactionId != '' }}
uses: actions/github-script@v7
with:
script: |
async function main() {
const token = await core.getIDToken("cap-discord-bot");
const cnReleaseId = JSON.parse(`${{ steps.create_cn_release.outputs.stdout }}`).id;
const resp = await fetch("https://cap-discord-bot.brendonovich.workers.dev/github-workflow", {
method: "POST",
body: JSON.stringify({
type: "release-ready",
tag: "${{ steps.create_tag.outputs.tag_name }}",
version: "${{ steps.read_version.outputs.value }}",
releaseUrl: "${{ steps.create_gh_release.outputs.url }}",
interactionId: "${{ inputs.interactionId }}",
cnReleaseId
}),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
}
});
if(resp.status !== 200) throw new Error(await resp.text());
}
main();
build:
needs: draft
if: ${{ needs.draft.outputs.needs_release == 'true' }}
permissions:
contents: write
actions: read
strategy:
fail-fast: false
matrix:
settings:
- target: x86_64-apple-darwin
runner: macos-latest-large
- target: aarch64-apple-darwin
runner: macos-latest-large
- target: x86_64-pc-windows-msvc
runner: windows-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
runs-on: ${{ matrix.settings.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create API Key File
run: echo "${{ secrets.APPLE_API_KEY_FILE }}" > api.p8
- uses: apple-actions/import-codesign-certs@v2
if: ${{ matrix.settings.runner == 'macos-latest-large' }}
with:
p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
- name: Verify certificate
if: ${{ matrix.settings.runner == 'macos-latest-large' }}
run: security find-identity -v -p codesigning ${{ runner.temp }}/build.keychain
- name: Rust setup
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.settings.target }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.settings.target }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: ./.github/actions/setup-js
- name: Create .env file in root
run: |
echo "appVersion=${{ needs.draft.outputs.version }}" >> .env
echo "VITE_ENVIRONMENT=production" >> .env
echo "CAP_DESKTOP_SENTRY_URL=https://6a3b6a09e6ae976c2ad6fff710e88748@o4506859771527168.ingest.us.sentry.io/4508330917101568" >> .env
echo "NEXT_PUBLIC_WEB_URL=${{ secrets.NEXT_PUBLIC_WEB_URL }}" >> .env
echo 'NEXTAUTH_URL=${{ secrets.NEXT_PUBLIC_WEB_URL }}' >> .env
echo 'VITE_POSTHOG_KEY=${{ secrets.VITE_POSTHOG_KEY }}' >> .env
echo 'VITE_POSTHOG_HOST=${{ secrets.VITE_POSTHOG_HOST }}' >> .env
echo 'VITE_SERVER_URL=${{ secrets.NEXT_PUBLIC_WEB_URL }}' >> .env
echo 'RUST_TARGET_TRIPLE=${{ matrix.settings.target }}' >> .env
- name: Build app
working-directory: apps/desktop
run: |
pnpm -w cap-setup
pnpm build:tauri --target ${{ matrix.settings.target }} --config src-tauri/tauri.prod.conf.json
env:
# https://github.com/tauri-apps/tauri-action/issues/740
CI: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# codesigning
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
# notarization
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_KEY_PATH: ${{ github.workspace }}/api.p8
APPLE_KEYCHAIN: ${{ runner.temp }}/build.keychain
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
# - name: Upload unsigned Windows installer
# if: ${{ runner.os == 'Windows' }}
# id: upload_unsigned_windows_installer
# uses: actions/upload-artifact@v4
# with:
# name: unsigned-windows-installer
# path: target/${{ matrix.settings.target }}/release/bundle/nsis/*.exe
# if-no-files-found: error
# - name: Submit SignPath signing request
# if: ${{ runner.os == 'Windows' }}
# id: submit_signpath_signing_request
# uses: signpath/github-action-submit-signing-request@v1
# with:
# api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
# organization-id: ${{ secrets.SIGNPATH_ORGANIZATION_ID }}
# project-slug: ${{ secrets.SIGNPATH_PROJECT_SLUG }}
# signing-policy-slug: ${{ secrets.SIGNPATH_SIGNING_POLICY_SLUG }}
# github-artifact-id: ${{ steps.upload_unsigned_windows_installer.outputs.artifact-id }}
# wait-for-completion: true
# output-artifact-directory: signed-windows-installer
# - name: Restore signed Windows installer
# if: ${{ runner.os == 'Windows' }}
# shell: pwsh
# run: |
# $signedDir = "signed-windows-installer"
# $bundleDir = "target/${{ matrix.settings.target }}/release/bundle/nsis"
# if (-not (Test-Path $signedDir)) {
# throw "Signed artifact directory '$signedDir' not found."
# }
# $executables = Get-ChildItem -Path $signedDir -Filter *.exe -Recurse
# if (-not $executables) {
# throw "No signed executables found in '$signedDir'."
# }
# # Copy signed executables back to the original bundle location for CrabNebula upload
# Write-Host "Copying signed executables to: $bundleDir"
# Copy-Item -Path (Join-Path $signedDir '*.exe') -Destination $bundleDir -Force
# # List the files to verify
# Write-Host "Files in bundle directory after signing:"
# Get-ChildItem -Path $bundleDir -Filter *.exe | ForEach-Object { Write-Host " - $($_.Name)" }
- name: Upload assets
uses: crabnebula-dev/cloud-release@v0
with:
working-directory: apps/desktop
command: release upload ${{ env.CN_APPLICATION }} "${{ needs.draft.outputs.version }}" --framework tauri
api-key: ${{ secrets.CN_API_KEY }}
env:
TAURI_BUNDLE_PATH: ../..
- uses: matbour/setup-sentry-cli@8ef22a4ff03bcd1ebbcaa3a36a81482ca8e3872e
- name: Upload debug symbols to Sentry
if: ${{ runner.os == 'macOS' }}
shell: bash
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
sentry-cli debug-files upload -o ${{ env.SENTRY_ORG }} -p ${{ env.SENTRY_PROJECT }} target/Cap.dSYM
- name: Upload debug symbols to Sentry
if: ${{ runner.os == 'Windows' }}
shell: bash
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
sentry-cli debug-files upload -o ${{ env.SENTRY_ORG }} -p ${{ env.SENTRY_PROJECT }} target/${{ matrix.settings.target }}/release/cap_desktop.pdb
done:
needs: [draft, build]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Send Discord notification
if: ${{ inputs.interactionId != '' }}
uses: actions/github-script@v7
with:
script: |
async function main() {
const token = await core.getIDToken("cap-discord-bot");
const cnReleaseId = JSON.parse(`${{ needs.draft.outputs.cn_release_stdout }}`).id;
const resp = await fetch("https://cap-discord-bot.brendonovich.workers.dev/github-workflow", {
method: "POST",
body: JSON.stringify({
type: "release-done",
interactionId: "${{ inputs.interactionId }}",
version: "${{ needs.draft.outputs.version }}",
releaseUrl: "${{ needs.draft.outputs.gh_release_url }}",
cnReleaseId
}),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
}
});
if(resp.status !== 200) throw new Error(await resp.text());
}
main();