Files
DeepTutor/.github/workflows/desktop-release.yml
2026-10-31 11:30:12 +08:00

232 lines
9.6 KiB
YAML

name: Desktop Release
# Builds Open DeepTutor for MacOS (Apple Silicon and Intel) and Windows from
# the release tag and attaches the downloads to the same GitHub Release that
# pypi-release.yml publishes. Each platform's build lives in
# apps/desktop/platforms/<target>/.
#
# Pull requests that touch apps/desktop build and smoke-test all three without
# publishing; they keep the downloads as workflow artifacts for 7 days.
# Pushes to dev and manual validation runs exercise configured signing without
# publishing. Pull requests always use disposable runtime signing keys.
#
# Secrets:
# DESKTOP_RUNTIME_SIGNING_KEY (required for releases) Ed25519 PEM matching
# apps/desktop/assets/runtime-public.pem.
# Pull requests always seal with a throwaway key.
# APPLE_CERTIFICATE_P12, APPLE_CERTIFICATE_PASSWORD, APPLE_SIGNING_IDENTITY,
# APPLE_ID, APPLE_TEAM_ID, APPLE_APP_PASSWORD
# (optional) Developer ID signing and
# notarization. Without them the Mac apps are
# signed ad hoc and Gatekeeper warns on first open.
# The Windows build is unsigned; SmartScreen warns on first open.
on:
push:
branches: [dev]
paths:
- apps/desktop/**
- .github/workflows/desktop-release.yml
release:
types: [published]
pull_request:
paths:
- apps/desktop/**
- .github/workflows/desktop-release.yml
workflow_dispatch:
inputs:
tag:
description: Existing release tag (required only when publishing)
required: false
type: string
publish:
description: Attach downloads to the existing release instead of only validating
type: boolean
default: false
env:
RELEASE_TAG: ${{ inputs.tag || github.event.release.tag_name }}
PUBLISH: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish) }}
permissions:
contents: write
concurrency:
group: desktop-release-${{ inputs.tag || github.event.release.tag_name || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- target: macos-arm64
name: Open DeepTutor for MacOS with Apple Silicon
runner: macos-15
- target: macos-x64
name: Open DeepTutor for MacOS with Intel Silicon
runner: macos-15-intel
- target: windows-x64
name: Open DeepTutor for Windows
runner: windows-2025
runs-on: ${{ matrix.runner }}
timeout-minutes: 120
env:
HAS_DEVELOPER_ID: ${{ secrets.APPLE_CERTIFICATE_P12 != '' }}
HAS_NOTARY: ${{ secrets.APPLE_ID != '' }}
HAS_RUNTIME_KEY: ${{ github.event_name != 'pull_request' && secrets.DESKTOP_RUNTIME_SIGNING_KEY != '' }}
defaults:
run:
shell: bash
working-directory: apps/desktop
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.PUBLISH == 'true' && env.RELEASE_TAG || '' }}
- name: Verify release tag matches deeptutor/__version__.py
if: env.PUBLISH == 'true'
run: |
set -euo pipefail
version="$(sed -nE 's/^__version__ = "([^"]+)"/\1/p' ../../deeptutor/__version__.py | tr -d '\r')"
if [ "v$version" != "$RELEASE_TAG" ]; then
echo "Release tag $RELEASE_TAG does not match deeptutor/__version__.py ($version)." >&2
exit 1
fi
- name: Verify signing configuration
if: github.event_name != 'pull_request'
env:
HAS_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD != '' }}
HAS_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY != '' }}
HAS_TEAM_ID: ${{ secrets.APPLE_TEAM_ID != '' }}
HAS_NOTARY_PASSWORD: ${{ secrets.APPLE_APP_PASSWORD != '' }}
run: |
set -euo pipefail
[ "$HAS_RUNTIME_KEY" = "true" ] || { echo "DESKTOP_RUNTIME_SIGNING_KEY is required for signed validation and releases." >&2; exit 1; }
if [ "$RUNNER_OS" = "macOS" ]; then
if [ "$HAS_DEVELOPER_ID" = "true" ] || [ "$HAS_SIGNING_IDENTITY" = "true" ] || [ "$HAS_CERTIFICATE_PASSWORD" = "true" ]; then
[ "$HAS_DEVELOPER_ID" = "true" ] && [ "$HAS_SIGNING_IDENTITY" = "true" ] && [ "$HAS_CERTIFICATE_PASSWORD" = "true" ] || { echo "Developer ID signing configuration is incomplete." >&2; exit 1; }
fi
if [ "$HAS_NOTARY" = "true" ] || [ "$HAS_NOTARY_PASSWORD" = "true" ]; then
[ "$HAS_DEVELOPER_ID" = "true" ] && [ "$HAS_NOTARY" = "true" ] && [ "$HAS_TEAM_ID" = "true" ] && [ "$HAS_NOTARY_PASSWORD" = "true" ] || { echo "Apple notarization configuration is incomplete." >&2; exit 1; }
fi
fi
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: |
apps/desktop/package-lock.json
web/package-lock.json
- uses: astral-sh/setup-uv@v6
- name: Install the Windows installer toolchain
if: runner.os == 'Windows'
run: choco install nsis --yes --no-progress
- name: Check and test the shell
run: npm ci && npm run check && npm test
- name: Import the Developer ID certificate
if: runner.os == 'macOS' && env.HAS_DEVELOPER_ID == 'true' && github.event_name != 'pull_request'
env:
APPLE_CERTIFICATE_P12: ${{ secrets.APPLE_CERTIFICATE_P12 }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
run: |
set -euo pipefail
keychain="$RUNNER_TEMP/signing.keychain-db"
password="$(uuidgen)"
umask 077
echo "$APPLE_CERTIFICATE_P12" | base64 --decode > "$RUNNER_TEMP/certificate.p12"
security create-keychain -p "$password" "$keychain"
security set-keychain-settings -lut 21600 "$keychain"
security unlock-keychain -p "$password" "$keychain"
security import "$RUNNER_TEMP/certificate.p12" -P "$APPLE_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k "$keychain"
security set-key-partition-list -S apple-tool:,apple: -k "$password" "$keychain"
security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
rm "$RUNNER_TEMP/certificate.p12"
- name: Build the bundled runtime
env:
OPEN_DEEPTUTOR_SIGNING_KEY: ${{ github.event_name != 'pull_request' && secrets.DESKTOP_RUNTIME_SIGNING_KEY || '' }}
APPLE_SIGNING_IDENTITY: ${{ github.event_name != 'pull_request' && secrets.APPLE_SIGNING_IDENTITY || '' }}
run: |
set -euo pipefail
if [ "$HAS_RUNTIME_KEY" = "true" ]; then
npm run build:runtime -- --target ${{ matrix.target }}
elif [ "$PUBLISH" = "true" ]; then
echo "DESKTOP_RUNTIME_SIGNING_KEY is required to publish desktop apps." >&2
exit 1
else
npm run build:runtime -- --target ${{ matrix.target }} --new-key
fi
- name: Boot the bundled runtime
run: npm run smoke -- --target ${{ matrix.target }}
- name: Package
env:
APPLE_SIGNING_IDENTITY: ${{ github.event_name != 'pull_request' && secrets.APPLE_SIGNING_IDENTITY || '' }}
run: npm run package -- --target ${{ matrix.target }}
- name: Verify Windows installation and app lifecycle
if: runner.os == 'Windows'
shell: pwsh
run: ./platforms/windows-x64/smoke-installer.ps1
- name: Notarize the DMG
if: runner.os == 'macOS' && env.HAS_NOTARY == 'true' && github.event_name != 'pull_request'
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
APPLE_APP_PASSWORD: ${{ secrets.APPLE_APP_PASSWORD }}
run: node scripts/notarize.mjs
- name: Keep the Apple notarization reports
if: always() && runner.os == 'macOS' && env.HAS_NOTARY == 'true' && github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: notarization-${{ matrix.target }}
retention-days: 7
path: apps/desktop/out/notarization-*.json
- name: Attach the downloads to the release
if: env.PUBLISH == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# Each platform produces only its own downloads.
shopt -s nullglob
files=(out/*.dmg out/*-Setup.exe out/*-Portable.zip)
[ ${#files[@]} -gt 0 ] || { echo "No downloads were produced." >&2; exit 1; }
gh release upload "$RELEASE_TAG" "${files[@]}" --clobber
- name: Remove the temporary signing keychain
if: always() && runner.os == 'macOS' && env.HAS_DEVELOPER_ID == 'true' && github.event_name != 'pull_request'
run: |
rm -f "$RUNNER_TEMP/certificate.p12"
if [ -f "$RUNNER_TEMP/signing.keychain-db" ]; then
security delete-keychain "$RUNNER_TEMP/signing.keychain-db"
fi
- name: Keep the validation build
if: always() && env.PUBLISH != 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
retention-days: 7
path: |
apps/desktop/out/*.dmg
apps/desktop/out/*-Setup.exe
apps/desktop/out/*-Portable.zip
apps/desktop/.local/${{ matrix.target }}/smoke.log
apps/desktop/.local/${{ matrix.target }}/smoke-result.json
apps/desktop/.local/${{ matrix.target }}/installed-app.log