@@ -3,40 +3,56 @@ name: Deploy release to NPM
33on :
44 release :
55 types : [published]
6-
6+
77jobs :
88 publish-to-npm :
99 runs-on : ubuntu-latest
1010 steps :
1111 - uses : actions/checkout@v3
1212
1313 - name : Set up node
14- uses : actions/setup-node@v3
14+ uses : actions/setup-node@v4
1515 with :
16- node-version : ' 18.x '
16+ node-version : ' 20 '
1717 # Enables caching Yarn dependencies (uses https://github.com/actions/cache under the hood)
1818 cache : ' yarn'
1919 registry-url : ' https://registry.npmjs.org'
2020 always-auth : true
2121
22+ - name : Create env variables
23+ run : |
24+ RELEASE_VERSION=${{ github.event.release.tag_name }}
25+ NEW_VERSION_NUMBER=${RELEASE_VERSION/v}
26+ echo NEW_VERSION_NUMBER=$NEW_VERSION_NUMBER >> $GITHUB_ENV
27+ echo Publishing $NEW_VERSION_NUMBER
28+
29+ - name : setup git config
30+ run : |
31+ git config user.name "GitHub Actions Bot"
32+ git config user.email "<>"
33+
2234 - name : Install dependencies
2335 run : yarn install --frozen-lockfile
2436
25- # Make sure you have bumped the version before publishing the release
26- # This script will not bump the version and will use the version from package.json
27- # It will just fail if trying to publish an already published version
37+ # Sets the version number in package.json
38+ # Invoked with --no-git-tag-version because the tag is already created by Github Release
39+ - name : Bump package version
40+ run : yarn version --new-version $NEW_VERSION_NUMBER --no-git-tag-version
41+
42+ - name : Commit package version bump
43+ run : |
44+ git add package.json
45+ git commit -m "chore: Release ${{ github.event.release.tag_name }}"
46+
47+ # Builds and publishes the package.
48+ # Invoked with --no-git-tag-version because the tag is already created by Github Release
2849 - name : Build and publish the package
29- run : yarn publish --non-interactive --new-version ${{ github.event.release.tag_name }} -- no-git-tag-version
50+ run : yarn publish --non-interactive --no-git-tag-version
3051 env :
3152 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
3253
33- - name : setup git config
54+ - name : Replace tag and push commit
3455 run : |
35- git config user.name "GitHub Actions Bot"
36- git config user.email "<>"
37-
38- - name : Commit files
39- run : |
40- git add package.json
41- git commit -m "chore: Release ${{ github.event.release.tag_name }}"
42- git push origin master
56+ git push origin --delete ${{ github.event.release.tag_name }}
57+ git tag -af ${{ github.event.release.tag_name }} -m "Release ${{ github.event.release.tag_name }}"
58+ git push origin master --follow-tags
0 commit comments