Skip to content

Commit 32d7e4a

Browse files
committed
ci: update publish workflow to trigger on tag push
1 parent 037e9f3 commit 32d7e4a

File tree

1 file changed

+27
-82
lines changed

1 file changed

+27
-82
lines changed

.github/workflows/publish.yml

Lines changed: 27 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,48 @@
1-
name: publish
2-
1+
name: Node.js Package
32
on:
4-
pull_request:
5-
branches:
6-
- master
7-
types: [closed]
3+
push:
4+
tags:
5+
- v[0-9]+.[0-9]+.[0-9]+
86

9-
env:
10-
CI: true
11-
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
7+
permissions:
8+
contents: write
9+
packages: write
1210

1311
jobs:
1412
publish:
1513
runs-on: ubuntu-latest
16-
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1914
steps:
20-
- name: Pull Request Merged
21-
if: github.event.pull_request.merged == false
22-
run: |
23-
echo 'The pull request has not been merged'
24-
exit 1
25-
26-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
2716
with:
2817
fetch-depth: 0
2918

30-
- name: Set git config
31-
run: |
32-
git config user.name github-actions
33-
git config user.email github-actions@github.com
34-
35-
- name: Use Node.js
36-
uses: actions/setup-node@v4
19+
- uses: actions/setup-node@v6
3720
with:
38-
node-version: 20.x
21+
node-version: "22.x"
22+
cache: "yarn"
3923
registry-url: "https://registry.npmjs.org"
4024

41-
- name: Setup .npmrc
42-
shell: bash
43-
run: |
44-
npm set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
45-
env:
46-
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
47-
48-
- name: Ensure access
49-
shell: bash
50-
run: npm whoami --registry https://registry.npmjs.org/
51-
env:
52-
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
53-
54-
- name: Install global dependencies
55-
run: npm i standard-version yarn -g
56-
5725
- name: Install dependencies
58-
run: yarn
59-
60-
- name: Get Prev Version
61-
shell: bash -ex {0}
62-
run: |
63-
PREV_VERSION=$(node -p 'require("./package.json").version')
64-
echo "::set-env name=PREV_VERSION::${PREV_VERSION}"
26+
run: npm ci
6527

66-
- name: Bump version
67-
run: |
68-
standard-version
28+
- name: Build
29+
run: npm run build
6930

70-
- name: Get Current Version
71-
shell: bash -ex {0}
72-
run: |
73-
CURRENT_VERSION=$(node -p 'require("./package.json").version')
74-
echo "::set-env name=CURRENT_VERSION::${CURRENT_VERSION}"
31+
- name: Run tests
32+
run: npm test
7533

76-
- name: Publish
77-
if: env.PREV_VERSION != env.CURRENT_VERSION
78-
run: |
79-
npm run build
80-
npm publish
34+
- name: Publish to NPM
35+
run: npm publish --access public
8136
env:
8237
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
8338

84-
- name: Push changes
85-
uses: ad-m/github-push-action@v0.6.0
86-
if: env.PREV_VERSION != env.CURRENT_VERSION
39+
- name: Create GitHub Release
40+
uses: softprops/action-gh-release@v2
8741
with:
88-
github_token: ${{ secrets.GITHUB_TOKEN }}
89-
branch: ${{ github.ref }}
90-
tags: true
91-
92-
- name: Create comment
93-
uses: actions/github-script@0.8.0
94-
if: env.PREV_VERSION != env.CURRENT_VERSION
95-
with:
96-
github-token: ${{secrets.GITHUB_TOKEN}}
97-
script: |
98-
github.issues.createComment({
99-
issue_number: context.issue.number,
100-
owner: context.repo.owner,
101-
repo: context.repo.repo,
102-
body: 'NPM package v${{ env.CURRENT_VERSION }} has been published 🎉'
103-
})
42+
tag_name: ${{ github.ref_name }}
43+
name: Release ${{ github.ref_name }}
44+
generate_release_notes: true
45+
draft: false
46+
prerelease: false
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)