-
Notifications
You must be signed in to change notification settings - Fork 56
165 lines (138 loc) Β· 5.42 KB
/
release.yml
File metadata and controls
165 lines (138 loc) Β· 5.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
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
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-(pre|preview).[0-9]+'
permissions:
contents: write
jobs:
verify-tag:
name: Verify Tag
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
is_prerelease: ${{ steps.check.outputs.is_prerelease }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check tag type and branch
id: check
run: |
git fetch origin main master dev || true
TAG="${{ github.ref_name }}"
BRANCHES=$(git branch -r --contains ${{ github.ref }})
echo "Tag: $TAG"
echo "Branches containing this tag: $BRANCHES"
# Check if it's a prerelease tag
if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-(pre|preview)\.[0-9]+$ ]]; then
echo "π¦ Detected prerelease tag"
echo "is_prerelease=true" >> $GITHUB_OUTPUT
if echo "$BRANCHES" | grep -q 'origin/dev'; then
echo "β Prerelease tag is on dev branch"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "β Prerelease tag must be on dev branch, skipping release"
echo "should_release=false" >> $GITHUB_OUTPUT
fi
elif [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "π¦ Detected stable release tag"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
if echo "$BRANCHES" | grep -qE 'origin/(main|master)'; then
echo "β Stable release tag is on main or master branch"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "β Stable release tag must be on main or master branch, skipping release"
echo "should_release=false" >> $GITHUB_OUTPUT
fi
else
echo "β Unknown tag format, skipping release"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "should_release=false" >> $GITHUB_OUTPUT
fi
- name: Verify version consistency
if: steps.check.outputs.should_release == 'true'
run: |
# Extract version from git tag (remove 'v' prefix)
TAG_VERSION="${{ github.ref_name }}"
TAG_VERSION="${TAG_VERSION#v}"
# Extract version from Cargo.toml
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
echo "Git tag version: $TAG_VERSION"
echo "Cargo.toml version: $CARGO_VERSION"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
echo "β Version check passed!"
check:
uses: ./.github/workflows/check.yml
needs: verify-tag
if: needs.verify-tag.outputs.should_release == 'true'
test-board:
uses: ./.github/workflows/test-board.yml
needs: verify-tag
if: needs.verify-tag.outputs.should_release == 'true'
test-qemu:
uses: ./.github/workflows/test-qemu.yml
needs: verify-tag
if: needs.verify-tag.outputs.should_release == 'true'
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [verify-tag, check, test-board, test-qemu]
if: needs.verify-tag.outputs.should_release == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate release notes
id: release_notes
run: |
CURRENT_TAG="${{ github.ref_name }}"
# Get previous tag
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "^${CURRENT_TAG}$" | tail -n1)
if [ -z "$PREVIOUS_TAG" ] || [ "$PREVIOUS_TAG" == "$CURRENT_TAG" ]; then
echo "No previous tag found, this is the first release"
CHANGELOG="Initial release"
else
echo "Generating changelog from $PREVIOUS_TAG to $CURRENT_TAG"
# Generate changelog with commit messages
CHANGELOG=$(git log --pretty=format:"- %s (%h)" "${PREVIOUS_TAG}..${CURRENT_TAG}")
if [ -z "$CHANGELOG" ]; then
CHANGELOG="No changes"
fi
fi
# Write changelog to output file (multi-line)
{
echo "changelog<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: ${{ needs.verify-tag.outputs.is_prerelease == 'true' }}
body: |
## Changes
${{ steps.release_notes.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [verify-tag, check, test-board, test-qemu]
if: needs.verify-tag.outputs.should_release == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Dry run publish
run: cargo publish --dry-run
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}