Skip to content

build

build #120

Workflow file for this run

name: build
on:
push:
tags:
- 'v*'
schedule:
- cron: "0 16 * * *"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: "main"
submodules: recursive
- name: Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10
cache: true
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'pnpm'
- name: Check and update submodules
id: check_submodules
run: |
git submodule status --recursive > submodules_before.txt
git submodule update --remote --recursive
git submodule status --recursive > submodules_after.txt
if ! diff submodules_before.txt submodules_after.txt > /dev/null; then
echo "Submodules have been updated"
echo "has_updates=true" >> $GITHUB_OUTPUT
echo "Submodule changes:"
diff submodules_before.txt submodules_after.txt || true
else
echo "No submodule updates"
echo "has_updates=false" >> $GITHUB_OUTPUT
fi
rm -f submodules_before.txt submodules_after.txt
- name: Update package version if submodules changed
if: steps.check_submodules.outputs.has_updates == 'true' && github.event_name != 'push'
run: |
pnpm version patch --no-git-tag-version
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: 同步 Sub-store 至 V$(node -p "require('./src/sub/backend/package.json').version")"
git push origin main
- name: Install dependencies
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
run: |
pnpm i --no-frozen-lockfile
- name: Bundle
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
run: |
pnpm build
- name: Generate release tag
id: tag
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
run: |
if [ "${{ github.event_name }}" == "push" ]; then
# 从推送的 tag 获取版本号
TAG_NAME="${{ github.ref_name }}"
# 移除 v 前缀(如果存在)
VERSION="${TAG_NAME#v}"
echo "release_tag=$VERSION" >> $GITHUB_OUTPUT
else
# 从 package.json 获取版本号
SUBSTORE_RELEASE=`node --eval="process.stdout.write(require('./package.json').version)"`
echo "release_tag=$SUBSTORE_RELEASE" >> $GITHUB_OUTPUT
fi
- name: Prepare release
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
run: |
pnpm i -D -w conventional-changelog-cli
npx conventional-changelog -p cli -i CHANGELOG.md -s
- name: Release
uses: softprops/action-gh-release@v1
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: ./CHANGELOG.md
tag_name: ${{ github.event_name == 'push' && github.ref_name || steps.tag.outputs.release_tag }}
files: |
./dist/_worker.js
- name: Git push assets to "release" branch
if: steps.check_submodules.outputs.has_updates == 'true' || github.event_name == 'push'
run: |
cd dist || exit 1
git init
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b release
git add .
git commit -m "release: ${{ steps.tag.outputs.release_tag }}"
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u origin release