Skip to content

fix(ci): fix bash syntax error by replacing heredoc with python -c #41

fix(ci): fix bash syntax error by replacing heredoc with python -c

fix(ci): fix bash syntax error by replacing heredoc with python -c #41

Workflow file for this run

name: Build and Release
on:
push:
tags:
- "v*"
workflow_dispatch:
jobs:
build:
strategy:
matrix:
include:
- os: macos-latest
platform: mac
- os: windows-latest
platform: win
arch: x64
- os: windows-latest
platform: win
arch: arm64
- os: ubuntu-latest
platform: linux
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
# 显式使用与 package.json 中一致的 pnpm 版本
version: 9.15.0
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Clean previous build artifacts
shell: bash
run: |
rm -rf dist || true
- name: Build for ${{ matrix.platform }} ${{ matrix.arch }}
shell: bash
run: |
if [ "${{ matrix.platform }}" = "win" ] && [ -n "${{ matrix.arch }}" ]; then
# Windows: build specific architecture
pnpm vite build && pnpm electron-builder --win --${{ matrix.arch }} --publish never
else
pnpm electron:build:${{ matrix.platform }}
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Normalize Windows update metadata
if: matrix.platform == 'win' && matrix.arch != ''
shell: bash
run: |
# For x64: keep latest.yml as-is (this is what electron-updater expects by default)
# For arm64: create latest-arm64.yml for future multi-arch support
if [ "${{ matrix.arch }}" = "arm64" ]; then
if [ -f "dist/latest.yml" ]; then
# Rename to latest-arm64.yml for arm64 builds
mv dist/latest.yml dist/latest-arm64.yml
echo "Renamed latest.yml to latest-arm64.yml for ARM64"
fi
else
# x64: just ensure the yml points to correct exe filename
if [ -f "dist/latest.yml" ]; then
exe=$(ls dist/PromptHub-Setup-*-x64.exe 2>/dev/null | head -1 | xargs -I {} basename {})
if [ -n "$exe" ]; then
sed -i.bak "s/PromptHub-Setup-[0-9.]*\.exe/$exe/g" dist/latest.yml
rm -f dist/latest.yml.bak
echo "Updated latest.yml to point to $exe"
fi
fi
fi
# Remove duplicate NSIS blockmap without arch (prevents release upload errors)
shopt -s nullglob
for file in dist/*.exe.blockmap; do
case "$file" in
*-x64.exe.blockmap|*-arm64.exe.blockmap) ;;
*) rm -f "$file" ;;
esac
done
- name: Remove debug files
shell: bash
run: |
# 删除 builder-debug.yml
find dist -name "builder-debug.yml" -delete || true
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-${{ matrix.arch || 'default' }}-build
path: |
dist/*.dmg
dist/*.zip
dist/*-x64.exe
dist/*-arm64.exe
dist/*.AppImage
dist/*.deb
dist/*.blockmap
dist/latest*.yml
if-no-files-found: ignore
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Set release version
shell: bash
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
- name: Merge Windows update metadata
shell: bash
run: |
x64_yml=$(find artifacts -name "latest.yml" -path "*/win-x64-build/*" | head -1)
arm64_yml=$(find artifacts -name "latest-arm64.yml" -path "*/win-arm64-build/*" | head -1)
if [ -n "$x64_yml" ] && [ -n "$arm64_yml" ]; then
echo "Merging Windows ARM64 metadata into latest.yml..."
python3 -c "import sys, re; x, a = sys.argv[1:3]; xc = open(x).read(); ac = open(a).read(); m = re.search(r'(\s+-\s+url:.*?arm64\.exe.*?\n\s+sha512:.*?\n\s+size:.*?\n)', ac, re.S); open(x, 'w').write(re.sub(r'(files:\s*\n\s+-\s+url:.*?\n\s+sha512:.*?\n\s+size:.*?\n)', r'\1' + m.group(1), xc, flags=re.S)) if m else print('Warning: No ARM64 entry found')" "$x64_yml" "$arm64_yml"
rm -f "$arm64_yml"
fi
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/**/PromptHub-*-x64.dmg
artifacts/**/PromptHub-*-arm64.dmg
artifacts/**/PromptHub-Setup-*-x64.exe
artifacts/**/PromptHub-Setup-*-arm64.exe
artifacts/**/PromptHub-*-x64.AppImage
artifacts/**/prompthub_*_amd64.deb
artifacts/**/PromptHub-*.zip
artifacts/**/latest*.yml
artifacts/**/*.blockmap
draft: false
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
generate_release_notes: true
body: |
## 📦 下载安装
| 平台 | 下载 |
|------|------|
| Windows | [![Windows x64](https://img.shields.io/badge/Windows_x64-0078D6?style=for-the-badge&logo=windows&logoColor=white)](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-Setup-${{ env.VERSION }}-x64.exe) [![Windows arm64](https://img.shields.io/badge/Windows_arm64-0078D6?style=for-the-badge&logo=windows&logoColor=white)](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-Setup-${{ env.VERSION }}-arm64.exe) |
| macOS | [![macOS Apple Silicon](https://img.shields.io/badge/macOS_Apple_Silicon-000000?style=for-the-badge&logo=apple&logoColor=white)](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-${{ env.VERSION }}-arm64.dmg) [![macOS Intel](https://img.shields.io/badge/macOS_Intel-000000?style=for-the-badge&logo=apple&logoColor=white)](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-${{ env.VERSION }}-x64.dmg) |
| Linux | [![Linux AppImage](https://img.shields.io/badge/Linux_AppImage-FCC624?style=for-the-badge&logo=linux&logoColor=black)](https://github.com/legeling/PromptHub/releases/latest/download/PromptHub-${{ env.VERSION }}-x64.AppImage) [![Linux deb](https://img.shields.io/badge/Linux_deb-FCC624?style=for-the-badge&logo=linux&logoColor=black)](https://github.com/legeling/PromptHub/releases/latest/download/prompthub_${{ env.VERSION }}_amd64.deb) |
### ⚠️ macOS 首次启动
如果提示"无法打开"或"已损坏",请在终端执行:
```bash
sudo xattr -rd com.apple.quarantine /Applications/PromptHub.app
```
---
## 🔄 本次更新
详细更新日志请查看 [更新日志](https://github.com/legeling/PromptHub#-更新日志)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}