chore: add publish actions #17
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: Publish NPM Packages | ||
on: push | ||
workflow_dispatch: | ||
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 |