diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ac8d5e2..0f21ff2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,11 +10,13 @@ jobs: runs-on: ubuntu-latest permissions: - contents: read + contents: write id-token: write steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: oven-sh/setup-bun@v2 @@ -24,8 +26,42 @@ jobs: - run: bun install --frozen-lockfile + - name: Determine version bump + id: bump + run: | + LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + if [ -z "$LAST_TAG" ]; then + COMMITS=$(git log --format="%s" --no-merges) + else + COMMITS=$(git log "${LAST_TAG}..HEAD" --format="%s" --no-merges) + fi + + if echo "$COMMITS" | grep -qiE "^[a-z]+(\(.+\))?!:|BREAKING CHANGE"; then + BUMP=major + elif echo "$COMMITS" | grep -qiE "^feat(\(.+\))?:"; then + BUMP=minor + else + BUMP=patch + fi + + echo "type=$BUMP" >> "$GITHUB_OUTPUT" + echo "Bump type: $BUMP" + + - name: Bump version + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + npm version ${{ steps.bump.outputs.type }} --no-git-tag-version + VERSION=$(node -p "require('./package.json').version") + git add package.json + git commit -m "chore: release v${VERSION}" + git tag "v${VERSION}" + - name: Build run: bun run build - name: Publish run: npm publish --access public + + - name: Push version bump + run: git push --follow-tags