Skip to content

Merge pull request #49 from XasYer/release-please--branches--main--co… #115

Merge pull request #49 from XasYer/release-please--branches--main--co…

Merge pull request #49 from XasYer/release-please--branches--main--co… #115

Workflow file for this run

name: Build, Bump Version, and Commit
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 安装node
uses: actions/setup-node@v4
with:
node-version: 20.10.0
- name: 安装pnpm
uses: pnpm/action-setup@v2
with:
version: 9.0.2
- name: 安装依赖
run: pnpm install
- name: 编译
run: pnpm run build
- name: 设置时区
run: |
sudo timedatectl set-timezone Asia/Shanghai
- name: 设置git用户名和邮箱
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: 创建临时文件夹存储编译后的lib文件夹
run: |
mkdir ./../temp
- name: 复制编译后的lib文件夹到临时文件夹
run: |
cp -r ./lib ./../temp/lib
- name: 切换到 build 分支
run: |
git fetch origin build
git checkout build
- name: 删除build分支上的lib文件夹
run: |
rm -rf lib
- name: 复制编译后的lib文件夹到 build 分支
run: |
cp -r ./../temp/lib ./
- name: 删除临时文件夹
run: |
rm -rf ./../temp
- name: 从main分支复制文件到build分支
run: |
git checkout main -- package.json CHANGELOG.md pnpm-lock.yaml README.md index.js config
- name: 创建 build.zip
run: |
find . -path "./.git" -prune -o -type f -print | zip -@ build.zip
- name: 上传 build.zip
uses: actions/upload-artifact@v4
with:
name: build-zip
path: build.zip
- name: 根据main分支的commit信息生成提交消息
run: |
rm -rf node_modules
git add .
git reset build.zip
if [ -z "$(git diff --cached --name-only)" ]; then
echo "No changes detected"
exit 0
else
git commit -m "chore(build): ${{ github.event.head_commit.message }}"
fi
- name: 推送到 build 分支
uses: ad-m/github-push-action@master
with:
branch: build
github_token: ${{ secrets.GITHUB_TOKEN }}
force_with_lease: true
- name: 更新版本号
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: 上传 release
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