|
| 1 | +name: Publish to npm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dry_run: |
| 7 | + description: 'Dry run' |
| 8 | + required: false |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + ci: |
| 18 | + uses: ./.github/workflows/build.yml |
| 19 | + |
| 20 | + publish: |
| 21 | + needs: ci |
| 22 | + runs-on: ubuntu-latest |
| 23 | + timeout-minutes: 30 |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v5 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Setup Node.js |
| 31 | + uses: actions/setup-node@v5 |
| 32 | + with: |
| 33 | + node-version: 22.x |
| 34 | + registry-url: 'https://registry.npmjs.org' |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: npm ci |
| 38 | + |
| 39 | + - name: Determine version bump |
| 40 | + id: bump |
| 41 | + working-directory: packages/blockly |
| 42 | + run: | |
| 43 | + RELEASE_TYPE=$(npx conventional-recommended-bump --preset conventionalcommits) |
| 44 | + echo "release_type=$RELEASE_TYPE" >> "$GITHUB_OUTPUT" |
| 45 | + echo "Recommended bump: $RELEASE_TYPE" |
| 46 | +
|
| 47 | + - name: Apply version bump |
| 48 | + working-directory: packages/blockly |
| 49 | + run: npm version ${{ steps.bump.outputs.release_type }} --no-git-tag-version |
| 50 | + |
| 51 | + - name: Read new version |
| 52 | + id: version |
| 53 | + working-directory: packages/blockly |
| 54 | + run: | |
| 55 | + VERSION=$(node -p "require('./package.json').version") |
| 56 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 57 | + echo "New version: $VERSION" |
| 58 | +
|
| 59 | + - name: Commit and push version bump |
| 60 | + if: ${{ !inputs.dry_run }} |
| 61 | + run: | |
| 62 | + git config user.name "github-actions[bot]" |
| 63 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 64 | + git add packages/blockly/package.json package-lock.json |
| 65 | + git commit -m "chore: release v${{ steps.version.outputs.version }}" |
| 66 | + git push |
| 67 | +
|
| 68 | + - name: Build package |
| 69 | + if: ${{ !inputs.dry_run }} |
| 70 | + working-directory: packages/blockly |
| 71 | + run: npm run package |
| 72 | + |
| 73 | + - name: Publish to npm |
| 74 | + if: ${{ !inputs.dry_run }} |
| 75 | + working-directory: packages/blockly/dist |
| 76 | + run: npm publish |
| 77 | + |
| 78 | + - name: Create tarball |
| 79 | + if: ${{ !inputs.dry_run }} |
| 80 | + working-directory: packages/blockly |
| 81 | + run: npm pack ./dist |
| 82 | + |
| 83 | + - name: Create GitHub release |
| 84 | + if: ${{ !inputs.dry_run }} |
| 85 | + working-directory: packages/blockly |
| 86 | + env: |
| 87 | + GH_TOKEN: ${{ github.token }} |
| 88 | + run: | |
| 89 | + TARBALL=$(ls blockly-*.tgz) |
| 90 | + gh release create "blockly-v${{ steps.version.outputs.version }}" "$TARBALL" \ |
| 91 | + --repo "$GITHUB_REPOSITORY" \ |
| 92 | + --title "blockly-v${{ steps.version.outputs.version }}" \ |
| 93 | + --generate-notes |
0 commit comments