1+ name : NPM Publish
2+
3+ on :
4+ release :
5+ # This specifies that the build will be triggered when we publish a release
6+ types :
7+ - published
8+
9+ jobs :
10+ publish :
11+ name : Publish to NPM & Create Pull Request of Version Update
12+ # Run on latest version of ubuntu
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - uses : actions/checkout@v2
17+ with :
18+ # "ref" specifies the branch to check out.
19+ # "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted
20+ ref : ${{ github.event.release.target_commitish }}
21+ # install Node.js
22+ - name : Use Node.js 16
23+ uses : actions/setup-node@v1
24+ with :
25+ node-version : 16
26+ # Specifies the registry, this field is required!
27+ registry-url : https://registry.npmjs.org/
28+ # clean install of your projects' deps. We use "npm ci" to avoid package lock changes
29+ - run : npm install
30+ # set up git since we will later push to the repo
31+ - run : git config --global user.name "hyj1991"
32+ - run : git config --global user.email "yeekwanvong@gmail.com"
33+ # upgrade npm version in package.json to the tag used in the release.
34+ # upgrade npm version in package.json to the tag used in the release.
35+ - run : npm version ${{ github.event.release.tag_name }}
36+ # build the project
37+ - run : npm run build
38+ # run tests just in case
39+ - run : npm test
40+ # publish to NPM -> there is one caveat, continue reading for the fix
41+ - run : npm publish
42+ if : " !github.event.release.prerelease"
43+ env :
44+ # Use a token to publish to NPM. See below for how to set it up
45+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
46+ - run : npm publish --tag beta
47+ if : " github.event.release.prerelease"
48+ env :
49+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
50+ - name : Create Pull Request
51+ uses : peter-evans/create-pull-request@v4
52+ with :
53+ title : " Release ${{ github.event.release.tag_name }}"
0 commit comments