feat: 使用fastify #16
This file contains 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, Bump Version, and Commit | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.10.0 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 9.0.2 | |
- name: Install dependencies | |
run: pnpm install | |
- name: Run build | |
run: pnpm run build | |
- name: setup git config | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
# 存储编译后的lib文件夹 | |
- name: Stash uncommitted changes | |
run: | | |
git stash push -u -m "stash lib folder" | |
# 切换到 build 分支 | |
- name: Checkout build branch | |
run: | | |
git fetch origin build | |
git checkout build | |
# 复制编译后的lib文件夹到 build 分支 | |
- name: Apply stashed changes | |
run: | | |
if [ -d "lib" ]; then | |
git rm -rf lib | |
fi | |
git stash pop | |
# 从main分支复制文件到build分支 | |
- name: Copy files to build branch | |
run: | | |
git checkout main -- package.json CHANGELOG.md pnpm-lock.yaml README.md .gitignore index.js config | |
# 检查是否有变更 | |
- name: Check for changes in the repository | |
run: | | |
if [ -z "$(git diff --cached --name-only)" ] && [ -z "$(git status --porcelain)" ]; then | |
echo "No changes detected, ending job." | |
exit 0 | |
fi | |
# 获取上次提交的消息 | |
- name: Get the last commit message from main branch | |
id: get_commit_message | |
run: | | |
LAST_COMMIT_MSG=$(git log -1 --pretty=%B main | tr -d '\n' | sed 's/"/\\"/g') | |
echo "commit_message=$LAST_COMMIT_MSG" >> $GITHUB_ENV | |
# 根据main分支的提交消息 | |
- name: Commit changes | |
run: | | |
git add . | |
if [ -z "$(git diff --cached --name-only)" ]; then | |
echo "No changes detected, ending job." | |
exit 0 | |
else | |
git commit -m "chore(build): $commit_message" | |
fi | |
# 推送到 build 分支 | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
branch: build | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
force_with_lease: true | |
- name: Create build zip | |
run: | | |
find . \( -path "./node_modules" -o -path "./.git" \) -prune -o -type f -print | zip -@ build.zip | |
- name: Upload build.zip as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-zip | |
path: build.zip | |
# 更新版本号 | |
- name: Run release-please | |
uses: googleapis/release-please-action@v4 | |
id: release_please | |
with: | |
release-type: node | |
token: ${{ secrets.GITHUB_TOKEN }} | |
bump-minor-pre-major: true | |
version-file: package.json | |
fork: false | |
create-release: true | |
- name: Upload Release Artifact | |
if: ${{ steps.release_please.outputs.release_created }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh release upload ${{ steps.release_please.outputs.tag_name }} build.zip |