mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-04-03 07:25:53 +00:00
279 lines
9.2 KiB
YAML
279 lines
9.2 KiB
YAML
name: Preview Nightly
|
||
|
||
on:
|
||
schedule:
|
||
# GitHub Actions schedule uses UTC. 16:00 UTC = 北京时间次日 00:00
|
||
- cron: "0 16 * * *"
|
||
workflow_dispatch:
|
||
|
||
permissions:
|
||
contents: write
|
||
|
||
env:
|
||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
||
ELECTRON_BUILDER_BINARIES_MIRROR: https://github.com/electron-userland/electron-builder-binaries/releases/download/
|
||
|
||
jobs:
|
||
prepare:
|
||
runs-on: ubuntu-latest
|
||
outputs:
|
||
should_build: ${{ steps.meta.outputs.should_build }}
|
||
preview_version: ${{ steps.meta.outputs.preview_version }}
|
||
steps:
|
||
- name: Check out git repository
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Install Node.js
|
||
uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: "npm"
|
||
|
||
- name: Decide whether to build and generate preview version
|
||
id: meta
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
shell: bash
|
||
run: |
|
||
set -euo pipefail
|
||
|
||
git fetch origin main --depth=1
|
||
COMMITS_24H="$(git rev-list --count --since='24 hours ago' origin/main)"
|
||
|
||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||
SHOULD_BUILD=true
|
||
elif [ "$COMMITS_24H" -gt 0 ]; then
|
||
SHOULD_BUILD=true
|
||
else
|
||
SHOULD_BUILD=false
|
||
fi
|
||
|
||
BASE_VERSION="$(node -p "require('./package.json').version.split('-')[0]")"
|
||
YEAR_2="$(TZ=Asia/Shanghai date +%y)"
|
||
EXISTING_COUNT="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/releases" --jq "[.[].tag_name | select(test(\"^v${BASE_VERSION}-preview[.]${YEAR_2}[.][0-9]+$\"))] | length")"
|
||
NEXT_COUNT=$((EXISTING_COUNT + 1))
|
||
PREVIEW_VERSION="${BASE_VERSION}-preview.${YEAR_2}.${NEXT_COUNT}"
|
||
|
||
echo "should_build=$SHOULD_BUILD" >> "$GITHUB_OUTPUT"
|
||
echo "preview_version=$PREVIEW_VERSION" >> "$GITHUB_OUTPUT"
|
||
echo "Preview version: $PREVIEW_VERSION (commits in last 24h on main: $COMMITS_24H)"
|
||
|
||
preview-mac-arm64:
|
||
needs: prepare
|
||
if: needs.prepare.outputs.should_build == 'true'
|
||
runs-on: macos-14
|
||
steps:
|
||
- name: Check out git repository
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Install Node.js
|
||
uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: "npm"
|
||
|
||
- name: Install Dependencies
|
||
run: npm install
|
||
|
||
- name: Set preview version
|
||
shell: bash
|
||
run: npm version "${{ needs.prepare.outputs.preview_version }}" --no-git-tag-version --allow-same-version
|
||
|
||
- name: Build Frontend & Type Check
|
||
run: |
|
||
npx tsc
|
||
npx vite build
|
||
|
||
- name: Package and Publish macOS arm64 preview
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
CSC_IDENTITY_AUTO_DISCOVERY: "false"
|
||
shell: bash
|
||
run: |
|
||
export ELECTRON_BUILDER_BINARIES_MIRROR="https://github.com/electron-userland/electron-builder-binaries/releases/download/"
|
||
echo "Using ELECTRON_BUILDER_BINARIES_MIRROR=$ELECTRON_BUILDER_BINARIES_MIRROR"
|
||
npx electron-builder --mac dmg --arm64 --publish always '--config.publish.releaseType=prerelease' '--config.publish.channel=preview'
|
||
|
||
preview-linux:
|
||
needs: prepare
|
||
if: needs.prepare.outputs.should_build == 'true'
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Check out git repository
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Install Node.js
|
||
uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: "npm"
|
||
|
||
- name: Install Dependencies
|
||
run: npm install
|
||
|
||
- name: Set preview version
|
||
shell: bash
|
||
run: npm version "${{ needs.prepare.outputs.preview_version }}" --no-git-tag-version --allow-same-version
|
||
|
||
- name: Build Frontend & Type Check
|
||
run: |
|
||
npx tsc
|
||
npx vite build
|
||
|
||
- name: Package and Publish Linux preview
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
npx electron-builder --linux --publish always '--config.publish.releaseType=prerelease' '--config.publish.channel=preview'
|
||
|
||
preview-win-x64:
|
||
needs: prepare
|
||
if: needs.prepare.outputs.should_build == 'true'
|
||
runs-on: windows-latest
|
||
steps:
|
||
- name: Check out git repository
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Install Node.js
|
||
uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: "npm"
|
||
|
||
- name: Install Dependencies
|
||
run: npm install
|
||
|
||
- name: Set preview version
|
||
shell: bash
|
||
run: npm version "${{ needs.prepare.outputs.preview_version }}" --no-git-tag-version --allow-same-version
|
||
|
||
- name: Build Frontend & Type Check
|
||
run: |
|
||
npx tsc
|
||
npx vite build
|
||
|
||
- name: Package and Publish Windows x64 preview
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
npx electron-builder --win nsis --x64 --publish always '--config.publish.releaseType=prerelease' '--config.publish.channel=preview' '--config.artifactName=${productName}-${version}-x64-Setup.${ext}'
|
||
|
||
preview-win-arm64:
|
||
needs: prepare
|
||
if: needs.prepare.outputs.should_build == 'true'
|
||
runs-on: windows-latest
|
||
steps:
|
||
- name: Check out git repository
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Install Node.js
|
||
uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: "npm"
|
||
|
||
- name: Install Dependencies
|
||
run: npm install
|
||
|
||
- name: Set preview version
|
||
shell: bash
|
||
run: npm version "${{ needs.prepare.outputs.preview_version }}" --no-git-tag-version --allow-same-version
|
||
|
||
- name: Build Frontend & Type Check
|
||
run: |
|
||
npx tsc
|
||
npx vite build
|
||
|
||
- name: Package and Publish Windows arm64 preview
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
npx electron-builder --win nsis --arm64 --publish always '--config.publish.releaseType=prerelease' '--config.publish.channel=preview-arm64' '--config.artifactName=${productName}-${version}-arm64-Setup.${ext}'
|
||
|
||
update-preview-release-notes:
|
||
needs:
|
||
- prepare
|
||
- preview-mac-arm64
|
||
- preview-linux
|
||
- preview-win-x64
|
||
- preview-win-arm64
|
||
if: needs.prepare.outputs.should_build == 'true' && always()
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Update preview release notes
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
shell: bash
|
||
run: |
|
||
set -euo pipefail
|
||
|
||
TAG="v${{ needs.prepare.outputs.preview_version }}"
|
||
REPO="$GITHUB_REPOSITORY"
|
||
RELEASE_PAGE="https://github.com/$REPO/releases/tag/$TAG"
|
||
|
||
if ! gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then
|
||
echo "Release $TAG not found (possibly all publish jobs failed), skip notes update."
|
||
exit 0
|
||
fi
|
||
|
||
ASSETS_JSON="$(gh release view "$TAG" --repo "$REPO" --json assets)"
|
||
|
||
pick_asset() {
|
||
local pattern="$1"
|
||
echo "$ASSETS_JSON" | jq -r --arg p "$pattern" '[.assets[].name | select(test($p))][0] // ""'
|
||
}
|
||
|
||
WINDOWS_ASSET="$(pick_asset "x64.*[.]exe$")"
|
||
if [ -z "$WINDOWS_ASSET" ]; then
|
||
WINDOWS_ASSET="$(echo "$ASSETS_JSON" | jq -r '[.assets[].name | select(test("[.]exe$")) | select(test("arm64") | not)][0] // ""')"
|
||
fi
|
||
WINDOWS_ARM64_ASSET="$(pick_asset "arm64.*[.]exe$")"
|
||
MAC_ASSET="$(pick_asset "[.]dmg$")"
|
||
LINUX_TAR_ASSET="$(pick_asset "[.]tar[.]gz$")"
|
||
LINUX_APPIMAGE_ASSET="$(pick_asset "[.]AppImage$")"
|
||
|
||
build_link() {
|
||
local name="$1"
|
||
if [ -n "$name" ]; then
|
||
echo "https://github.com/$REPO/releases/download/$TAG/$name"
|
||
fi
|
||
}
|
||
|
||
WINDOWS_URL="$(build_link "$WINDOWS_ASSET")"
|
||
WINDOWS_ARM64_URL="$(build_link "$WINDOWS_ARM64_ASSET")"
|
||
MAC_URL="$(build_link "$MAC_ASSET")"
|
||
LINUX_TAR_URL="$(build_link "$LINUX_TAR_ASSET")"
|
||
LINUX_APPIMAGE_URL="$(build_link "$LINUX_APPIMAGE_ASSET")"
|
||
|
||
cat > preview_release_notes.md <<EOF
|
||
## Preview Nightly 说明
|
||
- 该版本为 **预览版**,用于提前体验即将发布的功能与修复。
|
||
- 可能包含尚未完全稳定的改动,不建议长期使用
|
||
|
||
## 下载
|
||
- Windows x64: ${WINDOWS_URL:-$RELEASE_PAGE}
|
||
- Windows arm64: ${WINDOWS_ARM64_URL:-$RELEASE_PAGE}
|
||
- macOS(Apple Silicon): ${MAC_URL:-$RELEASE_PAGE}
|
||
- Linux (.tar.gz): ${LINUX_TAR_URL:-$RELEASE_PAGE}
|
||
- Linux (.AppImage): ${LINUX_APPIMAGE_URL:-$RELEASE_PAGE}
|
||
|
||
## macOS 安装提示
|
||
- 如果被系统提示已损坏,你需要在终端执行以下命令去除隔离标记:
|
||
- \`xattr -dr com.apple.quarantine "/Applications/WeFlow.app"\`
|
||
- 执行后重新打开 WeFlow。
|
||
|
||
> 如某个平台链接暂未生成,请前往发布页查看最新资源:$RELEASE_PAGE
|
||
EOF
|
||
|
||
gh release edit "$TAG" --repo "$REPO" --notes-file preview_release_notes.md
|