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