mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:29:37 +08:00
291 lines
12 KiB
YAML
291 lines
12 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.
|
|
# Branch and pull request builds use disposable keys. Version tags use the
|
|
# protected desktop-release environment for signed validation and publishing.
|
|
#
|
|
# desktop-release environment 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
|
|
# Required for signed and notarized Mac tag builds.
|
|
# 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: ${{ github.ref_type == 'tag' && github.ref_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
|
|
environment: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && 'desktop-release' || 'desktop-validation' }}
|
|
runs-on: ${{ matrix.runner }}
|
|
timeout-minutes: 120
|
|
env:
|
|
HAS_DEVELOPER_ID: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && secrets.APPLE_CERTIFICATE_P12 != '' }}
|
|
HAS_NOTARY: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && secrets.APPLE_ID != '' }}
|
|
HAS_RUNTIME_KEY: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && secrets.DESKTOP_RUNTIME_SIGNING_KEY != '' }}
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
working-directory: apps/desktop
|
|
steps:
|
|
- name: Check publishing ref
|
|
if: env.PUBLISH == 'true'
|
|
working-directory: ${{ runner.temp }}
|
|
env:
|
|
REQUESTED_TAG: ${{ inputs.tag || github.event.release.tag_name }}
|
|
run: |
|
|
[[ "$RELEASE_TAG" == v* && "$RELEASE_TAG" == "$REQUESTED_TAG" ]] || {
|
|
echo "Select the same version tag as the workflow ref and release tag." >&2
|
|
exit 1
|
|
}
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.sha }}
|
|
persist-credentials: false
|
|
|
|
- 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.ref_type == 'tag' && startsWith(github.ref_name, 'v')
|
|
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 "Missing release runtime signing key." >&2; exit 1; }
|
|
if [ "$RUNNER_OS" = "macOS" ]; then
|
|
for configured in "$HAS_DEVELOPER_ID" "$HAS_SIGNING_IDENTITY" "$HAS_CERTIFICATE_PASSWORD" "$HAS_NOTARY" "$HAS_TEAM_ID" "$HAS_NOTARY_PASSWORD"; do
|
|
[ "$configured" = "true" ] || { echo "Missing release signing or notarization credential." >&2; exit 1; }
|
|
done
|
|
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.ref_type == 'tag' && startsWith(github.ref_name, 'v') && secrets.DESKTOP_RUNTIME_SIGNING_KEY || '' }}
|
|
APPLE_SIGNING_IDENTITY: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && 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.ref_type == 'tag' && startsWith(github.ref_name, 'v') && 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; }
|
|
# Also attach copies without the version in the name, so the README
|
|
# can link to releases/latest/download/<name> and always get the newest build.
|
|
mkdir -p out/latest
|
|
for f in "${files[@]}"; do
|
|
name="$(basename "$f")"
|
|
stable="${name/-$RELEASE_TAG/}"
|
|
[ "$stable" != "$name" ] || { echo "Expected $RELEASE_TAG in $name." >&2; exit 1; }
|
|
cp "$f" "out/latest/$stable"
|
|
done
|
|
gh release upload "$RELEASE_TAG" "${files[@]}" out/latest/* --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
|
|
|
|
verify-release:
|
|
name: Verify all desktop downloads are published
|
|
needs: build
|
|
if: always() && (github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish))
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Require successful builds and all release assets
|
|
uses: actions/github-script@v7
|
|
env:
|
|
BUILD_RESULT: ${{ needs.build.result }}
|
|
with:
|
|
script: |
|
|
if (process.env.BUILD_RESULT !== 'success') {
|
|
core.setFailed(`Desktop builds did not all succeed: ${process.env.BUILD_RESULT}`);
|
|
return;
|
|
}
|
|
const tag = process.env.RELEASE_TAG;
|
|
const { data: release } = await github.rest.repos.getReleaseByTag({
|
|
...context.repo, tag,
|
|
});
|
|
const assets = await github.paginate(github.rest.repos.listReleaseAssets, {
|
|
...context.repo, release_id: release.id, per_page: 100,
|
|
});
|
|
const versioned = [
|
|
`Open-DeepTutor-MacOS-Apple-Silicon-${tag}.dmg`,
|
|
`Open-DeepTutor-MacOS-Intel-${tag}.dmg`,
|
|
`Open-DeepTutor-Windows-${tag}-Setup.exe`,
|
|
`Open-DeepTutor-Windows-${tag}-Portable.zip`,
|
|
];
|
|
const expected = [...versioned, ...versioned.map(name => name.replace(`-${tag}`, ''))];
|
|
const uploaded = new Set(assets
|
|
.filter(asset => asset.state === 'uploaded' && asset.size > 0)
|
|
.map(asset => asset.name));
|
|
const missing = expected.filter(name => !uploaded.has(name));
|
|
if (missing.length) {
|
|
core.setFailed(`Desktop release is incomplete. Missing downloads: ${missing.join(', ')}`);
|
|
} else {
|
|
core.info(`Verified all ${expected.length} desktop downloads for ${tag}.`);
|
|
}
|