Skip to content

chore: add publish actions #17

chore: add publish actions

chore: add publish actions #17

Workflow file for this run

name: Publish NPM Packages
on: push
workflow_dispatch:

Check failure on line 3 in .github/workflows/publish npm.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/publish npm.yml

Invalid workflow file

You have an error in your yaml syntax on line 3
inputs:
packagePath:
description: 'Path to the package (e.g., action-block)'
required: true
versionType:
description: 'Version update type (major, minor, patch)'
required: true
default: 'patch'
jobs:
publish-package:
runs-on: ubuntu-latest
if: >-
github.ref == 'refs/heads/main' &&
(github.actor == 'JackLian' || github.actor == 'liujuping')
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16' # 或者您希望的任何版本
- name: Install Dependencies and Publish
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
cd packages
cd ${{ github.event.inputs.packagePath }}
npm install
# 假设您使用 npm 来修改版本和发布
npm run build
npm version patch
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
npm publish
echo "::set-output name=PACKAGE_NAME::$(node -p "require('./package.json').name")"
echo "::set-output name=PACKAGE_VERSION::$(node -p "require('./package.json').version")"
git tag -a "${{ steps.package_info.outputs.PACKAGE_NAME }}@${{ steps.package_info.outputs.PACKAGE_VERSION }}" -m "Release ${{ steps.package_info.outputs.PACKAGE_NAME }} version ${{ steps.package_info.outputs.PACKAGE_VERSION }}"
git push origin "${{ steps.package_info.outputs.PACKAGE_NAME }}@${{ steps.package_info.outputs.PACKAGE_VERSION }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 确保在您的 GitHub 仓库的 Secrets 中设置了 NPM_TOKEN