-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (118 loc) · 4.9 KB
/
Copy pathversion-bump.yml
File metadata and controls
141 lines (118 loc) · 4.9 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
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 "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 }}