Merge branch 'v2.x' #53
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: NPM | |
on: # 配置触发workflow的事件 | |
push: | |
branches: # 添加这一行来指定触发分支 | |
- 'main' # 两个星号代表任意分支 | |
# tags: # tag更新时触发此workflow | |
# - '*' | |
jobs: | |
publish: | |
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/v')) | |
name: Publish | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
registry-url: https://registry.npmjs.org/ | |
cache: npm | |
cache-dependency-path: package.json | |
- name: Install Dependencies | |
run: npm install | |
- name: chmod | |
run: chmod +x ./scripts/generate-package-json.sh | |
- name: chmod | |
run: chmod +x ./scripts/package-publish-config-tag.sh | |
- name: Generate Package JSON | |
run: ./scripts/generate-package-json.sh | |
- name: Set Publish Config | |
run: ./scripts/package-publish-config-tag.sh | |
- name: Build Dist | |
run: npm run dist | |
- name: Check Branch | |
id: check-branch | |
run: | | |
if [[ ${{ github.ref }} =~ ^refs/heads/(main|v[0-9]+\.[0-9]+.*)$ ]]; then | |
echo ::set-output name=match::true | |
fi # See: https://stackoverflow.com/a/58869470/1123955 | |
- name: Is A Publish Branch | |
if: steps.check-branch.outputs.match == 'true' | |
run: | | |
NAME=$(npx pkg-jq -r .name) | |
VERSION=$(npx pkg-jq -r .version) | |
if npx version-exists "$NAME" "$VERSION" | |
then echo "$NAME@$VERSION exists on NPM, skipped." | |
else npm publish --access=public | |
fi | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Is Not A Publish Branch | |
if: steps.check-branch.outputs.match != 'true' | |
run: echo 'Not A Publish Branch' |