Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
195 changes: 195 additions & 0 deletions .github/workflows/release-desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Releases the app in desktop/ for Windows, Linux, and macOS as a release of this repository tagged
# desktop-vX.Y.Z. The repository's latest release stays the CLI's, which install-cli.sh and
# install-cli.ps1 download, and the apps find the newest desktop-v release through the GitHub API.
# A tag desktop-vX.Y.Z, naming the version in desktop/mygo.config.ts, drafts the release with the
# version's section of desktop/CHANGELOG.md as its notes, then builds Windows x64, Linux x64,
# Linux arm64 and macOS on Apple silicon side by side. A run by hand does the same for the commit it
# runs on, naming the release after desktop/mygo.config.ts; the tag appears when the draft is
# published. Each build runs `bun run release-desktop <platform>`: the CLI (with cargo-zigbuild off
# the Mac), then `go tool mygo build -upload`, which builds the app and its installer, signs the
# macOS app with the Developer ID and notarizes its disk image, signs the update archive and
# deltas, and uploads them to the draft. Publishing the draft, without making it the latest
# release, once every platform is there makes it the update apps see. docs/releasing-desktop.md
# has the steps.
name: Release desktop

on:
push:
tags: ["desktop-v*"]
workflow_dispatch:

permissions:
contents: read

# One run at a time, so two runs never upload to the same release.
concurrency:
group: release-desktop

env:
CARGO_TERM_COLOR: always

jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.package.outputs.version }}
tag: ${{ steps.package.outputs.tag }}
steps:
- uses: actions/checkout@v7
- uses: oven-sh/setup-bun@v2
- id: package
name: Name the release after desktop/mygo.config.ts
env:
GH_TOKEN: ${{ github.token }}
run: |
version=$(bun -e 'console.log((await import("./desktop/mygo.config.ts")).default({ command: "build" }).version)')
tag=desktop-v$version
# A pushed tag, or a run by hand on one, has to name the version the app says it is.
if [[ $GITHUB_REF_TYPE == tag && $GITHUB_REF_NAME != "$tag" ]]; then
echo "::error::$GITHUB_REF_NAME does not match version $version in desktop/mygo.config.ts: set \"version\" there to ${GITHUB_REF_NAME#desktop-v} and tag that commit"
exit 1
fi
# A release takes the tag that exists, so the builds have to come from its commit.
if tagged=$(gh api "repos/$GITHUB_REPOSITORY/commits/$tag" --jq .sha 2>/dev/null) && [[ $tagged != "$GITHUB_SHA" ]]; then
echo "::error::$tag already tags $tagged: run this on that commit, or bump \"version\" in desktop/mygo.config.ts"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"

# The builds upload into one draft, which this job makes first; each would make its own.
draft:
needs: version
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: oven-sh/setup-bun@v2
- name: Draft ${{ needs.version.outputs.tag }}
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.version.outputs.tag }}
VERSION: ${{ needs.version.outputs.version }}
run: |
if ! state=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft --jq 'if .isDraft then "draft" else "published" end' 2>/dev/null); then
state=none
fi
case $state in
published)
echo "::error::$TAG is already published: bump \"version\" in desktop/mygo.config.ts"
exit 1
;;
draft)
# An earlier run's draft takes these builds, from this commit.
echo "::notice::the draft $TAG takes these builds"
gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA"
;;
none)
bun -e '
import { extractReleaseNotes } from "./scripts/changelog.ts"
const notes = extractReleaseNotes(await Bun.file("desktop/CHANGELOG.md").text(), process.env.VERSION)
if (!notes) {
console.error(`::error::desktop/CHANGELOG.md has no "## [${process.env.VERSION}]" section`)
process.exit(1)
}
await Bun.write("notes.md", notes + "\n")
'
# Not the latest release, which stays the CLI's. On the tag's commit, or on the commit a
# run by hand builds, where publishing the draft makes the tag.
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --draft --latest=false --target "$GITHUB_SHA" --title "Lorca for Windows, Linux, and macOS $VERSION" --notes-file notes.md
;;
esac

build:
name: build ${{ matrix.platform }}
needs: draft
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
# A platform that fails leaves the others to finish their uploads.
fail-fast: false
matrix:
include:
# MyGo builds Windows and Linux from Linux without cgo, and zig, through cargo-zigbuild,
# builds the CLI inside each app as the CLI releases do: static (musl) for Linux. The
# macOS app needs a Mac, which signs it, notarizes it, and makes its disk image; it is
# for Apple silicon, as the CLI's macOS release is.
- { platform: windows/amd64, target: x86_64-pc-windows-gnu, os: ubuntu-latest }
- { platform: linux/amd64, target: x86_64-unknown-linux-musl, os: ubuntu-latest }
- { platform: linux/arm64, target: aarch64-unknown-linux-musl, os: ubuntu-latest }
- { platform: darwin/arm64, target: aarch64-apple-darwin, os: macos-26 }
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: mlugg/setup-zig@v2
if: runner.os == 'Linux'
with:
version: 0.16.0
- uses: taiki-e/install-action@v2
if: runner.os == 'Linux'
with:
tool: cargo-zigbuild
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- uses: actions/setup-go@v6
with:
go-version-file: desktop/go.mod
cache-dependency-path: desktop/go.sum
- uses: oven-sh/setup-bun@v2
# makensis, which mygo build needs for the Windows installer on Linux.
- name: Install NSIS
if: startsWith(matrix.platform, 'windows/')
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends nsis
# The Developer ID Application certificate, alone in a keychain of its own,
# so release-desktop's partial name "Developer ID Application" matches exactly
# one identity, and the notarytool profile NOTARY, signed in with the App Store Connect API
# key, in the same keychain, where mygo.config.ts finds it through NOTARY_KEYCHAIN.
- name: Add the signing identity and the notary profile
if: runner.os == 'macOS'
env:
ASC_KEY: ${{ secrets.ASC_KEY }}
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
IDENTITY: ${{ secrets.MAC_SIGNING_IDENTITY }}
IDENTITY_PASSWORD: ${{ secrets.MAC_SIGNING_IDENTITY_PASSWORD }}
run: |
for name in ASC_KEY ASC_KEY_ID ASC_ISSUER_ID IDENTITY IDENTITY_PASSWORD; do
if [[ -z ${!name} ]]; then
echo "::error::a secret for $name is missing: docs/releasing-desktop.md"
exit 1
fi
done
umask 077
keychain=$RUNNER_TEMP/signing.keychain-db
password=$(openssl rand -hex 16)
security create-keychain -p "$password" "$keychain"
security set-keychain-settings -lut 21600 "$keychain"
security unlock-keychain -p "$password" "$keychain"
base64 --decode <<<"$IDENTITY" > "$RUNNER_TEMP/identity.p12"
security import "$RUNNER_TEMP/identity.p12" -k "$keychain" -P "$IDENTITY_PASSWORD" -f pkcs12 -T /usr/bin/codesign -T /usr/bin/security
rm "$RUNNER_TEMP/identity.p12"
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$password" "$keychain" > /dev/null
security list-keychains -d user -s "$keychain"
security find-identity -v -p codesigning "$keychain"
key=$RUNNER_TEMP/AuthKey_$ASC_KEY_ID.p8
printf '%s\n' "$ASC_KEY" > "$key"
xcrun notarytool store-credentials NOTARY --key "$key" --key-id "$ASC_KEY_ID" --issuer "$ASC_ISSUER_ID" --keychain "$keychain"
rm "$key"
echo "NOTARY_KEYCHAIN=$keychain" >> "$GITHUB_ENV"
- name: Build and upload
env:
PLATFORM: ${{ matrix.platform }}
# gh uploads with it, and mygo build reads the GitHub API with it for delta updates.
GH_TOKEN: ${{ github.token }}
MYGO_UPDATER_PRIVATE_KEY: ${{ secrets.MYGO_UPDATER_PRIVATE_KEY }}
run: bun run release-desktop "$PLATFORM"
- name: Remove the keychain
if: always() && runner.os == 'macOS'
run: security delete-keychain "$RUNNER_TEMP/signing.keychain-db" 2>/dev/null || true
Loading
Loading