name: Auto Tag on Version Bump
on:
push:
branches:
- main
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect version bump and push tag
env:
BEFORE_SHA: ${{ github.event.before }}
run: |
set -euo pipefail
CURRENT=$(node -p "require('./package.json').version")
TAG="v${CURRENT}"
PREVIOUS=$(git show "${BEFORE_SHA}:package.json" 2>/dev/null \
| node -e "const fs=require('fs');const d=fs.readFileSync(0,'utf8');try{console.log(JSON.parse(d).version)}catch{console.log('')}" \
|| echo "")
if [[ -n "$PREVIOUS" && "$CURRENT" == "$PREVIOUS" ]]; then
echo "Version unchanged, skipping tag"
exit 0
fi
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q .; then
echo "Tag ${TAG} already exists, skipping"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "${TAG}" -m "Release ${CURRENT}"
git push origin "${TAG}"strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
platform: mac
args: --mac --arm64 --x64
- os: windows-latest
platform: win
args: --win --x64- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Rebuild native modules for Electron
run: pnpm rebuild:native
- name: Build app
run: pnpm build
- name: Package installer
shell: bash
run: |
unset CSC_LINK CSC_KEY_PASSWORD WIN_CSC_LINK WIN_CSC_KEY_PASSWORD || true
export CSC_IDENTITY_AUTO_DISCOVERY=false
pnpm exec electron-builder ${{ matrix.args }} --publish neverfunction collectWinUpdateFiles(dir) {
const names = new Set();
for (const filePath of listFiles(dir)) {
const base = path.basename(filePath);
if (base === "latest.yml") names.add(base);
else if (/^app-setup-.+\.exe$/i.test(base)) names.add(base);
else if (/^app-setup-.+\.exe\.blockmap$/i.test(base)) names.add(base);
}
if (!names.has("latest.yml")) {
throw new Error("latest.yml not found");
}
const exe = [...names].find((name) => name.endsWith(".exe"));
if (!exe) throw new Error("Windows setup exe not found");
const files = ["latest.yml", exe];
const blockmap = `${exe}.blockmap`;
if (names.has(blockmap)) files.push(blockmap);
return files;
}version/latest.yml
version/app-setup-1.2.3.exe
version/app-setup-1.2.3.exe.blockmap- name: Prepare release notes
env:
WIN_DOWNLOAD_URL: ${{ steps.qiniu.outputs.win_download_url }}
run: |
cat > release-notes.md <<EOF
## Windows 安装包(CDN 推荐)
[点击下载](${WIN_DOWNLOAD_URL})
## macOS
请在下方 Assets 下载 arm64 或 x64 的 dmg/zip。
EOF