chore(main): release 1.7.18 (#92) #22
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 | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 拉取代码 | |
uses: actions/checkout@v4 | |
- name: 安装node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 21 | |
registry-url: "https://registry.npmjs.org" | |
- name: 安装pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 9.7.1 | |
- name: 安装依赖 | |
run: | | |
pnpm install | |
pnpm add node-karin@latest | |
- name: 放弃 package.json 的本地更改 | |
run: | | |
git checkout HEAD package.json | |
- name: 删除 pnpm-lock.yaml | |
run: rm -rf pnpm-lock.yaml | |
- name: 编译 | |
run: pnpm 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文件夹和resources文件夹 | |
run: | | |
mkdir ./../temp | |
- name: 复制编译后的lib文件夹和resources文件夹到临时文件夹 | |
run: | | |
cp -r ./lib ./../temp/lib | |
cp -r ./resources ./../temp/resources | |
- name: 检查并创建空的 build 分支 | |
run: | | |
git fetch origin | |
# 检查 build 分支是否存在 | |
if git show-ref --verify --quiet refs/heads/dev; then | |
echo "Dev branch exists locally. Switching to it." | |
git checkout dev | |
else | |
# 检查远程是否有 dev 分支 | |
if git ls-remote --exit-code --heads origin dev; then | |
echo "Dev branch exists remotely. Fetching and switching to it." | |
git checkout dev | |
else | |
# dev 分支不存在,创建一个空的 dev 分支 | |
echo "Dev branch does not exist. Creating an empty dev branch." | |
git checkout --orphan dev # 创建一个没有历史记录的空分支 | |
git reset --hard # 重置所有文件 | |
git clean -fdx # 删除未被 Git 管理的文件和文件夹 | |
echo "Empty dev branch created." | |
git commit --allow-empty -m "Initial empty commit on dev branch" | |
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} dev # 推送到远程仓库 | |
fi | |
fi | |
- name: 切换到 build 分支 | |
run: | | |
git fetch origin dev | |
git checkout dev | |
- name: 删除dev分支上的lib文件夹和resources文件夹 | |
run: | | |
rm -rf lib | |
rm -rf resources | |
- name: 复制编译后的lib文件夹和resources文件夹到 dev 分支 | |
run: | | |
cp -r ./../temp/lib ./ | |
cp -r ./../temp/resources ./ | |
- name: 删除临时文件夹 | |
run: | | |
rm -rf ./../temp | |
- name: 从main分支复制文件到dev分支 | |
run: | | |
git checkout main -- package.json CHANGELOG.md README.md config resources LICENSE | |
- name: 删除依赖文件夹 node_modules | |
run: | | |
rm -rf node_modules | |
- name: 将文件整理到 karin-plugin-ling 文件夹 | |
run: | | |
mkdir -p karin-plugin-ling | |
find . -path "./.git" -prune -o -type f -print | while read file; do | |
mkdir -p "karin-plugin-ling/$(dirname "$file")" | |
cp "$file" "karin-plugin-ling/$file" | |
done | |
- name: 创建 dev.zip | |
run: zip -r dev.zip karin-plugin-ling | |
- name: 上传 dev.zip | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dev-zip | |
path: dev.zip | |
- name: 删除 karin-plugin-ling 文件夹 | |
run: rm -rf karin-plugin-ling | |
- name: 删除开发依赖 | |
run: npm run pr clean | |
- name: 根据main分支的commit信息生成提交消息 | |
run: | | |
git add . | |
git reset dev.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: 设置 dev 分支的上游分支 | |
run: git push --set-upstream origin dev | |
- name: 推送到 dev 分支 | |
uses: ad-m/github-push-action@master | |
with: | |
branch: dev | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
force_with_lease: true | |
args: --set-upstream | |
- name: 更新版本号 | |
uses: google-github-actions/release-please-action@v3 | |
id: release_please | |
with: | |
release-type: node | |
package-name: 'karin-plugin-ling' | |
- name: 发布到 npm | |
run: npm run pub | |
if: ${{ steps.release_please.outputs.release_created }} | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- 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 }} dev.zip |