Skip to content

release: 0.4.0

release: 0.4.0 #58

Workflow file for this run

name: 发包到 NPM
on:
push:
branches:
- main # 当推送到 main 分支时触发
tags:
- '*' # 当打 tag 时触发
jobs:
release:
runs-on: ubuntu-latest # 使用最新的 Ubuntu 作为运行环境
if: '!(( github.ref == ''refs/heads/main'' ) && contains(github.event.head_commit.message, ''release''))'
steps:
- name: 检出仓库代码
uses: actions/checkout@v4
- name: 安装 pnpm
uses: pnpm/action-setup@v4
- name: 设置 Node.js 环境
uses: actions/setup-node@v4
with:
node-version: 'latest'
registry-url: 'https://registry.npmjs.org/'
cache: 'pnpm'
- name: 安装依赖
run: pnpm i
- name: 构建
run: pnpm build
- name: 更新 package.json 中的版本号
id: update_version
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'release')
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
MAJOR_MINOR_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1"."$2}')
NEW_VERSION="${MAJOR_MINOR_VERSION}.$(date +%s)"
pnpm version $NEW_VERSION --no-git-tag-version
echo "new_version=${NEW_VERSION}" >> $GITHUB_ENV
- name: 发布到 NPM(main 分支的预发布版本)
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'release')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 使用 NPM 的认证 token
run: pnpm publish --tag prerelease --access public --no-git-checks
- name: 发布到 NPM(使用 tag 的正式版本发布)
if: startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 使用 NPM 的认证 token
run: pnpm publish --access public --no-git-checks
- name: 设置发布类型为正式或预发布
id: set_release_type
run: |
if [[ "${{ github.ref }}" == refs/heads/main ]]; then
echo "release_type=prerelease" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "release_type=latest" >> $GITHUB_ENV
fi
- name: 使用 GitHub App 进行身份验证
id: auth
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_SECRET }}
owner: ${{ github.repository_owner }}
- name: 触发 RLE-wiki 仓库的构建工作流
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ steps.auth.outputs.token }}" \
https://api.github.com/repos/project-trans/RLE-wiki/actions/workflows/update-and-build.yml/dispatches \
-d '{"ref":"main", "inputs": {"theme_version": "${{ env.release_type }}"}}'