Skip to content

Merge pull request #7 from itsparser/fix/workflow-permissions #7

Merge pull request #7 from itsparser/fix/workflow-permissions

Merge pull request #7 from itsparser/fix/workflow-permissions #7

Workflow file for this run

name: Version Bump on PR Merge

Check failure on line 1 in .github/workflows/version-bump.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/version-bump.yml

Invalid workflow file

(Line: 112, Col: 17): Unexpected symbol: '|'. Located at position 38 within expression: steps.version_type.outputs.bump_type | upper
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 "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"
- 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: |
git checkout -b "release/v${{ env.new_version }}"
git add Cargo.toml Cargo.lock
git commit -m "Release v${{ env.new_version }}"
git tag "v${{ env.new_version }}"
- 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: |
cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.new_version }}
release_name: Release v${{ env.new_version }}
body: |
## 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 }}"
```
draft: false
prerelease: false
- name: Create version update PR
run: |
git push origin "release/v${{ env.new_version }}"
gh pr create --title "Update version to v${{ env.new_version }}" \
--body "Automated version update following release v${{ env.new_version }}" \
--base main \
--head "release/v${{ env.new_version }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}