-
Notifications
You must be signed in to change notification settings - Fork 30
114 lines (94 loc) · 3.42 KB
/
Copy pathbump-version.yml
File metadata and controls
114 lines (94 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Bump Version
on:
workflow_dispatch:
inputs:
bump_type:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
env:
CARGO_TERM_COLOR: always
jobs:
bump-version:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Read current version and calculate new version
id: version
run: |
# Read current version from Cargo.toml
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Current version: $CURRENT_VERSION"
# Split version into parts
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Bump version based on input
case "${{ github.event.inputs.bump_type }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "New version: $NEW_VERSION"
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create branch
run: |
BRANCH_NAME="re/bump-for-${{ steps.version.outputs.new }}"
echo "Creating branch: $BRANCH_NAME"
git checkout -b "$BRANCH_NAME"
echo "branch=$BRANCH_NAME" >> $GITHUB_ENV
- name: Update Cargo.toml version
run: |
sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.new }}"/' Cargo.toml
echo "Updated Cargo.toml to version ${{ steps.version.outputs.new }}"
- name: Run cargo check to update Cargo.lock
run: cargo check
- name: Commit and push changes
run: |
git add Cargo.toml Cargo.lock
git commit -m "Bump version to ${{ steps.version.outputs.new }}"
git push origin "${{ env.branch }}"
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.PAT_RELEASE_ENGINEER }}
run: |
gh pr create \
--title "Release: Bump version to ${{ steps.version.outputs.new }}" \
--assignee "${{ github.actor }}" \
--body "This PR bumps the version from ${{ steps.version.outputs.current }} to ${{ steps.version.outputs.new }}.
**Bump type:** ${{ github.event.inputs.bump_type }}
After merging this PR, a tag \`v${{ steps.version.outputs.new }}\` will be automatically created and pushed, which will trigger the release workflow.
If you want to prevent automatic tagging, add the \`no-auto-tag\` label to this PR before merging." \
--base main \
--head "${{ env.branch }}"