docs: Update version in README to 0.1.6 #14
Workflow file for this run
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: Version Bump on PR Merge | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| version-bump: | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| - name: Setup Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| profile: minimal | |
| override: true | |
| - name: Install cargo-edit | |
| run: cargo install cargo-edit | |
| - name: Get current version | |
| id: get_version | |
| run: | | |
| CURRENT_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') | |
| echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Current version: $CURRENT_VERSION" | |
| - name: Determine version bump type | |
| id: version_type | |
| run: | | |
| LABELS="${{ join(github.event.pull_request.labels.*.name, ' ') }}" | |
| echo "PR Labels: $LABELS" | |
| if [[ "$LABELS" == *"major"* ]]; then | |
| echo "bump_type=major" >> "$GITHUB_OUTPUT" | |
| echo "bump_type_upper=MAJOR" >> "$GITHUB_OUTPUT" | |
| echo "Version bump: MAJOR" | |
| elif [[ "$LABELS" == *"minor"* ]]; then | |
| echo "bump_type=minor" >> "$GITHUB_OUTPUT" | |
| echo "bump_type_upper=MINOR" >> "$GITHUB_OUTPUT" | |
| echo "Version bump: MINOR" | |
| else | |
| echo "bump_type=patch" >> "$GITHUB_OUTPUT" | |
| echo "bump_type_upper=PATCH" >> "$GITHUB_OUTPUT" | |
| echo "Version bump: PATCH (default)" | |
| fi | |
| - name: Bump version | |
| run: | | |
| # Bump main package version | |
| 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" | |
| # Bump derive crate version to match | |
| cd gonfig_derive | |
| cargo set-version $NEW_VERSION | |
| cd .. | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| - name: Create version bump branch and commit | |
| run: | | |
| # Debug: Check git status | |
| git status | |
| # Create release branch | |
| git checkout -b "release/v${{ env.new_version }}" | |
| # Add changes (include both main and derive crate) | |
| git add Cargo.toml gonfig_derive/Cargo.toml | |
| if [ -f Cargo.lock ]; then | |
| git add Cargo.lock | |
| fi | |
| # Check if there are changes to commit | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit. Version might already be set." | |
| exit 1 | |
| fi | |
| # Commit and tag (only if tag doesn't exist) | |
| git commit -m "Release v${{ env.new_version }}" | |
| if git rev-parse "v${{ env.new_version }}" >/dev/null 2>&1; then | |
| echo "Tag v${{ env.new_version }} already exists, skipping tag creation" | |
| else | |
| git tag "v${{ env.new_version }}" | |
| fi | |
| - name: Build release artifacts | |
| run: | | |
| cargo build --release | |
| cargo test --release -- --test-threads=1 | |
| - name: Push tag | |
| 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: | | |
| # First publish the derive crate | |
| echo "Publishing gonfig_derive crate..." | |
| cd gonfig_derive | |
| cargo publish | |
| cd .. | |
| # Wait a moment for the derive crate to be available | |
| echo "Waiting for derive crate to be available..." | |
| sleep 30 | |
| # Then publish the main crate | |
| echo "Publishing main gonfig crate..." | |
| cargo publish | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| - name: Create GitHub Release | |
| run: | | |
| # Check if release already exists | |
| if gh release view "v${{ env.new_version }}" >/dev/null 2>&1; then | |
| echo "Release v${{ env.new_version }} already exists, skipping release creation" | |
| else | |
| echo "Creating new release v${{ env.new_version }}" | |
| gh release create "v${{ env.new_version }}" \ | |
| --title "Release v${{ env.new_version }}" \ | |
| --notes "## Changes in this release | |
| This release was automatically created from PR #${{ github.event.pull_request.number }} | |
| **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 | |
| ${{ 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] | |
| gonfig = \"${{ env.new_version }}\" | |
| \`\`\`" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update main branch with new version | |
| run: | | |
| # Switch back to main and merge the version changes | |
| git checkout main | |
| git merge "release/v${{ env.new_version }}" --no-ff -m "Release v${{ env.new_version }}" | |
| git push origin main | |
| # Clean up the release branch | |
| git branch -D "release/v${{ env.new_version }}" |