1- name : " Release New Version "
1+ name : Publish to npm
22
33on :
4- workflow_dispatch :
5-
6- permissions :
7- contents : write
4+ release :
5+ types : [published]
86
97jobs :
10- publish :
8+ build :
119 runs-on : ubuntu-latest
10+ permissions :
11+ contents : read
12+ id-token : write
1213 steps :
13- - name : " Checkout source code"
14- uses : actions/checkout@v4
15- with :
16- fetch-depth : 0
17-
18- - name : " Set up Node.js"
19- uses : actions/setup-node@v4
20- with :
21- node-version : 22.x
22- registry-url : " https://registry.npmjs.org/"
23-
24- - name : " Install dependencies"
25- run : npm ci
26-
27- - name : " Create build"
28- run : npm run build
29-
30- - name : " Get version from package.json"
31- id : get_version
32- run : |
33- VERSION="v$(node -p 'require("./package.json").version')"
34- echo "version=$VERSION" >> $GITHUB_OUTPUT
35-
36- - name : " Get previous Git tag"
37- id : get_previous_tag
38- run : |
39- VERSION="${{ steps.get_version.outputs.version }}"
40- PREV_TAG=$(git tag --sort=-creatordate | grep '^v' | grep -v "$VERSION" | head -n 1)
41- echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
42-
43- - name : " Fetch and categorize merged PRs"
44- id : fetch_prs
45- env :
46- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
47- run : |
48- set -e
49- PREVIOUS_TAG=${{ steps.get_previous_tag.outputs.previous_tag }}
50- if [ -z "$PREVIOUS_TAG" ]; then
51- echo "pr_list=No previous tag found to compare PRs." >> $GITHUB_OUTPUT
52- exit 0
53- fi
54- PREVIOUS_SHA=$(git rev-list -n 1 $PREVIOUS_TAG)
55- PREVIOUS_DATE=$(git show -s --format=%cI $PREVIOUS_SHA)
56- CURRENT_DATE=$(git show -s --format=%cI HEAD)
57- echo "Fetching PRs merged between $PREVIOUS_DATE and $CURRENT_DATE"
58-
59- RAW_PRS=$(gh pr list --state merged --search "merged:${PREVIOUS_DATE}..${CURRENT_DATE}" \
60- --json number,title,url \
61- --jq '.[] | "- [#\(.number)](\(.url)) \(.title)"')
62-
63- if [ -z "$RAW_PRS" ]; then
64- echo "pr_list=No pull requests were merged during this release." >> $GITHUB_OUTPUT
65- exit 0
66- fi
67-
68- ADDED=""
69- FIXED=""
70- while IFS= read -r pr; do
71- if echo "$pr" | grep -iq "fix"; then
72- FIXED+="$pr"$'\n'
73- else
74- ADDED+="$pr"$'\n'
75- fi
76- done <<< "$RAW_PRS"
77-
78- BODY=""
79- if [ -n "$ADDED" ]; then
80- BODY="$BODY### Added"$'\n'"$ADDED"
81- fi
82- if [ -n "$FIXED" ]; then
83- BODY="$BODY"$'\n'"### Fixed"$'\n'"$FIXED"
84- fi
85-
86- echo "pr_list<<EOF" >> $GITHUB_OUTPUT
87- echo "$BODY" >> $GITHUB_OUTPUT
88- echo "EOF" >> $GITHUB_OUTPUT
89-
90- - name : " Set Git user name and email"
91- run : |
92- git config --global user.name "github-actions"
93- git config --global user.email "[email protected] " 94-
95- - name : " Create Git tag for version"
96- run : git tag ${{ steps.get_version.outputs.version }}
97-
98- - name : " Push tag to origin"
99- run : git push origin ${{ steps.get_version.outputs.version }}
100-
101- - name : " Publish to NPM"
102- run : npm publish --provenance --access public
103- env :
104- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
105-
106- - name : " Create GitHub Release"
107- uses : actions/create-release@v1
14+ - uses : actions/checkout@v5
15+ - uses : actions/setup-node@v4
10816 with :
109- tag_name : ${{ steps.get_version.outputs.version }}
110- release_name : ${{ steps.get_version.outputs.version }}
111- body : |
112- ${{ steps.fetch_prs.outputs.pr_list }}
113-
114- Published by ${{ github.actor }}
17+ node-version : ' 20.x'
18+ registry-url : ' https://registry.npmjs.org'
19+ - run : npm ci
20+ - run : npm publish --provenance --access public
11521 env :
116- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments