build #113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build | |
| on: | |
| schedule: | |
| - cron: "0 16 * * *" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| with: | |
| ref: "main" | |
| submodules: recursive | |
| - uses: pnpm/action-setup@v6 | |
| name: Install pnpm | |
| with: | |
| version: 10 | |
| cache: true | |
| - name: Set up Node.js 16-nightly, latest, node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 'latest' | |
| 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' | |
| 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' | |
| run: | | |
| pnpm i --no-frozen-lockfile | |
| cd src/sub/backend | |
| pnpm i --no-frozen-lockfile | |
| - name: Bundle | |
| if: steps.check_submodules.outputs.has_updates == 'true' | |
| run: | | |
| pnpm build | |
| - id: tag | |
| name: Generate release tag | |
| if: steps.check_submodules.outputs.has_updates == 'true' | |
| run: | | |
| SUBSTORE_RELEASE=`node --eval="process.stdout.write(require('./package.json').version)"` | |
| echo "release_tag=$SUBSTORE_RELEASE" >> $GITHUB_OUTPUT | |
| - name: Prepare release | |
| if: steps.check_submodules.outputs.has_updates == 'true' | |
| run: | | |
| pnpm i -D 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' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| body_path: ./CHANGELOG.md | |
| tag_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' | |
| 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 |