Build and publish #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release-type: | |
| description: "Release type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - prepatch | |
| - preminor | |
| - premajor | |
| - prerelease | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| environment: Packages | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| packages: write | |
| id-token: write | |
| steps: | |
| # Checkout project repository | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| # Setup Bun | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| registry-url: https://registry.npmjs.org/ | |
| # Install dependencies | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| # Configure Git | |
| - name: Git configuration | |
| run: | | |
| git config --global user.email "137602160+bebrasmell@users.noreply.github.com>" | |
| git config --global user.name "bebrasmell (GitHub Actions)" | |
| # Bump package version (latest tag) | |
| - name: Bump release version | |
| if: startsWith(github.event.inputs.release-type, 'pre') != true | |
| run: | | |
| echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV | |
| echo "RELEASE_TAG=latest" >> $GITHUB_ENV | |
| env: | |
| RELEASE_TYPE: ${{ github.event.inputs.release-type }} | |
| # Bump package pre-release version (beta tag) | |
| - name: Bump pre-release version | |
| if: startsWith(github.event.inputs.release-type, 'pre') | |
| run: | | |
| echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV | |
| echo "RELEASE_TAG=beta" >> $GITHUB_ENV | |
| env: | |
| RELEASE_TYPE: ${{ github.event.inputs.release-type }} | |
| # Update changelog unreleased section with new version | |
| - name: Update changelog | |
| uses: superfaceai/release-changelog-action@v1 | |
| with: | |
| path-to-changelog: CHANGELOG.md | |
| version: ${{ env.NEW_VERSION }} | |
| operation: release | |
| # Bump jsr.json version | |
| - name: Bump jsr.json version | |
| run: | | |
| NEW_VER=${NEW_VERSION#v} | |
| jq --arg ver "$NEW_VER" '.version = $ver' jsr.json > tmp.json && mv tmp.json jsr.json | |
| # Commit changes and create tag | |
| - name: Commit CHANGELOG.md, package.json and jsr.json changes and create tag | |
| run: | | |
| git checkout -b release/${{ env.NEW_VERSION }} | |
| git add "package.json" | |
| git add "CHANGELOG.md" | |
| git add "jsr.json" | |
| git commit -m "chore: release ${{ env.NEW_VERSION }}" | |
| git tag ${{ env.NEW_VERSION }} | |
| # Build | |
| - name: Build | |
| run: bun run build | |
| # Publish version to NPM | |
| - name: Publish to NPM | |
| env: | |
| NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: bun publish --verbose --access public --tag ${{ env.RELEASE_TAG }} | |
| - name: Publish to JSR | |
| run: bunx jsr publish --allow-dirty | |
| # Push repository changes | |
| - name: Push changes to repository | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git push origin release/${{ env.NEW_VERSION }} && git push --tags | |
| # Create Pull Request to main | |
| - name: Create Pull Request to main | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh pr create \ | |
| --title "chore: release ${{ env.NEW_VERSION }}" \ | |
| --body "Release PR for ${{ env.NEW_VERSION }}" \ | |
| --base main \ | |
| --head release/${{ env.NEW_VERSION }} | |
| # Read version changelog | |
| - id: get-changelog | |
| name: Get version changelog | |
| uses: superfaceai/release-changelog-action@v1 | |
| with: | |
| path-to-changelog: CHANGELOG.md | |
| version: ${{ env.NEW_VERSION }} | |
| operation: read | |
| # Update GitHub release with changelog | |
| - name: Update GitHub release documentation | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ env.NEW_VERSION }} | |
| body: ${{ steps.get-changelog.outputs.changelog }} | |
| prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |