|
| 1 | +name: Publish to npm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dry_run: |
| 7 | + description: 'Dry run - print the version that would be published, but do not commit or publish anything.' |
| 8 | + required: false |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + skip_versioning: |
| 12 | + description: > |
| 13 | + Skip version bump - use the version already in the repo |
| 14 | + (e.g. retry after npm publish failed but the release commit is already pushed). |
| 15 | + required: false |
| 16 | + default: false |
| 17 | + type: boolean |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + id-token: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + ci: |
| 25 | + uses: ./.github/workflows/build.yml |
| 26 | + |
| 27 | + version: |
| 28 | + needs: ci |
| 29 | + runs-on: ubuntu-latest |
| 30 | + timeout-minutes: 30 |
| 31 | + outputs: |
| 32 | + version: ${{ steps.version.outputs.version }} |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v5 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - name: Setup Node.js |
| 40 | + uses: actions/setup-node@v5 |
| 41 | + with: |
| 42 | + node-version: 24.x |
| 43 | + registry-url: 'https://registry.npmjs.org' |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + if: ${{ !inputs.skip_versioning }} |
| 47 | + run: npm ci |
| 48 | + |
| 49 | + - name: Determine version bump |
| 50 | + id: bump |
| 51 | + if: ${{ !inputs.skip_versioning }} |
| 52 | + working-directory: packages/blockly |
| 53 | + run: | |
| 54 | + RELEASE_TYPE=$(npx conventional-recommended-bump --preset conventionalcommits -t blockly-) |
| 55 | + echo "release_type=$RELEASE_TYPE" >> "$GITHUB_OUTPUT" |
| 56 | + echo "Recommended bump: $RELEASE_TYPE" |
| 57 | +
|
| 58 | + - name: Apply version bump |
| 59 | + if: ${{ !inputs.skip_versioning }} |
| 60 | + working-directory: packages/blockly |
| 61 | + run: npm version ${{ steps.bump.outputs.release_type }} --no-git-tag-version |
| 62 | + |
| 63 | + - name: Read package version |
| 64 | + id: version |
| 65 | + working-directory: packages/blockly |
| 66 | + run: | |
| 67 | + VERSION=$(node -p "require('./package.json').version") |
| 68 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 69 | + echo "Version: $VERSION" |
| 70 | +
|
| 71 | + - name: Upload versioned files |
| 72 | + if: ${{ !inputs.skip_versioning }} |
| 73 | + uses: actions/upload-artifact@v4 |
| 74 | + with: |
| 75 | + name: versioned-files |
| 76 | + path: | |
| 77 | + packages/blockly/package.json |
| 78 | + package-lock.json |
| 79 | +
|
| 80 | + publish: |
| 81 | + needs: version |
| 82 | + runs-on: ubuntu-latest |
| 83 | + if: ${{ !inputs.dry_run }} |
| 84 | + environment: release |
| 85 | + steps: |
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v5 |
| 88 | + with: |
| 89 | + fetch-depth: 0 |
| 90 | + ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }} |
| 91 | + |
| 92 | + - name: Download versioned files |
| 93 | + if: ${{ !inputs.skip_versioning }} |
| 94 | + uses: actions/download-artifact@v4 |
| 95 | + with: |
| 96 | + name: versioned-files |
| 97 | + |
| 98 | + - name: Commit and push version bump |
| 99 | + if: ${{ !inputs.skip_versioning }} |
| 100 | + run: | |
| 101 | + git config user.name "github-actions[bot]" |
| 102 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 103 | + git add packages/blockly/package.json package-lock.json |
| 104 | + git commit -m "release: v${{ needs.version.outputs.version }}" |
| 105 | + git push |
| 106 | +
|
| 107 | + - name: Setup Node.js |
| 108 | + uses: actions/setup-node@v5 |
| 109 | + with: |
| 110 | + node-version: 24.x |
| 111 | + registry-url: 'https://registry.npmjs.org' |
| 112 | + |
| 113 | + - name: Install dependencies |
| 114 | + run: npm ci |
| 115 | + |
| 116 | + - name: Build package |
| 117 | + working-directory: packages/blockly |
| 118 | + run: npm run package |
| 119 | + |
| 120 | + - name: Publish to npm |
| 121 | + working-directory: packages/blockly/dist |
| 122 | + run: npm publish --verbose |
| 123 | + |
| 124 | + - name: Create tarball |
| 125 | + working-directory: packages/blockly |
| 126 | + run: npm pack ./dist |
| 127 | + |
| 128 | + - name: Create GitHub release |
| 129 | + working-directory: packages/blockly |
| 130 | + env: |
| 131 | + GH_TOKEN: ${{ github.token }} |
| 132 | + run: | |
| 133 | + TARBALL="blockly-${{ needs.version.outputs.version }}.tgz" |
| 134 | + gh release create "blockly-v${{ needs.version.outputs.version }}" "$TARBALL" \ |
| 135 | + --repo "$GITHUB_REPOSITORY" \ |
| 136 | + --title "blockly-v${{ needs.version.outputs.version }}" \ |
| 137 | + --generate-notes |
0 commit comments