chore: 修正触发条件 #2
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: Release | |
permissions: | |
contents: write | |
on: | |
# 当对分支master进行push操作的时候,触发该条工作流 | |
push: | |
branches: [master] | |
pull_request: | |
branches: [master] | |
jobs: | |
check: | |
name: 检查并创建版本号 | |
runs-on: ubuntu-latest | |
outputs: | |
created: ${{ steps.create_tag.outputs.created }} | |
steps: | |
- name: 检出代码 | |
uses: actions/checkout@v4 | |
- name: 配置 Node.js | |
uses: actions/setup-node@v4 | |
- name: 获取所有标签 | |
run: | | |
git fetch --prune --unshallow | |
- name: 读取 package.json 版本号 | |
id: package_json | |
run: | | |
version=$(node -p "require('./package.json').version") | |
echo "Package version is: $version" | |
echo "version=$version" >> $GITHUB_OUTPUT | |
- name: 检查是否有重复的版本 tag | |
id: check_version | |
run: | | |
package_version=v${{ steps.package_json.outputs.version }} | |
if git tag -l "$package_version" | grep -q "$package_version"; then | |
echo "::notice::版本 Tag '$package_version' 已存在。" | |
echo "exists=true" >> $GITHUB_OUTPUT | |
fi | |
- name: 创建版本tag | |
id: create_tag | |
if: steps.check_version.outputs.exists != 'true' | |
run: | | |
set -e | |
version_tag=v${{ steps.package_json.outputs.version }} | |
echo "Creating new tag: $version_tag" | |
git tag "$version_tag" | |
git push origin "$version_tag" | |
echo "created=true" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |