-
Notifications
You must be signed in to change notification settings - Fork 142
50 lines (41 loc) · 1.6 KB
/
publish npm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Publish NPM Packages
on:
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: Publish Package
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
cd packages/${{ github.event.inputs.packagePath }}
npm install --legacy-peer-deps
npm version ${{ github.event.inputs.versionType }}
npm run build
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
npm publish
echo "PACKAGE_NAME=$(node -p "require('./package.json').name")" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
git add package.json
git commit -m "Bump version to ${PACKAGE_VERSION}"
git tag -a "${PACKAGE_NAME}@${PACKAGE_VERSION}" -m "Release ${PACKAGE_NAME} version ${PACKAGE_VERSION}"
git push origin "${PACKAGE_NAME}@${PACKAGE_VERSION}"