|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry-run: |
| 10 | + description: 'Preview what would be published without actually publishing' |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + uses: ./.github/workflows/ci.yml |
| 18 | + |
| 19 | + publish: |
| 20 | + name: Publish to npm |
| 21 | + needs: test |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: github.repository == 'TryGhost/gscan' |
| 24 | + concurrency: |
| 25 | + group: publish-npm-${{ github.ref }} |
| 26 | + cancel-in-progress: false |
| 27 | + |
| 28 | + permissions: |
| 29 | + id-token: write |
| 30 | + contents: read |
| 31 | + |
| 32 | + env: |
| 33 | + FORCE_COLOR: 1 |
| 34 | + CI: true |
| 35 | + NPM_CONFIG_PROVENANCE: true |
| 36 | + |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 39 | + |
| 40 | + - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 |
| 41 | + with: |
| 42 | + node-version: 24 |
| 43 | + registry-url: 'https://registry.npmjs.org' |
| 44 | + |
| 45 | + # npm 11+ is required for npm Trusted Publishing (OIDC). |
| 46 | + - name: Install npm 11 |
| 47 | + run: npm install -g npm@11 |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + run: yarn --prefer-offline --ignore-scripts --frozen-lockfile |
| 51 | + |
| 52 | + - name: Compare local and npm versions |
| 53 | + id: version_check |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + local_version=$(node -p "require('./package.json').version") |
| 57 | + npm_version=$(npm view gscan version 2>/dev/null || true) |
| 58 | +
|
| 59 | + echo "local_version=$local_version" >> "$GITHUB_OUTPUT" |
| 60 | + echo "npm_version=$npm_version" >> "$GITHUB_OUTPUT" |
| 61 | +
|
| 62 | + if [[ -z "$npm_version" || "$local_version" != "$npm_version" ]]; then |
| 63 | + echo "should_publish=true" >> "$GITHUB_OUTPUT" |
| 64 | + echo "reason=version-diff" >> "$GITHUB_OUTPUT" |
| 65 | + else |
| 66 | + echo "should_publish=false" >> "$GITHUB_OUTPUT" |
| 67 | + echo "reason=same-version" >> "$GITHUB_OUTPUT" |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Publish to npm (dry run) |
| 71 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs['dry-run'] == 'true' |
| 72 | + run: yarn ship:ci |
| 73 | + env: |
| 74 | + NPM_CONFIG_DRY_RUN: true |
| 75 | + |
| 76 | + - name: Publish to npm |
| 77 | + if: steps.version_check.outputs.should_publish == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs['dry-run'] != 'true') |
| 78 | + run: yarn ship:ci |
| 79 | + |
| 80 | + - name: Skip publish summary |
| 81 | + if: steps.version_check.outputs.should_publish != 'true' || (github.event_name == 'workflow_dispatch' && github.event.inputs['dry-run'] == 'true') |
| 82 | + run: | |
| 83 | + echo "Publish not executed." |
| 84 | + echo "Version check: ${{ steps.version_check.outputs.reason || 'not-run' }}" |
| 85 | + echo "Dry run: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs['dry-run'] == 'true' }}" |
| 86 | +
|
| 87 | + - uses: tryghost/actions/actions/slack-build@main |
| 88 | + if: failure() && secrets.SLACK_WEBHOOK_URL != '' |
| 89 | + with: |
| 90 | + status: ${{ job.status }} |
| 91 | + env: |
| 92 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments