Skip to content

chore: release v1.0.1 #1

chore: release v1.0.1

chore: release v1.0.1 #1

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: '发布版本 (例如: 1.0.0)'
required: true
type: string
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置 Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: 获取 pnpm store 目录
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: 设置 pnpm 缓存
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: 安装依赖
run: |
# 尝试使用 frozen lockfile,如果失败则更新 lockfile
pnpm install --frozen-lockfile || {
echo "⚠️ Lockfile 不匹配,正在更新..."
pnpm install --no-frozen-lockfile
}
- name: 格式检查
run: pnpm run lint
- name: 构建项目
run: pnpm run build
- name: 获取版本号
id: get_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: 更新版本号 (手动触发时)
if: github.event_name == 'workflow_dispatch'
run: |
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add package.json
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
git tag ${{ steps.get_version.outputs.tag_name }}
git push origin HEAD:${{ github.ref_name }}
git push origin ${{ steps.get_version.outputs.tag_name }}
- name: 生成变更日志
id: changelog
run: npx changelogithub
continue-on-error: true
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: 发布到 npm
run: pnpm publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: 创建 GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.tag_name }}
release_name: Release ${{ steps.get_version.outputs.tag_name }}
body_path: ${{ steps.changelog.outputs.changelog_file }}
draft: false
prerelease: false
- name: 通知发布成功
run: |
echo "🎉 发布成功!"
echo "📦 版本: ${{ steps.get_version.outputs.version }}"
echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}"
echo "📝 npm: https://www.npmjs.com/package/@winner-fed/plugin-element-ui"