Skip to content

Commit 2529836

Browse files
committed
do it ourselves
1 parent 55a3df2 commit 2529836

File tree

1 file changed

+195
-8
lines changed

1 file changed

+195
-8
lines changed

.github/workflows/rust-release.yml

Lines changed: 195 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,214 @@ jobs:
110110
- uses: actions/checkout@v4
111111
with:
112112
fetch-depth: 0
113-
- name: Install release tools
113+
- name: Install git-cliff
114114
uses: taiki-e/install-action@v2
115115
with:
116-
tool: release-plz, git-cliff
117-
- name: Run release-plz
116+
tool: git-cliff
117+
- name: Determine next version from conventional commits
118+
id: next_version
119+
working-directory: ./rust/main
120+
env:
121+
CURRENT_VERSION: ${{ needs.check-release-status.outputs.current_version }}
122+
run: |
123+
# Get commits since last release
124+
LATEST_TAG=$(git tag -l "agents-v*" --sort=-version:refname | grep -E "^agents-v[0-9]+\.[0-9]+\.[0-9]+$" | head -1)
125+
126+
if [ -z "$LATEST_TAG" ]; then
127+
COMMITS=$(git log --oneline --no-merges -- .)
128+
else
129+
COMMITS=$(git log "${LATEST_TAG}..HEAD" --oneline --no-merges -- .)
130+
fi
131+
132+
# Parse current version
133+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
134+
135+
# Analyze commits for conventional commit types
136+
HAS_BREAKING=false
137+
HAS_FEAT=false
138+
HAS_FIX=false
139+
140+
while IFS= read -r commit; do
141+
if echo "$commit" | grep -qE "^[a-f0-9]+ [a-z]+(\(.+\))?!:"; then
142+
HAS_BREAKING=true
143+
elif echo "$commit" | grep -qE "^[a-f0-9]+ feat(\(.+\))?:"; then
144+
HAS_FEAT=true
145+
elif echo "$commit" | grep -qE "^[a-f0-9]+ fix(\(.+\))?:"; then
146+
HAS_FIX=true
147+
fi
148+
149+
# Check commit body for BREAKING CHANGE
150+
COMMIT_HASH=$(echo "$commit" | cut -d' ' -f1)
151+
if git show -s --format=%B "$COMMIT_HASH" | grep -q "BREAKING CHANGE:"; then
152+
HAS_BREAKING=true
153+
fi
154+
done <<< "$COMMITS"
155+
156+
# Determine version bump
157+
if [ "$HAS_BREAKING" = true ]; then
158+
MAJOR=$((MAJOR + 1))
159+
MINOR=0
160+
PATCH=0
161+
BUMP_TYPE="major"
162+
elif [ "$HAS_FEAT" = true ]; then
163+
MINOR=$((MINOR + 1))
164+
PATCH=0
165+
BUMP_TYPE="minor"
166+
elif [ "$HAS_FIX" = true ]; then
167+
PATCH=$((PATCH + 1))
168+
BUMP_TYPE="patch"
169+
else
170+
# Default to patch for any other changes
171+
PATCH=$((PATCH + 1))
172+
BUMP_TYPE="patch"
173+
fi
174+
175+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
176+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
177+
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
178+
echo "Next version: $NEW_VERSION ($BUMP_TYPE bump from $CURRENT_VERSION)"
179+
- name: Generate changelog
180+
id: changelog
181+
working-directory: ./rust/main
182+
env:
183+
NEW_VERSION: ${{ steps.next_version.outputs.new_version }}
184+
run: |
185+
# Generate changelog for commits since last release
186+
LATEST_TAG=$(git tag -l "agents-v*" --sort=-version:refname | grep -E "^agents-v[0-9]+\.[0-9]+\.[0-9]+$" | head -1)
187+
188+
if [ -z "$LATEST_TAG" ]; then
189+
CHANGELOG=$(git-cliff --config cliff.toml --unreleased --strip all)
190+
else
191+
CHANGELOG=$(git-cliff --config cliff.toml "${LATEST_TAG}..HEAD" --strip all)
192+
fi
193+
194+
# Save changelog to file for PR body
195+
echo "$CHANGELOG" > /tmp/changelog.md
196+
197+
# Also output for GitHub Actions
198+
{
199+
echo 'changelog<<EOF'
200+
echo "$CHANGELOG"
201+
echo 'EOF'
202+
} >> $GITHUB_OUTPUT
203+
- name: Update Cargo.toml version
204+
working-directory: ./rust/main
205+
env:
206+
NEW_VERSION: ${{ steps.next_version.outputs.new_version }}
207+
run: |
208+
# Update workspace version
209+
sed -i.bak "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
210+
rm Cargo.toml.bak
211+
212+
echo "Updated Cargo.toml to version $NEW_VERSION"
213+
git diff Cargo.toml
214+
- name: Update CHANGELOG
118215
working-directory: ./rust/main
216+
env:
217+
NEW_VERSION: ${{ steps.next_version.outputs.new_version }}
218+
run: |
219+
# Prepend new version to CHANGELOG.md
220+
if [ -f CHANGELOG.md ]; then
221+
CURRENT_CHANGELOG=$(cat CHANGELOG.md)
222+
else
223+
CURRENT_CHANGELOG=""
224+
fi
225+
226+
cat > CHANGELOG.md <<EOF
227+
# Changelog
228+
229+
## [$NEW_VERSION] - $(date +%Y-%m-%d)
230+
231+
$(cat /tmp/changelog.md)
232+
233+
$CURRENT_CHANGELOG
234+
EOF
235+
236+
echo "Updated CHANGELOG.md"
237+
- name: Create or update release PR
119238
env:
120239
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
240+
NEW_VERSION: ${{ steps.next_version.outputs.new_version }}
241+
BUMP_TYPE: ${{ steps.next_version.outputs.bump_type }}
242+
CHANGELOG: ${{ steps.changelog.outputs.changelog }}
121243
run: |
122244
git config user.name "github-actions[bot]"
123245
git config user.email "github-actions[bot]@users.noreply.github.com"
124246
125-
# Run release-plz to create/update the release PR
126-
# It will automatically generate changelog and update Cargo.toml versions
127-
release-plz release-pr --git-token "$GITHUB_TOKEN"
247+
BRANCH_NAME="release-agents-v${NEW_VERSION}"
248+
249+
# Check if release PR branch already exists
250+
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
251+
echo "Branch $BRANCH_NAME already exists, updating it"
252+
git fetch origin "$BRANCH_NAME"
253+
git checkout "$BRANCH_NAME"
254+
git reset --hard origin/main
255+
else
256+
echo "Creating new branch $BRANCH_NAME"
257+
git checkout -b "$BRANCH_NAME"
258+
fi
259+
260+
# Stage changes
261+
git add rust/main/Cargo.toml rust/main/CHANGELOG.md
262+
263+
# Commit if there are changes
264+
if git diff --staged --quiet; then
265+
echo "No changes to commit"
266+
else
267+
git commit -m "chore(release): prepare agents v${NEW_VERSION}
268+
269+
This is a $BUMP_TYPE version bump for the Hyperlane agents.
270+
271+
Changes will be released as agents-v${NEW_VERSION} after this PR is merged."
272+
273+
git push -f origin "$BRANCH_NAME"
274+
fi
275+
276+
# Create or update PR
277+
PR_BODY="## Release agents v${NEW_VERSION}
278+
279+
This PR prepares the release of Hyperlane agents version **${NEW_VERSION}** (${BUMP_TYPE} bump).
280+
281+
### What's Changed
282+
283+
${CHANGELOG}
284+
285+
---
286+
287+
Once this PR is merged, the [\`rust-release.yml\`](https://github.com/${{ github.repository }}/blob/main/.github/workflows/rust-release.yml) workflow will automatically:
288+
- Create a GitHub release with tag \`agents-v${NEW_VERSION}\`
289+
- Trigger the build of release binaries
290+
291+
🤖 This PR was automatically created by the release workflow."
292+
293+
# Check if PR already exists
294+
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number' 2>/dev/null || echo "")
295+
296+
if [ -n "$EXISTING_PR" ]; then
297+
echo "Updating existing PR #$EXISTING_PR"
298+
gh pr edit "$EXISTING_PR" \
299+
--title "chore(release): agents v${NEW_VERSION}" \
300+
--body "$PR_BODY"
301+
echo "Updated PR: $(gh pr view $EXISTING_PR --json url --jq .url)"
302+
else
303+
echo "Creating new PR"
304+
gh pr create \
305+
--title "chore(release): agents v${NEW_VERSION}" \
306+
--body "$PR_BODY" \
307+
--base main \
308+
--head "$BRANCH_NAME" \
309+
--label "release"
310+
PR_URL=$(gh pr list --head "$BRANCH_NAME" --json url --jq '.[0].url')
311+
echo "Created PR: $PR_URL"
312+
fi
128313
- name: Summary
129314
if: always()
315+
env:
316+
NEW_VERSION: ${{ steps.next_version.outputs.new_version }}
130317
run: |
131-
echo "Release PR workflow completed" >> $GITHUB_STEP_SUMMARY
318+
echo "### Release PR for agents v${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY
132319
echo "" >> $GITHUB_STEP_SUMMARY
133-
echo "If a release PR was created, it will appear in the Pull Requests tab." >> $GITHUB_STEP_SUMMARY
320+
echo "The release PR has been created/updated." >> $GITHUB_STEP_SUMMARY
134321
echo "Once merged, the release will be published automatically." >> $GITHUB_STEP_SUMMARY
135322
136323
publish:

0 commit comments

Comments
 (0)