|
| 1 | +name: Bump & Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: "Version bump type" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + bump-and-tag: |
| 20 | + runs-on: ubuntu-22.04 |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + - name: Compute new version |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + CURRENT=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/') |
| 30 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" |
| 31 | + case "${{ inputs.bump }}" in |
| 32 | + major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; |
| 33 | + minor) MINOR=$((MINOR + 1)); PATCH=0 ;; |
| 34 | + patch) PATCH=$((PATCH + 1)) ;; |
| 35 | + esac |
| 36 | + NEW="${MAJOR}.${MINOR}.${PATCH}" |
| 37 | + echo "current=$CURRENT" >> "$GITHUB_OUTPUT" |
| 38 | + echo "new=$NEW" >> "$GITHUB_OUTPUT" |
| 39 | + echo "Bumping $CURRENT -> $NEW" |
| 40 | +
|
| 41 | + - name: Bump Cargo.toml |
| 42 | + run: sed -i "0,/^version = \".*\"/s//version = \"${{ steps.version.outputs.new }}\"/" Cargo.toml |
| 43 | + |
| 44 | + - name: Update Cargo.lock |
| 45 | + run: cargo generate-lockfile |
| 46 | + |
| 47 | + - name: Commit, tag, and push |
| 48 | + run: | |
| 49 | + git config user.name "github-actions[bot]" |
| 50 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | + git add Cargo.toml Cargo.lock |
| 52 | + git commit -m "chore: release v${{ steps.version.outputs.new }}" |
| 53 | + git tag "v${{ steps.version.outputs.new }}" |
| 54 | + git push origin main --tags |
0 commit comments