Skip to content

fix: 修复工作流版本提取命令 #4

fix: 修复工作流版本提取命令

fix: 修复工作流版本提取命令 #4

Workflow file for this run

name: Publish to npm
on:
push:
branches: [main]
tags:
- 'v*'
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Extract version
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Check version tag
id: check-tag
run: |
TAG_VERSION="v${{ steps.version.outputs.VERSION }}"
echo "Checking for tag: $TAG_VERSION"
if git rev-parse "refs/tags/$TAG_VERSION" > /dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag exists, will publish"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag does not exist, skipping publish"
fi
- name: Publish to npm (on tag)
if: steps.check-tag.outputs.tag_exists == 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Release (on tag)
if: steps.check-tag.outputs.tag_exists == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.VERSION }}
release_name: TaskFlow AI v${{ steps.version.outputs.VERSION }}
draft: false
prerelease: false