|
8 | 8 | branches: |
9 | 9 | - main |
10 | 10 |
|
| 11 | +defaults: |
| 12 | + run: |
| 13 | + shell: bash -o pipefail {0} |
| 14 | + |
11 | 15 | jobs: |
12 | 16 | audit: |
13 | 17 | name: Audit |
@@ -74,40 +78,51 @@ jobs: |
74 | 78 | name: coverage |
75 | 79 | path: coverage |
76 | 80 |
|
77 | | - publish: |
| 81 | + detect_version_update: |
78 | 82 | if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
79 | | - name: Publish on version update |
80 | | - needs: |
81 | | - - test |
82 | | - permissions: |
83 | | - contents: read |
84 | | - id-token: write |
| 83 | + name: Detect version update |
85 | 84 | runs-on: ubuntu-latest |
| 85 | + outputs: |
| 86 | + detected: ${{ steps.detect.outputs.detected }} |
86 | 87 | steps: |
87 | 88 | - uses: actions/checkout@v5 |
88 | | - - uses: actions/setup-node@v5 |
89 | 89 | with: |
90 | | - node-version-file: '/.nvmrc' |
91 | | - registry-url: 'https://registry.npmjs.org' |
| 90 | + fetch-depth: 2 |
92 | 91 |
|
93 | | - - name: Check for version update |
94 | | - id: check_version |
| 92 | + - id: detect |
95 | 93 | run: | |
96 | 94 | CURRENT_VERSION=$(jq -r .version package.json) |
97 | 95 | PREVIOUS_VERSION=$(git show HEAD~1:package.json | jq -r .version) |
98 | 96 |
|
99 | 97 | if [[ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]]; then |
100 | | - echo "version_updated=true" >> $GITHUB_OUTPUT |
| 98 | + echo "Version has been updated. Proceeding to publish." |
| 99 | + echo "detected=true" >> $GITHUB_OUTPUT |
| 100 | + else |
| 101 | + echo "Version has not changed. Skipping publish." |
| 102 | + echo "detected=false" >> $GITHUB_OUTPUT |
101 | 103 | fi |
102 | 104 |
|
103 | | - - if: steps.check_version.outputs.version_updated |
104 | | - run: npm ci |
| 105 | + publish: |
| 106 | + name: Publish |
| 107 | + needs: |
| 108 | + - test |
| 109 | + - detect_version_update |
| 110 | + if: needs.detect_version_update.outputs.detected == 'true' |
| 111 | + permissions: |
| 112 | + contents: read |
| 113 | + id-token: write |
| 114 | + runs-on: ubuntu-latest |
| 115 | + steps: |
| 116 | + - uses: actions/checkout@v5 |
| 117 | + - uses: actions/setup-node@v5 |
| 118 | + with: |
| 119 | + node-version-file: '/.nvmrc' |
| 120 | + registry-url: 'https://registry.npmjs.org' |
105 | 121 |
|
106 | | - - if: steps.check_version.outputs.version_updated |
107 | | - run: npm run build |
| 122 | + - run: npm ci |
| 123 | + - run: npm run build |
108 | 124 |
|
109 | | - - if: steps.check_version.outputs.version_updated |
110 | | - name: Publish |
| 125 | + - name: Publish |
111 | 126 | env: |
112 | 127 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
113 | 128 | run: | |
|
0 commit comments