Skip to content

Commit 729ff6d

Browse files
committed
test
1 parent a1b8274 commit 729ff6d

1 file changed

Lines changed: 226 additions & 0 deletions

File tree

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
name: Test — Prepare Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to test against'
8+
required: true
9+
default: 'feature/release-process'
10+
version:
11+
description: 'Version to test (e.g. 0.58.0 or 0.58.0rc1) — leave blank for auto minor bump'
12+
required: false
13+
default: ''
14+
pull_request:
15+
paths:
16+
- '.github/workflows/prepare-release.yaml'
17+
- '.github/workflows/test-prepare-release.yaml'
18+
- '.github/scripts/check_prerelease.py'
19+
- '.github/scripts/validate_version_input.py'
20+
21+
jobs:
22+
test-prepare-release:
23+
name: Test prepare-release logic (dry run)
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write
27+
pull-requests: write
28+
29+
steps:
30+
- name: Checkout branch
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.inputs.branch || github.head_ref }}
34+
fetch-depth: 0
35+
36+
- name: Compute version and generate release notes
37+
id: release
38+
env:
39+
VERSION_INPUT: ${{ github.event.inputs.version }}
40+
run: |
41+
pip install packaging -q
42+
43+
CURRENT_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
44+
echo "Current version: $CURRENT_VERSION"
45+
46+
if [[ -n "$VERSION_INPUT" ]]; then
47+
python3 .github/scripts/validate_version_input.py
48+
python3 .github/scripts/check_version_bump.py "$CURRENT_VERSION" "$VERSION_INPUT"
49+
NEW_VERSION="$VERSION_INPUT"
50+
else
51+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
52+
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
53+
fi
54+
55+
TAG="v${NEW_VERSION}"
56+
echo "Version: $CURRENT_VERSION → $NEW_VERSION"
57+
58+
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$' | head -1)
59+
if [[ -z "$LATEST_TAG" ]]; then
60+
echo "No semver tag found — using initial commit as baseline."
61+
BASELINE=$(git rev-list --max-parents=0 HEAD)
62+
else
63+
BASELINE="$LATEST_TAG"
64+
fi
65+
66+
LOG=$(git log "$BASELINE"..HEAD --pretty=format:"%H %s" --reverse)
67+
68+
if [[ -z "$LOG" ]]; then
69+
echo "ERROR: No commits since $BASELINE. Nothing to release."
70+
exit 1
71+
fi
72+
73+
echo "Commits since $BASELINE:"
74+
echo "$LOG"
75+
76+
FEATURES=""
77+
FIXES=""
78+
IMPROVEMENTS=""
79+
BREAKING=""
80+
81+
while IFS= read -r line; do
82+
SHA="${line%% *}"
83+
SHORT_SHA="${SHA:0:7}"
84+
SUBJECT="${line#* }"
85+
86+
if echo "$SUBJECT" | grep -qE '(\w+)(\(.+\))?!:|BREAKING CHANGE'; then
87+
SCOPE=$(echo "$SUBJECT" | sed -E 's/^[a-z]+\(([^)]+)\)!:.*/\1/' | sed -E 's/^[a-z]+!:.*//')
88+
DESC=$(echo "$SUBJECT" | sed -E 's/^[a-z]+(\([^)]+\))?!: //')
89+
if [[ -n "$SCOPE" ]]; then
90+
BREAKING+="- **[$SCOPE]**: $DESC (commit $SHORT_SHA)"$'\n'
91+
else
92+
BREAKING+="- $DESC (commit $SHORT_SHA)"$'\n'
93+
fi
94+
elif echo "$SUBJECT" | grep -qE '^feat(\(.+\))?:'; then
95+
SCOPE=$(echo "$SUBJECT" | sed -E 's/^feat\(([^)]+)\):.*/\1/')
96+
DESC=$(echo "$SUBJECT" | sed -E 's/^feat(\([^)]+\))?: //')
97+
if [[ "$SCOPE" != "$SUBJECT" ]]; then
98+
FEATURES+="- **[$SCOPE]**: $DESC (commit $SHORT_SHA)"$'\n'
99+
else
100+
FEATURES+="- $DESC (commit $SHORT_SHA)"$'\n'
101+
fi
102+
elif echo "$SUBJECT" | grep -qE '^fix(\(.+\))?:'; then
103+
SCOPE=$(echo "$SUBJECT" | sed -E 's/^fix\(([^)]+)\):.*/\1/')
104+
DESC=$(echo "$SUBJECT" | sed -E 's/^fix(\([^)]+\))?: //')
105+
if [[ "$SCOPE" != "$SUBJECT" ]]; then
106+
FIXES+="- **[$SCOPE]**: $DESC (commit $SHORT_SHA)"$'\n'
107+
else
108+
FIXES+="- $DESC (commit $SHORT_SHA)"$'\n'
109+
fi
110+
elif echo "$SUBJECT" | grep -qE '^(refactor|perf|chore|docs|test|ci|style|build|revert)(\(.+\))?:'; then
111+
SCOPE=$(echo "$SUBJECT" | sed -E 's/^[a-z]+\(([^)]+)\):.*/\1/')
112+
DESC=$(echo "$SUBJECT" | sed -E 's/^[a-z]+(\([^)]+\))?: //')
113+
if [[ "$SCOPE" != "$SUBJECT" ]]; then
114+
IMPROVEMENTS+="- **[$SCOPE]**: $DESC (commit $SHORT_SHA)"$'\n'
115+
else
116+
IMPROVEMENTS+="- $DESC (commit $SHORT_SHA)"$'\n'
117+
fi
118+
fi
119+
done <<< "$LOG"
120+
121+
NOTES=""
122+
if [[ -n "$BREAKING" ]]; then
123+
NOTES+="### Breaking Changes"$'\n'
124+
NOTES+="> ⚠️ **Important**: Review migration steps before upgrading from \`$BASELINE\`."$'\n'
125+
NOTES+="$BREAKING"$'\n'
126+
fi
127+
if [[ -n "$FEATURES" ]]; then
128+
NOTES+="### What's New"$'\n'
129+
NOTES+="$FEATURES"$'\n'
130+
fi
131+
if [[ -n "$FIXES" ]]; then
132+
NOTES+="### Bug Fixes"$'\n'
133+
NOTES+="$FIXES"$'\n'
134+
fi
135+
if [[ -n "$IMPROVEMENTS" ]]; then
136+
NOTES+="### Improvements"$'\n'
137+
NOTES+="$IMPROVEMENTS"$'\n'
138+
fi
139+
140+
printf '%s' "$NOTES" > /tmp/release_notes.md
141+
142+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
143+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
144+
145+
- name: Check pre-release flag
146+
id: prerelease
147+
env:
148+
VERSION: ${{ steps.release.outputs.version }}
149+
run: |
150+
IS_PRERELEASE=$(python3 .github/scripts/check_prerelease.py)
151+
echo "is_prerelease=$IS_PRERELEASE" >> "$GITHUB_OUTPUT"
152+
153+
- name: Print dry-run summary
154+
env:
155+
VERSION: ${{ steps.release.outputs.version }}
156+
TAG: ${{ steps.release.outputs.tag }}
157+
IS_PRERELEASE: ${{ steps.prerelease.outputs.is_prerelease }}
158+
BRANCH: ${{ github.event.inputs.branch || github.head_ref }}
159+
run: |
160+
echo "========================================"
161+
echo " DRY RUN SUMMARY"
162+
echo "========================================"
163+
echo " Branch: $BRANCH"
164+
echo " Tag: $TAG"
165+
echo " Version: $VERSION"
166+
echo " Pre-release: $IS_PRERELEASE"
167+
echo ""
168+
echo " Release notes that would be created:"
169+
echo "----------------------------------------"
170+
cat /tmp/release_notes.md
171+
echo "----------------------------------------"
172+
echo " Step skipped (dry run): gh release create $TAG --draft"
173+
echo "========================================"
174+
175+
- name: Generate bot token
176+
id: bot_token
177+
uses: actions/create-github-app-token@v1
178+
with:
179+
app-id: ${{ secrets.CLOUD_SDK_BOT_APP_ID }}
180+
private-key: ${{ secrets.CLOUD_SDK_BOT_PRIVATE_KEY }}
181+
182+
- name: Install uv
183+
uses: astral-sh/setup-uv@v3
184+
185+
- name: Bump version and open auto-merge PR
186+
env:
187+
GH_TOKEN: ${{ steps.bot_token.outputs.token }}
188+
VERSION: ${{ steps.release.outputs.version }}
189+
TAG: ${{ steps.release.outputs.tag }}
190+
BRANCH: ${{ github.event.inputs.branch || github.head_ref }}
191+
run: |
192+
RELEASE_BRANCH="test-release-action-${TAG}"
193+
194+
git config user.name "github-actions[bot]"
195+
git config user.email "github-actions[bot]@users.noreply.github.com"
196+
197+
git checkout -b "$RELEASE_BRANCH"
198+
199+
CURRENT=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
200+
python .github/scripts/check_version_bump.py "$CURRENT" "$VERSION"
201+
202+
sed -i "s/^version = \"${CURRENT}\"/version = \"${VERSION}\"/" pyproject.toml
203+
grep '^version = ' pyproject.toml
204+
echo "Updated pyproject.toml → ${VERSION}"
205+
206+
uv lock
207+
208+
git add pyproject.toml uv.lock
209+
git commit -m "chore(test): bump version to ${VERSION}"
210+
git push origin "$RELEASE_BRANCH"
211+
212+
PR_URL=$(gh pr create \
213+
--repo "${{ github.repository }}" \
214+
--base "$BRANCH" \
215+
--head "$RELEASE_BRANCH" \
216+
--title "chore(test): bump version to ${VERSION}" \
217+
--body "Test version bump for [v${VERSION}](https://github.com/${{ github.repository }}/releases/tag/${TAG}). Merges automatically. Safe to delete if test is complete.")
218+
219+
echo "PR created: $PR_URL"
220+
221+
gh pr merge "$PR_URL" \
222+
--repo "${{ github.repository }}" \
223+
--squash \
224+
--delete-branch
225+
226+
echo "Version bump PR merged and branch deleted."

0 commit comments

Comments
 (0)