-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (154 loc) · 6.54 KB
/
Copy pathversion-bump.yml
File metadata and controls
185 lines (154 loc) · 6.54 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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 }}"