Skip to content

feat: 添加连接前后行为配置 (#15) #104

feat: 添加连接前后行为配置 (#15)

feat: 添加连接前后行为配置 (#15) #104

Workflow file for this run

name: 'Build and Release'
on:
push:
branches:
- "master"
tags:
- 'v*'
paths-ignore:
- 'docs/**'
- '.github/workflows/deploy-docs.yml'
workflow_dispatch:
env:
REPO_NAME: "sftool"
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version number
id: get_version
run: |
VERSION=$(node scripts/version-manager.js get)
echo "version=$VERSION" >> $GITHUB_OUTPUT
windows-build:
needs: get-version
env:
VERSION: ${{ needs.get-version.outputs.VERSION }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }}
outputs:
VERSION: ${{ env.VERSION }}
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
version: 10
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Update version
run: pnpm run update-version
- name: Build tauri app
uses: tauri-apps/tauri-action@v0
- name: Create artifacts directory
run: mkdir -p artifacts
- name: Copy nsis bundle and signature to release assets
run: |
cp "src-tauri/target/release/bundle/nsis/${{ env.REPO_NAME }}_${{ env.VERSION }}_x64-setup.exe" "artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_windows_x64.exe"
cp "src-tauri/target/release/bundle/nsis/${{ env.REPO_NAME }}_${{ env.VERSION }}_x64-setup.exe.sig" "artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_windows_x64.exe.sig"
- name: Zip portable to release assets
run: |
cd src-tauri/target/release
7z a -tzip "../../../artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_windows_x64_portable.zip" "sftool.exe"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: windows-assets
path: artifacts/*
linux-build:
needs: get-version
env:
VERSION: ${{ needs.get-version.outputs.VERSION }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }}
outputs:
VERSION: ${{ env.VERSION }}
runs-on: ubuntu-24.04
steps:
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
version: 10
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Update version
run: pnpm run update-version
- name: Build tauri app
uses: tauri-apps/tauri-action@v0
- name: Create artifacts directory
run: mkdir -p artifacts
- name: Copy deb to release assets
run: cp "src-tauri/target/release/bundle/deb/${{ env.REPO_NAME }}_${{ env.VERSION }}_amd64.deb" "artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_linux_amd64.deb"
- name: Copy rpm to release assets
run: cp "src-tauri/target/release/bundle/rpm/${{ env.REPO_NAME }}-${{ env.VERSION }}-1.x86_64.rpm" "artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_linux_amd64.rpm"
- name: Copy appimage and signature to release assets
run: |
cp "src-tauri/target/release/bundle/appimage/${{ env.REPO_NAME }}_${{ env.VERSION }}_amd64.AppImage" \
"artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_amd64.AppImage"
cp "src-tauri/target/release/bundle/appimage/${{ env.REPO_NAME }}_${{ env.VERSION }}_amd64.AppImage.sig" \
"artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_amd64.AppImage.sig"
- name: Zip portable to release assets
run: |
cd src-tauri/target/release
tar -czf "../../../artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_linux_amd64_portable.tar.gz" sftool
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: linux-assets
path: artifacts/*
macos-build:
needs: get-version
env:
VERSION: ${{ needs.get-version.outputs.VERSION }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }}
outputs:
VERSION: ${{ env.VERSION }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
version: 10
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-darwin, x86_64-apple-darwin
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Update version
run: pnpm run update-version
- name: Build tauri app
uses: tauri-apps/tauri-action@v0
with:
args: --target universal-apple-darwin
- name: Create artifacts directory
run: mkdir -p artifacts
- name: Copy dmg to release assets
run: cp "src-tauri/target/universal-apple-darwin/release/bundle/dmg/${{ env.REPO_NAME }}_${{ env.VERSION }}_universal.dmg" "artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_macos_universal.dmg"
- name: Copy updater tarball and signature to release assets
run: |
cp "src-tauri/target/universal-apple-darwin/release/bundle/macos/${{ env.REPO_NAME }}.app.tar.gz" \
"artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_macos_universal.app.tar.gz"
cp "src-tauri/target/universal-apple-darwin/release/bundle/macos/${{ env.REPO_NAME }}.app.tar.gz.sig" \
"artifacts/${{ env.REPO_NAME }}_${{ env.VERSION }}_macos_universal.app.tar.gz.sig"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: macos-assets-universal
path: artifacts/*
create-release:
needs: [windows-build, linux-build, macos-build]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all assets
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
- name: Determine tag range
id: tag_range
shell: bash
run: |
set -euo pipefail
CURRENT="${GITHUB_REF_NAME}"
PREV="$(git describe --tags --abbrev=0 "${CURRENT}^" 2>/dev/null || true)"
if [ -n "${PREV}" ]; then
RANGE="${PREV}..${CURRENT}"
else
RANGE="${CURRENT}"
fi
echo "range=${RANGE}" >> "${GITHUB_OUTPUT}"
- name: Generate release notes
run: git cliff "${{ steps.tag_range.outputs.range }}" -c cliff.toml -o RELEASE_NOTES.md
- name: List files in artifacts directory
run: ls -R artifacts
- name: Create GitHub Release
id: create_release
uses: ncipollo/release-action@v1
with:
artifacts: |
artifacts/*
bodyFile: RELEASE_NOTES.md
allowUpdates: true
sync-mirror:
needs: [windows-build, linux-build, macos-build]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Download all assets
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts
- name: List files in artifacts directory
run: ls -R artifacts
- name: Sync to SiFli mirror
uses: OpenSiFli/SiFliMirrorSync@v1
with:
secret_id: ${{ secrets.COS_DOWNLOAD_SECRET_ID }}
secret_key: ${{ secrets.COS_DOWNLOAD_SECRET_KEY }}
region: ${{ secrets.COS_DOWNLOAD_REGION }}
bucket: ${{ secrets.COS_DOWNLOAD_BUCKET }}
prefix: "sftool-gui/${{ github.ref_name }}"
delete_remote: true
working_directory: "artifacts"
artifacts: "./**/*"
generate-latest-json:
needs: [windows-build, linux-build, macos-build, get-version]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Download all assets
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts
- name: Generate latest.json (global & cn)
uses: actions/github-script@v7
env:
TAG_NAME: ${{ needs.get-version.outputs.VERSION }}
REPO_NAME: ${{ env.REPO_NAME }}
with:
script: |
const fs = require('fs');
const path = require('path');
const tag = process.env.TAG_NAME;
const repo = process.env.REPO_NAME;
const names = {
windows: `${repo}_${tag}_windows_x64.exe`,
linux: `${repo}_${tag}_amd64.AppImage`,
mac: `${repo}_${tag}_macos_universal.app.tar.gz`,
};
const sig = (relPath) => fs.readFileSync(relPath, 'utf8').trim();
const sigs = {
windows: sig(path.join('artifacts', `${names.windows}.sig`)),
linux: sig(path.join('artifacts', `${names.linux}.sig`)),
mac: sig(path.join('artifacts', `${names.mac}.sig`)),
};
const buildJson = (base) => ({
version: tag,
platforms: {
'windows-x86_64': {
url: `${base}/${names.windows}`,
signature: sigs.windows,
},
'linux-x86_64': {
url: `${base}/${names.linux}`,
signature: sigs.linux,
},
'darwin-aarch64': {
url: `${base}/${names.mac}`,
signature: sigs.mac,
},
'darwin-x86_64': {
url: `${base}/${names.mac}`,
signature: sigs.mac,
},
},
});
fs.mkdirSync('updater/global', { recursive: true });
fs.mkdirSync('updater/cn', { recursive: true });
const globalJson = buildJson(`https://github.com/OpenSiFli/sftool-gui/releases/download/v${tag}`);
const cnJson = buildJson(`https://downloads.sifli.com/sftool-gui/v${tag}`);
fs.writeFileSync(path.join('updater/global/latest.json'), JSON.stringify(globalJson, null, 2));
fs.writeFileSync(path.join('updater/cn/latest.json'), JSON.stringify(cnJson, null, 2));
- name: Upload updater manifests
uses: actions/upload-artifact@v4
with:
name: updater-manifests
path: updater/**/*.json
- name: Sync to SiFli mirror
uses: OpenSiFli/SiFliMirrorSync@v1
with:
secret_id: ${{ secrets.COS_DOWNLOAD_SECRET_ID }}
secret_key: ${{ secrets.COS_DOWNLOAD_SECRET_KEY }}
region: ${{ secrets.COS_DOWNLOAD_REGION }}
bucket: ${{ secrets.COS_DOWNLOAD_BUCKET }}
prefix: "sftool-gui"
delete_remote: true
flush_url: "https://downloads.sifli.com/sftool-gui/"
working_directory: "updater"
artifacts: "global/latest.json,cn/latest.json"