Repository navigation
187 lines (165 loc) · 6.29 KB
/
Copy pathprepare-release.yml
File metadata and controls
187 lines (165 loc) · 6.29 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
186
187
name: Prepare release
"on":
workflow_dispatch:
inputs:
version:
description: "Release version (for example 0.13.11); defaults to the next patch version"
required: false
type: string
concurrency:
group: prepare-release
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
jobs:
prepare-release:
name: Prepare release PR
if: github.ref_name == github.event.repository.default_branch
runs-on: blacksmith-32vcpu-ubuntu-2404
env:
HOST_CARGO_JOBS: "8"
# Releases are always cut from master, regardless of the default branch.
RELEASE_BASE_BRANCH: master
steps:
- name: Checkout release base branch
uses: actions/checkout@v5
with:
path: magicblock-validator
ref: ${{ env.RELEASE_BASE_BRANCH }}
fetch-depth: 0
persist-credentials: false
- uses: ./magicblock-validator/.github/actions/setup-build-env
with:
build_cache_key_name: "magicblock-validator-prepare-release-v001"
rust_toolchain_release: "1.94.1"
- name: Determine release version
working-directory: magicblock-validator
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
current_version="$(
awk '
$0 == "[workspace.package]" { in_section = 1; next }
in_section && /^\[/ { exit }
in_section && /^version = "/ {
value = $0
sub(/^version = "/, "", value)
sub(/"$/, "", value)
print value
exit
}
' Cargo.toml
)"
if [[ ! "$current_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Invalid current workspace version: $current_version" >&2
exit 1
fi
current_major=$((10#${BASH_REMATCH[1]}))
current_minor=$((10#${BASH_REMATCH[2]}))
current_patch=$((10#${BASH_REMATCH[3]}))
if [[ -z "$INPUT_VERSION" ]]; then
version="${current_major}.${current_minor}.$((current_patch + 1))"
else
requested_version="${INPUT_VERSION#v}"
if [[ ! "$requested_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Version must have the form X.Y.Z or vX.Y.Z" >&2
exit 1
fi
new_major=$((10#${BASH_REMATCH[1]}))
new_minor=$((10#${BASH_REMATCH[2]}))
new_patch=$((10#${BASH_REMATCH[3]}))
if (( new_major < current_major ||
(new_major == current_major && new_minor < current_minor) ||
(new_major == current_major && new_minor == current_minor && new_patch <= current_patch) )); then
echo "Version must be newer than $current_version" >&2
exit 1
fi
version="${new_major}.${new_minor}.${new_patch}"
fi
release_branch="release/v${version}"
remote_branch="$(git ls-remote --heads origin "refs/heads/${release_branch}")"
if [[ -n "$remote_branch" ]]; then
echo "Branch $release_branch already exists" >&2
exit 1
fi
remote_tag="$(git ls-remote --tags origin "refs/tags/v${version}")"
if [[ -n "$remote_tag" ]]; then
echo "Tag v${version} already exists" >&2
exit 1
fi
git switch --create "$release_branch"
{
echo "CURRENT_VERSION=$current_version"
echo "VERSION=$version"
echo "RELEASE_BRANCH=$release_branch"
} >> "$GITHUB_ENV"
echo "Preparing v${version} from v${current_version} (base: ${RELEASE_BASE_BRANCH})" >> "$GITHUB_STEP_SUMMARY"
- name: Set workspace version
working-directory: magicblock-validator
shell: bash
run: |
set -euo pipefail
awk -v version="$VERSION" '
BEGIN { in_section = 0; updated = 0 }
$0 == "[workspace.package]" {
in_section = 1
print
next
}
in_section && /^\[/ { in_section = 0 }
in_section && /^version = "/ {
print "version = \"" version "\""
updated++
next
}
{ print }
END { if (updated != 1) exit 1 }
' Cargo.toml > Cargo.toml.tmp
mv Cargo.toml.tmp Cargo.toml
- name: Align package versions
working-directory: magicblock-validator/.github
shell: bash
run: ./version-align.sh
- name: Build project and integration tests
working-directory: magicblock-validator
shell: bash
run: |
set -euo pipefail
cargo build --workspace --jobs "$HOST_CARGO_JOBS"
cargo build --workspace --manifest-path test-integration/Cargo.toml --jobs "$HOST_CARGO_JOBS"
# Full dependency resolution so --locked actually validates the
# lockfiles (--no-deps skips resolution and never trips --locked).
cargo metadata --locked --format-version 1 >/dev/null
cargo metadata --manifest-path test-integration/Cargo.toml --locked --format-version 1 >/dev/null
- name: Commit and push release branch
working-directory: magicblock-validator
shell: bash
env:
GH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
run: |
set -euo pipefail
git diff --check
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add --all
if git diff --cached --quiet; then
echo "No release changes were generated" >&2
exit 1
fi
git commit -m "chore(release): prepare v${VERSION}"
gh auth setup-git
git push --set-upstream origin "$RELEASE_BRANCH"
- name: Create pull request
working-directory: magicblock-validator
shell: bash
env:
GH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
run: |
gh pr create \
--base "$RELEASE_BASE_BRANCH" \
--head "$RELEASE_BRANCH" \
--title "chore(release): prepare v${VERSION}" \
--body ""