Skip to content

Commit 190645b

Browse files
committed
feat(INFRA-2772): add automatic main version bump after release PR creation
1 parent fc6fe1a commit 190645b

1 file changed

Lines changed: 153 additions & 0 deletions

File tree

.github/workflows/create-release-pr.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,156 @@ jobs:
128128
${{ inputs.previous-version-tag }} \
129129
${{ inputs.semver-version }} \
130130
${{ inputs.mobile-build-version }}
131+
132+
bump-main-version:
133+
name: Create Version Bump PR for Main
134+
runs-on: ubuntu-latest
135+
needs: create-release-pr
136+
permissions:
137+
contents: write
138+
pull-requests: write
139+
steps:
140+
# Step 1: Checkout main branch of invoking repository
141+
- name: Checkout main branch
142+
uses: actions/checkout@v4
143+
with:
144+
fetch-depth: 0
145+
ref: main
146+
token: ${{ secrets.github-token }}
147+
148+
# Step 2: Checkout github-tools repository
149+
- name: Checkout github-tools repository
150+
uses: actions/checkout@v4
151+
with:
152+
repository: MetaMask/github-tools
153+
ref: ${{ inputs.github-tools-version }}
154+
path: github-tools
155+
156+
# Step 3: Setup environment from github-tools
157+
- name: Checkout and setup environment
158+
uses: ./github-tools/.github/actions/checkout-and-setup
159+
with:
160+
is-high-risk-environment: true
161+
162+
# Step 4: Calculate next version
163+
- name: Calculate next version
164+
id: calc-version
165+
working-directory: github-tools
166+
run: |
167+
# Use Node.js semver to increment the minor version
168+
CURRENT_VERSION="${{ inputs.semver-version }}"
169+
NEXT_VERSION=$(node -e "
170+
const semver = require('semver');
171+
const current = '$CURRENT_VERSION';
172+
const next = semver.inc(current, 'minor');
173+
console.log(next);
174+
")
175+
echo "next-version=$NEXT_VERSION" >> $GITHUB_OUTPUT
176+
echo "Next version will be: $NEXT_VERSION"
177+
178+
# Step 5: Create version bump branch
179+
- name: Create version bump branch
180+
run: |
181+
BRANCH_NAME="bump-main-version-${{ steps.calc-version.outputs.next-version }}"
182+
183+
# Check if branch already exists locally or remotely
184+
if git show-ref --verify --quiet refs/heads/"$BRANCH_NAME" || git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
185+
echo "Branch $BRANCH_NAME already exists, checking it out"
186+
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
187+
git fetch origin "$BRANCH_NAME"
188+
git checkout "$BRANCH_NAME"
189+
else
190+
git checkout "$BRANCH_NAME"
191+
fi
192+
else
193+
echo "Creating new branch $BRANCH_NAME"
194+
git checkout -b "$BRANCH_NAME"
195+
fi
196+
197+
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
198+
id: create-branch
199+
200+
# Step 6: Update version using set-semvar-version.sh
201+
- name: Update version files
202+
run: |
203+
# Make script executable
204+
chmod +x ./github-tools/.github/scripts/set-semvar-version.sh
205+
206+
# Run the version update script
207+
./github-tools/.github/scripts/set-semvar-version.sh \
208+
${{ steps.calc-version.outputs.next-version }} \
209+
${{ inputs.platform }}
210+
211+
# Step 7: Commit changes
212+
- name: Commit version bump
213+
run: |
214+
git config --local user.email "action@github.com"
215+
git config --local user.name "GitHub Action"
216+
git add -A
217+
git commit -m "Bump version to ${{ steps.calc-version.outputs.next-version }} after release ${{ inputs.semver-version }}
218+
219+
This automated version bump ensures that:
220+
- Main branch version is ahead of the release branch
221+
- Future nightly builds will have correct versioning
222+
223+
Release version: ${{ inputs.semver-version }}
224+
New main version: ${{ steps.calc-version.outputs.next-version }}
225+
Platform: ${{ inputs.platform }}"
226+
227+
# Step 8: Push branch
228+
- name: Push version bump branch
229+
run: |
230+
if ! git push --set-upstream origin ${{ steps.create-branch.outputs.branch-name }}; then
231+
echo "No changes to push to ${{ steps.create-branch.outputs.branch-name }}"
232+
# Check if branch exists remotely
233+
if git ls-remote --heads origin ${{ steps.create-branch.outputs.branch-name }} | grep -q ${{ steps.create-branch.outputs.branch-name }}; then
234+
echo "Branch ${{ steps.create-branch.outputs.branch-name }} already exists remotely"
235+
else
236+
echo "Error: Failed to push and branch doesn't exist remotely"
237+
exit 1
238+
fi
239+
fi
240+
241+
# Step 9: Create pull request
242+
- name: Create pull request
243+
env:
244+
GH_TOKEN: ${{ secrets.github-token }}
245+
run: |
246+
# Check if PR already exists
247+
if gh pr list --head ${{ steps.create-branch.outputs.branch-name }} --json number --jq 'length' | grep -q "1"; then
248+
echo "PR for branch ${{ steps.create-branch.outputs.branch-name }} already exists"
249+
else
250+
gh pr create \
251+
--title "🔄 Bump main version to ${{ steps.calc-version.outputs.next-version }}" \
252+
--body "## Version Bump After Release
253+
254+
This PR bumps the main branch version from ${{ inputs.semver-version }} to ${{ steps.calc-version.outputs.next-version }} after cutting the release branch.
255+
256+
### Why this is needed:
257+
- **Nightly builds**: Each nightly build needs to be one minor version ahead of the current release candidate
258+
- **Version conflicts**: Prevents conflicts between nightlies and release candidates
259+
- **Platform alignment**: Maintains version alignment between MetaMask mobile and extension
260+
- **Update systems**: Ensures nightlies are accepted by app stores and browser update systems
261+
262+
### What changed:
263+
- Version bumped from \`${{ inputs.semver-version }}\` to \`${{ steps.calc-version.outputs.next-version }}\`
264+
- Platform: \`${{ inputs.platform }}\`
265+
- Files updated by \`set-semvar-version.sh\` script
266+
267+
### Next steps:
268+
This PR should be **manually reviewed and merged by the release manager** to maintain proper version flow.
269+
270+
### Related:
271+
- Release version: ${{ inputs.semver-version }}
272+
- Base branch for release: ${{ inputs.base-branch }}
273+
- Platform: ${{ inputs.platform }}
274+
275+
---
276+
*This PR was automatically created by the \`create-release-pr\` workflow.*" \
277+
--base main \
278+
--head ${{ steps.create-branch.outputs.branch-name }} \
279+
--label "release-management" \
280+
--label "version-bump" \
281+
--assignee @me
282+
echo "Version bump PR created successfully"
283+
fi

0 commit comments

Comments
 (0)