1- name : Release workflow
1+ name : Build workflow
22
33on :
44 push :
55 branches : [main]
66
7- env :
8- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
9- NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
10- NPM_PACKAGE_NAME : ' react-usage-bar'
11- VERSION : ' '
12- PUBLISHED_VERSION : ' '
13- NODE_VERSION : ' 20.x'
14-
157jobs :
168 build-and-test :
179 runs-on : ubuntu-latest
@@ -21,69 +13,13 @@ jobs:
2113 node-version : [20.x]
2214
2315 steps :
24- - uses : actions/checkout@v3
16+ - uses : actions/checkout@v4
2517 - name : Setup Node.js ${{ matrix.node-version }}
26- uses : actions/setup-node@v3
18+ uses : actions/setup-node@v4
2719 with :
2820 node-version : ${{ matrix.node-version }}
29- cache : ' npm '
21+ cache : ' yarn '
3022 - name : Install and Build
31- run : | # Install npm packages and build the src files
32- npm install --force
33- npm run build --if-present
34-
35- tag-and-npm-publish :
36- if : ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
37- runs-on : ubuntu-latest
38- permissions :
39- contents : read
40- id-token : write
41- needs : [build-and-test]
42- steps :
43- - name : Check out repository code
44- uses : actions/checkout@v4
45- with :
46- token : ${{ env.GITHUB_TOKEN }}
47- - uses : actions/setup-node@v4
48- with :
49- node-version : ${{ env.NODE_VERSION }}
50- check-latest : true
51- - name : Set NPM
52- run : |
53- echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
54- - name : Set version
55- run : |
56- echo VERSION=$(npm pkg get version | sed 's/"//g') >> $GITHUB_ENV
57- echo PUBLISHED_VERSION=$(npm show $NPM_PACKAGE_NAME version) >> $GITHUB_ENV
58- echo "VERSION ${VERSION}"
59- echo "NPM_PACKAGE_NAME ${NPM_PACKAGE_NAME}"
60- - name : Install dependecies
61- if : ${{ env.VERSION != env.PUBLISHED_VERSION }}
6223 run : |
6324 yarn install
64- - name : Build typescript
65- if : ${{ env.VERSION != env.PUBLISHED_VERSION }}
66- run : yarn build
67- - run : npm publish --dry-run
68- - uses : step-security/wait-for-secrets@v1
69- id : wait-for-secrets
70- with :
71- secrets : |
72- OTP:
73- name: 'OTP to publish package'
74- description: 'OTP from authenticator app'
75- - name : Publish on NPM
76- if : ${{ env.VERSION != env.PUBLISHED_VERSION }}
77- run : |
78- git tag v${VERSION} ${GITHUB_SHA} || exit 0
79- git push origin v${VERSION}
80- npm publish --otp ${{ steps.wait-for-secrets.outputs.OTP }}
81- - name : Check loaded and NPM version
82- if : ${{ env.VERSION == env.PUBLISHED_VERSION }}
83- run : |
84- echo "The loaded version is the same on npm. 0 new uploaded versions."
85- exit 0;
86- - name : Remove NPM token
87- if : always()
88- run : |
89- rm .npmrc
25+ yarn build
0 commit comments