-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (121 loc) · 4.32 KB
/
release.yml
File metadata and controls
142 lines (121 loc) · 4.32 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
name: Release
on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
env:
CARGO_TERM_COLOR: always
jobs:
prepare-release:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Calculate new version
id: version
run: |
CURRENT=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "${{ inputs.bump }}" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
NEW="${MAJOR}.${MINOR}.${PATCH}"
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "new=$NEW" >> "$GITHUB_OUTPUT"
echo "Bumping $CURRENT -> $NEW"
- uses: dtolnay/rust-toolchain@stable
- name: Update Cargo.toml version
run: |
sed -i "s/^version = \"${{ steps.version.outputs.current }}\"/version = \"${{ steps.version.outputs.new }}\"/" Cargo.toml
cargo update --workspace
- name: Generate changelog entry
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.new }}"
DATE=$(date +%Y-%m-%d)
PREVIOUS_TAG=$(git tag -l "v*" --sort=-v:refname | head -1)
if [ -n "$PREVIOUS_TAG" ]; then
NOTES=$(gh api repos/${{ github.repository }}/releases/generate-notes \
-f tag_name="v${VERSION}" \
-f target_commitish=main \
-f previous_tag_name="$PREVIOUS_TAG" \
--jq '.body')
else
NOTES="- Initial release"
fi
{
echo "## [${VERSION}] - ${DATE}"
echo ""
echo "$NOTES"
echo ""
} > /tmp/changelog-entry.md
- name: Update changelog
run: |
{
head -n 4 CHANGELOG.md
cat /tmp/changelog-entry.md
echo ""
tail -n +5 CHANGELOG.md
} > CHANGELOG.tmp && mv CHANGELOG.tmp CHANGELOG.md
- name: Create release PR
uses: peter-evans/create-pull-request@v8
with:
branch: release/v${{ steps.version.outputs.new }}
commit-message: "release: v${{ steps.version.outputs.new }}"
title: "release: v${{ steps.version.outputs.new }}"
body: "Bumps version from ${{ steps.version.outputs.current }} to ${{ steps.version.outputs.new }}."
labels: release
publish:
if: >-
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Get version and publish
env:
GH_TOKEN: ${{ github.token }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
TAG="v${VERSION}"
# Extract changelog entry for this version
NOTES=$(sed -n "/^## \[${VERSION}\]/,/^## \[/{ /^## \[${VERSION}\]/p; /^## \[${VERSION}\]/!{ /^## \[/!p; } }" CHANGELOG.md)
# Tag and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$TAG"
git push origin "$TAG"
# Update major version tag (e.g., v1) for action consumers
MAJOR_TAG="v$(echo "$VERSION" | cut -d. -f1)"
git tag -f "$MAJOR_TAG"
git push origin "$MAJOR_TAG" -f
# Publish to crates.io
cargo publish
# Create GitHub release with changelog as notes
echo "$NOTES" > /tmp/release-notes.md
gh release create "$TAG" \
--title "v${VERSION}" \
--notes-file /tmp/release-notes.md