diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index e907652..94326ec 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -39,9 +39,26 @@ jobs: echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" echo "Current version: $CURRENT_VERSION" - - name: Bump minor version + - name: Determine version bump type + id: version_type run: | - cargo set-version --bump minor + LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}" + echo "PR Labels: $LABELS" + + if [[ "$LABELS" == *"major"* ]]; then + echo "bump_type=major" >> "$GITHUB_OUTPUT" + echo "Version bump: MAJOR" + elif [[ "$LABELS" == *"minor"* ]]; then + echo "bump_type=minor" >> "$GITHUB_OUTPUT" + echo "Version bump: MINOR" + else + echo "bump_type=patch" >> "$GITHUB_OUTPUT" + echo "Version bump: PATCH (default)" + fi + + - name: Bump version + run: | + cargo set-version --bump ${{ steps.version_type.outputs.bump_type }} NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') echo "New version: $NEW_VERSION" echo "new_version=$NEW_VERSION" >> "$GITHUB_ENV" @@ -67,7 +84,19 @@ jobs: run: | git push origin "v${{ env.new_version }}" + - name: Check if version exists on crates.io + id: check_version + run: | + if cargo search gonfig --limit 1 | grep -q "gonfig = \"${{ env.new_version }}\""; then + echo "version_exists=true" >> "$GITHUB_OUTPUT" + echo "Version ${{ env.new_version }} already exists on crates.io" + else + echo "version_exists=false" >> "$GITHUB_OUTPUT" + echo "Version ${{ env.new_version }} does not exist, proceeding with publish" + fi + - name: Publish to crates.io + if: steps.check_version.outputs.version_exists == 'false' run: | cargo publish env: @@ -87,10 +116,12 @@ jobs: **PR Title:** ${{ github.event.pull_request.title }} + **Version Bump:** ${{ steps.version_type.outputs.bump_type | upper }} + **Merged by:** @${{ github.event.pull_request.merged_by.login }} ### Published to crates.io - This version has been published to [crates.io](https://crates.io/crates/gonfig) and is available for use in your projects. + ${{ steps.check_version.outputs.version_exists == 'false' && 'This version has been published to [crates.io](https://crates.io/crates/gonfig) and is available for use in your projects.' || 'This version was already available on [crates.io](https://crates.io/crates/gonfig).' }} ```toml [dependencies]