Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Build and Release

on:
push:
tags: ['v*']
branches:
- main
- 'feat/**'
pull_request:
branches: ['main']

jobs:
# ---- Windows 桌面 app ----
build-windows:
needs: build-helper
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-msvc
artifact: CSSwitch-Windows-x64
- target: aarch64-pc-windows-msvc
artifact: CSSwitch-Windows-arm64
steps:
- uses: actions/checkout@v4
- name: Download Linux Helper Assets
uses: actions/download-artifact@v4
with:
pattern: csswitch-helper-linux-*
path: desktop/src-tauri/helper-assets
merge-multiple: true
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build Desktop App
run: |
cd desktop
npm install
npx tauri build --target ${{ matrix.target }} --bundles nsis
- name: Upload NSIS Installer
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: desktop/src-tauri/target/${{ matrix.target }}/release/bundle/nsis/*.exe

# ---- macOS 桌面 app ----
build-macos:
needs: build-helper
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- name: Download Linux Helper Assets
uses: actions/download-artifact@v4
with:
pattern: csswitch-helper-linux-*
path: desktop/src-tauri/helper-assets
merge-multiple: true
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-darwin
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build Desktop App
run: |
cd desktop
npm install
npx tauri build --target aarch64-apple-darwin --bundles dmg
- name: Upload DMG Installer
uses: actions/upload-artifact@v4
with:
name: CSSwitch-macOS-arm64
path: desktop/src-tauri/target/aarch64-apple-darwin/release/bundle/dmg/*.dmg

# ---- Linux Helper ----
build-helper:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
asset_arch: x86_64
- target: aarch64-unknown-linux-musl
asset_arch: aarch64
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: taiki-e/install-action@v2
with:
tool: cross
- name: Build Helper
env:
CSSWITCH_BUNDLED_PROXY_DIR: ${{ github.workspace }}/proxy
run: |
cd desktop/src-tauri
cross build --bin csswitch-helper --no-default-features --release --target ${{ matrix.target }}
mkdir -p helper-out
cp target/${{ matrix.target }}/release/csswitch-helper helper-out/csswitch-helper-linux-${{ matrix.asset_arch }}
- name: Upload Helper
uses: actions/upload-artifact@v4
with:
name: csswitch-helper-linux-${{ matrix.asset_arch }}
path: desktop/src-tauri/helper-out/csswitch-helper-linux-${{ matrix.asset_arch }}

# ---- Tests ----
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Install Linux desktop dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
build-essential \
curl \
wget \
file \
libxdo-dev \
libssl-dev \
libayatana-appindicator3-dev \
librsvg2-dev
- name: Run Tests
run: cd desktop/src-tauri && cargo test --lib
- name: Run Helper Tests
run: cd desktop/src-tauri && cargo test --bin csswitch-helper --no-default-features

# ---- GitHub Release (tag push only) ----
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [build-windows, build-macos, build-helper, test]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- name: Resolve Release Notes
id: release_notes
shell: bash
run: |
tag="${GITHUB_REF_NAME}"
version="${tag#v}"
if [[ -f "docs/release-notes/${tag}.md" ]]; then
echo "path=docs/release-notes/${tag}.md" >> "$GITHUB_OUTPUT"
elif [[ -f "docs/release-notes/${version}.md" ]]; then
echo "path=docs/release-notes/${version}.md" >> "$GITHUB_OUTPUT"
else
echo "path=" >> "$GITHUB_OUTPUT"
fi
- name: Create Release with curated notes
if: steps.release_notes.outputs.path != ''
uses: softprops/action-gh-release@v1
with:
files: |
CSSwitch-Windows-*/*.exe
CSSwitch-macOS-arm64/*.dmg
csswitch-helper-*/*
draft: false
body_path: ${{ steps.release_notes.outputs.path }}
- name: Create Release with generated notes
if: steps.release_notes.outputs.path == ''
uses: softprops/action-gh-release@v1
with:
files: |
CSSwitch-Windows-*/*.exe
CSSwitch-macOS-arm64/*.dmg
csswitch-helper-*/*
draft: false
generate_release_notes: true
Loading