Skip to content

build: stabilize macos dmg release packaging #8

build: stabilize macos dmg release packaging

build: stabilize macos dmg release packaging #8

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: "发布版本,例如 v0.3.5"
required: true
default: "v0.3.5"
source_ref:
description: "构建所用 Git ref,例如 main 或某个 commit/tag"
required: false
default: "main"
push:
tags:
- "v*"
permissions:
contents: write
concurrency:
group: release-${{ github.event.inputs.version || github.ref }}
cancel-in-progress: false
jobs:
meta:
name: Resolve Release Meta
runs-on: ubuntu-latest
outputs:
prerelease: ${{ steps.meta.outputs.prerelease }}
tag: ${{ steps.meta.outputs.tag }}
target_ref: ${{ steps.meta.outputs.target_ref }}
version: ${{ steps.meta.outputs.version }}
steps:
- name: Resolve metadata
id: meta
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
raw_tag="${{ github.event.inputs.version }}"
target_ref="${{ github.event.inputs.source_ref }}"
else
raw_tag="${{ github.ref_name }}"
target_ref="${{ github.sha }}"
fi
if [[ "${raw_tag}" != v* ]]; then
raw_tag="v${raw_tag}"
fi
if [[ -z "${target_ref}" ]]; then
target_ref="${{ github.sha }}"
fi
version="${raw_tag#v}"
echo "tag=${raw_tag}" >> "$GITHUB_OUTPUT"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "target_ref=${target_ref}" >> "$GITHUB_OUTPUT"
if [[ "${raw_tag}" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
package-macos:
name: Package macOS Release (${{ matrix.label }})
runs-on: ${{ matrix.runner }}
needs: meta
strategy:
fail-fast: false
matrix:
include:
- runner: macos-15
label: Apple Silicon
artifact_suffix: macos-arm64
- runner: macos-15-intel
label: Intel
artifact_suffix: macos-x64
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ needs.meta.outputs.target_ref }}
- name: Prepare scripts
run: chmod +x scripts/*.sh
- name: Show toolchain
run: |
swift --version
xcodebuild -version
- name: Build release package
run: ./scripts/package-release.sh --version "${{ needs.meta.outputs.version }}" --build-number "${{ github.run_number }}" --artifact-suffix "${{ matrix.artifact_suffix }}"
- name: Upload release artifact
uses: actions/upload-artifact@v6
with:
name: lime-pet-${{ needs.meta.outputs.tag }}-${{ matrix.artifact_suffix }}
path: |
dist/release/*.dmg
dist/release/*.zip
dist/release/*.sha256
package-windows:
name: Package Windows Release
runs-on: windows-latest
needs: meta
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ needs.meta.outputs.target_ref }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: "npm"
cache-dependency-path: "WindowsPet/package-lock.json"
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Show toolchain
run: |
node -v
npm -v
cargo -V
- name: Install Windows companion dependencies
working-directory: WindowsPet
run: npm ci
- name: Sync Windows companion version from tag
working-directory: WindowsPet
run: npm run sync:version -- "${{ needs.meta.outputs.version }}"
- name: Build Windows installer
working-directory: WindowsPet
run: npm run tauri build
- name: Upload Windows release artifact
uses: actions/upload-artifact@v6
with:
name: lime-pet-${{ needs.meta.outputs.tag }}-windows
path: |
WindowsPet/src-tauri/target/release/bundle/nsis/*.exe
publish-release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs:
- meta
- package-macos
- package-windows
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ needs.meta.outputs.target_ref }}
- name: Download macOS Apple Silicon artifact
uses: actions/download-artifact@v7
with:
name: lime-pet-${{ needs.meta.outputs.tag }}-macos-arm64
path: artifacts/macos-arm64
- name: Download macOS Intel artifact
uses: actions/download-artifact@v7
with:
name: lime-pet-${{ needs.meta.outputs.tag }}-macos-x64
path: artifacts/macos-x64
- name: Download Windows artifact
uses: actions/download-artifact@v7
with:
name: lime-pet-${{ needs.meta.outputs.tag }}-windows
path: artifacts/windows
- name: Generate release notes
id: notes
shell: bash
run: |
notes_file="${RUNNER_TEMP}/release-notes.md"
if [[ -f "RELEASE_NOTES.md" ]]; then
cp "RELEASE_NOTES.md" "${notes_file}"
else
{
echo "## Lime Pet ${{ needs.meta.outputs.tag }}"
echo ""
echo "- macOS Apple Silicon dmg + unsigned zip bundle"
echo "- macOS Intel dmg + unsigned zip bundle"
echo "- Windows companion NSIS installer"
echo "- Shared companion protocol across macOS Swift shell and Windows Tauri shell"
echo "- Version: ${{ needs.meta.outputs.version }}"
echo "- Build number: ${{ github.run_number }}"
} > "${notes_file}"
fi
echo "file=${notes_file}" >> "$GITHUB_OUTPUT"
- name: Publish GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
tag="${{ needs.meta.outputs.tag }}"
title="Lime Pet ${tag}"
target_ref="${{ needs.meta.outputs.target_ref }}"
notes_file="${{ steps.notes.outputs.file }}"
prerelease_flag=""
if [[ "${{ needs.meta.outputs.prerelease }}" == "true" ]]; then
prerelease_flag="--prerelease"
fi
shopt -s nullglob
assets=(artifacts/macos-arm64/* artifacts/macos-x64/* artifacts/windows/*)
if gh release view "${tag}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
gh release upload "${tag}" "${assets[@]}" --repo "${GITHUB_REPOSITORY}" --clobber
else
gh release create "${tag}" "${assets[@]}" \
--repo "${GITHUB_REPOSITORY}" \
--target "${target_ref}" \
--title "${title}" \
--notes-file "${notes_file}" \
${prerelease_flag}
fi