-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreate-threshold-release-proposal.yml
More file actions
191 lines (168 loc) · 7.29 KB
/
Copy pathcreate-threshold-release-proposal.yml
File metadata and controls
191 lines (168 loc) · 7.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
188
189
190
191
name: Create Threshold Release Proposal
env:
CARGO_TERM_COLOR: always
on:
workflow_dispatch:
inputs:
target_branch:
description: 'Target branch for the PR (default: master)'
required: false
type: string
default: 'master'
version_type:
description: 'Type of version bump (major, minor, patch) or specify custom version'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
- custom
custom_version:
description: 'Custom version string (e.g., v1.0.1). Only used if version_type is "custom". MUST start with "v"'
required: false
is_draft:
description: 'Is this a draft release?'
required: true
type: boolean
default: false
# Default to read-only; the version-bump job overrides with `contents: write`
# (it pushes a release branch and uses ADMIN_PAT for `gh pr create`).
permissions:
contents: read
jobs:
calculate-next-version:
name: 🧮 Calculate Next Threshold Version
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.versioner.outputs.new_version }}
commit_sha_short: ${{ steps.vars.outputs.commit_sha_short }}
source_branch: ${{ steps.vars.outputs.source_branch }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- name: Get current branch and commit SHA
id: vars
run: |
echo "commit_sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "source_branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
- name: Get latest threshold tag
id: latest_tag
run: |
# Get all threshold version tags and sort them by version
latest_semver_tag=$(git tag -l "threshold-v[0-9]*.[0-9]*.[0-9]*" | sort -V | tail -n 1)
# If no tags found, read current version from threshold/Cargo.toml
if [ -z "$latest_semver_tag" ]; then
cargo_version=$(grep -m1 '^version' threshold/Cargo.toml | sed 's/version = "\(.*\)"/\1/')
if [ -z "$cargo_version" ]; then
echo "Error: No threshold tags found and could not read version from threshold/Cargo.toml"
exit 1
fi
# Use the Cargo.toml version as the base for incrementing.
# With Cargo.toml at 1.0.0, the first patch release will be 1.0.1 (version 1.0.0 is never tagged/published)
latest_semver_tag="threshold-v$cargo_version"
echo "No existing threshold tags found. Using version from threshold/Cargo.toml: $latest_semver_tag"
echo "Note: The first release will increment from this version."
fi
echo "latest_tag_found=$latest_semver_tag" >> $GITHUB_OUTPUT
echo "Latest threshold semantic version tag found: $latest_semver_tag"
- name: Calculate new version
id: versioner
env:
LATEST_TAG: ${{ steps.latest_tag.outputs.latest_tag_found }}
VERSION_TYPE: ${{ github.event.inputs.version_type }}
CUSTOM_VERSION: ${{ github.event.inputs.custom_version }}
run: |
# Remove 'threshold-v' prefix for processing
current_version=${LATEST_TAG#threshold-v}
if [[ "$VERSION_TYPE" == "custom" ]]; then
if [[ -z "$CUSTOM_VERSION" ]]; then
echo "Error: Custom version is selected but no custom_version string provided."
exit 1
fi
if [[ ! "$CUSTOM_VERSION" =~ ^v ]]; then
echo "Error: Custom version string MUST start with 'v' (e.g., v1.2.3)."
exit 1
fi
new_version="threshold-$CUSTOM_VERSION"
else
# Split version into parts
IFS='.' read -r major minor patch <<< "$current_version"
# Increment based on type
if [[ "$VERSION_TYPE" == "major" ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ "$VERSION_TYPE" == "minor" ]]; then
minor=$((minor + 1))
patch=0
elif [[ "$VERSION_TYPE" == "patch" ]]; then
patch=$((patch + 1))
else
echo "Error: Invalid version_type: $VERSION_TYPE"
exit 1
fi
new_version="threshold-v$major.$minor.$patch"
fi
echo "New threshold version: $new_version"
echo "new_version=$new_version" >> $GITHUB_OUTPUT
update-threshold-version:
name: 📝 Update Threshold Version
needs: calculate-next-version
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Create version bump branch and PR
env:
NEW_VERSION: ${{ needs.calculate-next-version.outputs.new_version }}
GITHUB_TOKEN: ${{ secrets.ADMIN_PAT }}
SOURCE_BRANCH: ${{ needs.calculate-next-version.outputs.source_branch }}
TARGET_BRANCH: ${{ github.event.inputs.target_branch }}
GIT_USER_NAME: ${{ github.actor }}
GIT_USER_EMAIL: ${{ github.actor }}@users.noreply.github.com
IS_DRAFT: ${{ github.event.inputs.is_draft }}
VERSION_TYPE: ${{ github.event.inputs.version_type }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
set -ex
# Extract version without threshold- prefix
new_cargo_version=${NEW_VERSION#threshold-v}
branch_name="release/${NEW_VERSION}"
# Create new branch from source branch
git checkout "$SOURCE_BRANCH"
git checkout -b "$branch_name"
# Update threshold version
echo "Updating threshold/Cargo.toml to version: $new_cargo_version"
sed -i -E "s/^version\s*=\s*\"[0-9a-zA-Z.-]+\"/version = \"$new_cargo_version\"/" threshold/Cargo.toml
# Update workspace dependency in main Cargo.toml
echo "Updating threshold workspace dependency in main Cargo.toml"
sed -i "/qp-rusty-crystals-threshold/s/version = \"[^\"]*\"/version = \"$new_cargo_version\"/" Cargo.toml
# Update Cargo.lock
cargo update --package qp-rusty-crystals-threshold
# Commit changes
git config user.name "$GIT_USER_NAME"
git config user.email "$GIT_USER_EMAIL"
git add Cargo.toml threshold/Cargo.toml Cargo.lock
git commit -m "ci: Automate threshold version bump to $NEW_VERSION"
git push origin "$branch_name"
PR_TITLE="ci: Automate threshold version bump to $NEW_VERSION"
# Prepare labels
PR_LABELS="automated,threshold-release-proposal"
if [[ "$IS_DRAFT" == "true" ]]; then
PR_LABELS="$PR_LABELS,draft-release"
fi
gh pr create \
--title "$PR_TITLE" \
--body "$(printf "Automated threshold version bump for release %s.\\n\\nTriggered by workflow run: %s\\n\\nType: %s" "$NEW_VERSION" "$WORKFLOW_URL" "$VERSION_TYPE")" \
--base "$TARGET_BRANCH" \
--head "$branch_name" \
--label "$PR_LABELS"