|
1 | | -name: Release |
| 1 | +name: Publish |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: [published] |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'package.json' |
6 | 9 |
|
7 | 10 | permissions: |
8 | 11 | contents: read |
9 | 12 | id-token: write |
10 | 13 |
|
11 | 14 | jobs: |
12 | | - publish: |
| 15 | + version-check: |
13 | 16 | runs-on: ubuntu-latest |
14 | | - environment: npm |
| 17 | + outputs: |
| 18 | + version_changed: ${{ steps.check.outputs.changed }} |
| 19 | + version: ${{ steps.check.outputs.version }} |
15 | 20 | steps: |
16 | 21 | - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
17 | 24 |
|
18 | | - - name: Validate version |
| 25 | + - name: Detect package.json version bump |
| 26 | + id: check |
19 | 27 | run: | |
20 | | - TAG_VERSION="${GITHUB_REF_NAME#v}" |
21 | | - PKG_VERSION=$(node -p "require('./package.json').version") |
22 | | - if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then |
23 | | - echo "::error::Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)" |
24 | | - exit 1 |
25 | | - fi |
| 28 | + set -euo pipefail |
| 29 | + NEW=$(node -p "require('./package.json').version") |
| 30 | + echo "version=${NEW}" >> "$GITHUB_OUTPUT" |
| 31 | + BEFORE="${{ github.event.before }}" |
| 32 | + OLD=$(git show "${BEFORE}:package.json" 2>/dev/null | jq -r .version 2>/dev/null) || OLD="" |
| 33 | + echo "changed=$([[ "$BEFORE" =~ ^0{40}$ || "$OLD" != "$NEW" ]] && echo true || echo false)" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + publish: |
| 36 | + needs: version-check |
| 37 | + if: needs.version-check.outputs.version_changed == 'true' |
| 38 | + runs-on: ubuntu-latest |
| 39 | + environment: npm |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
26 | 42 |
|
27 | 43 | - name: Setup Node.js |
28 | 44 | uses: actions/setup-node@v4 |
|
40 | 56 |
|
41 | 57 | # Runs after npm publish; failures here do not affect the published package (re-run this job only if needed). |
42 | 58 | notify-vscode-motoko: |
43 | | - needs: publish |
| 59 | + needs: [publish, version-check] |
44 | 60 | runs-on: ubuntu-latest |
45 | 61 | steps: |
46 | 62 | - name: Generate GitHub App token |
|
59 | 75 | token: ${{ steps.dispatch-token.outputs.token }} |
60 | 76 | repository: caffeinelabs/vscode-motoko |
61 | 77 | event-type: motoko-release |
62 | | - client-payload: '{"version":"${{ github.event.release.tag_name }}"}' |
| 78 | + client-payload: '{"version":"v${{ needs.version-check.outputs.version }}"}' |
0 commit comments