@@ -2,18 +2,19 @@ name: Publish Package
22
33on :
44 push :
5- tags :
6- - ' v*'
5+ branches : main
76
87permissions :
8+ contents : write
99 id-token : write
10- contents : read
1110
1211jobs :
1312 publish :
1413 runs-on : ubuntu-latest
1514 steps :
1615 - uses : actions/checkout@v4
16+ with :
17+ fetch-depth : 0
1718
1819 - uses : actions/setup-node@v4
1920 with :
2324 - name : Update npm
2425 run : npm install -g npm@latest
2526
26- - run : npm ci
27+ - name : Get package version
28+ id : version
29+ run : |
30+ echo "version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
31+ echo "version_number=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
32+
33+ - name : Check if tag exists
34+ id : tag_check
35+ run : |
36+ if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
37+ echo "exists=true" >> $GITHUB_OUTPUT
38+ else
39+ echo "exists=false" >> $GITHUB_OUTPUT
40+ fi
41+
42+ - name : Extract changelog for version
43+ if : steps.tag_check.outputs.exists == 'false'
44+ run : |
45+ VERSION_NUMBER="${{ steps.version.outputs.version_number }}"
46+ awk -v ver="$VERSION_NUMBER" '
47+ /^## \[/ {
48+ if (found) exit
49+ if (index($0, ver)) found=1
50+ next
51+ }
52+ found { print }
53+ ' CHANGELOG.md > release_notes.md
54+
55+ - name : Create tag and release
56+ if : steps.tag_check.outputs.exists == 'false'
57+ env :
58+ GH_TOKEN : ${{ github.token }}
59+ run : |
60+ git config user.name "github-actions[bot]"
61+ git config user.email "github-actions[bot]@users.noreply.github.com"
62+ git tag ${{ steps.version.outputs.version }}
63+ git push origin ${{ steps.version.outputs.version }}
64+ gh release create ${{ steps.version.outputs.version }} \
65+ --title "${{ steps.version.outputs.version }}" \
66+ --notes-file release_notes.md
67+
68+ - name : Check if already published
69+ id : npm_check
70+ run : |
71+ PUBLISHED=$(npm view @reserve-protocol/react-zapper version 2>/dev/null || echo "0.0.0")
72+ CURRENT="${{ steps.version.outputs.version_number }}"
73+ if [ "$PUBLISHED" = "$CURRENT" ]; then
74+ echo "published=true" >> $GITHUB_OUTPUT
75+ else
76+ echo "published=false" >> $GITHUB_OUTPUT
77+ fi
78+
79+ - name : Install dependencies
80+ if : steps.npm_check.outputs.published == 'false'
81+ run : npm ci
2782
28- - run : npm run build
83+ - name : Build package
84+ if : steps.npm_check.outputs.published == 'false'
85+ run : npm run build
2986
30- - run : npm publish
87+ - name : Publish to npm
88+ if : steps.npm_check.outputs.published == 'false'
89+ run : npm publish
0 commit comments