Skip to content

Commit cbaa0e3

Browse files
authored
INFRA-2849:Added auto-create-release-pr workflow to automatically create release cp-13.3.0 (#35589)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** New Workflow auto-create-release-pr.yml will trigger create-release-pr.yml workflow when a new Branch is created that matches the syntax **Version-v***. The create-release-pr.yml workflow can still be triggered manually as well. Tested Manual Trigger: https://github.com/consensys-test/metamask-extension-test-workflow2/actions/runs/17437706364 Tested Automated Trigger **Version-v**: https://github.com/consensys-test/metamask-extension-test-workflow2/actions/runs/17435684587 Test Automated Trigger **release/**: https://github.com/consensys-test/metamask-extension-test-workflow2/actions/runs/17435734319 Tested Automated w/ Invalid Branch name: https://github.com/consensys-test/metamask-extension-test-workflow2/actions/runs/17409021422/job/49421128206, https://github.com/consensys-test/metamask-extension-test-workflow2/actions/runs/17411139614 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/35589?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 1a2619a commit cbaa0e3

File tree

2 files changed

+148
-4
lines changed

2 files changed

+148
-4
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Auto Create Release PR
2+
3+
on:
4+
create:
5+
6+
jobs:
7+
extract:
8+
if: ${{ github.ref_type == 'branch' && (startsWith(github.ref, 'refs/heads/Version-v') || startsWith(github.ref, 'refs/heads/release/')) }}
9+
runs-on: ubuntu-latest
10+
outputs:
11+
semver: ${{ steps.out.outputs.semver }}
12+
previous_ref: ${{ steps.out.outputs.previous_ref }}
13+
steps:
14+
- id: out
15+
shell: bash
16+
env:
17+
GITHUB_TOKEN: ${{ github.token }}
18+
run: |
19+
set -euo pipefail
20+
21+
ref_name="${GITHUB_REF#refs/heads/}"
22+
23+
# Extract semver based on prefix
24+
if [[ "$ref_name" == Version-v* ]]; then
25+
semver="${ref_name#Version-v}"
26+
elif [[ "$ref_name" == release/* ]]; then
27+
semver="${ref_name#release/}"
28+
else
29+
echo "Error: Branch name must be Version-vX.Y.Z or release/X.Y.Z where X, Y, Z are numbers. Got: $ref_name" >&2
30+
exit 1
31+
fi
32+
echo "semver=${semver}" >> "$GITHUB_OUTPUT"
33+
34+
# Validate semver format X.Y.Z where X, Y, Z are numbers
35+
if ! [[ "$semver" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
36+
echo "Error: Invalid semver in branch name: $ref_name (extracted: $semver; must be numeric X.Y.Z)" >&2
37+
exit 1
38+
fi
39+
40+
# Function to paginate and collect refs for a prefix
41+
fetch_matching_refs() {
42+
local prefix="$1"
43+
local temp_file
44+
temp_file="$(mktemp)"
45+
local page=1
46+
echo "Fetching branches matching $prefix* (paginated)..." >&2
47+
while :; do
48+
echo "Fetching page $page for $prefix..." >&2
49+
resp="$(mktemp)"
50+
url="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/heads/${prefix}?per_page=100&page=${page}"
51+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "$url" -o "$resp"
52+
53+
cat "$resp" >> "$temp_file"
54+
55+
count=$(jq length "$resp")
56+
if [ "$count" -lt 100 ]; then
57+
break
58+
fi
59+
page=$((page + 1))
60+
done
61+
echo "$temp_file"
62+
}
63+
64+
# Fetch for each prefix
65+
version_v_file=$(fetch_matching_refs "Version-v")
66+
release_file=$(fetch_matching_refs "release/")
67+
68+
# Combine and process: extract {name, semver} for matches, sort desc by semver
69+
jq -s 'add | [ .[] | .ref | ltrimstr("refs/heads/") as $name | select($name | test("^Version-v[0-9]+\\.[0-9]+\\.[0-9]+$") or test("^release/[0-9]+\\.[0-9]+\\.[0-9]+$")) | {name: $name, semver: (if $name | test("^Version-v") then $name | ltrimstr("Version-v") else $name | ltrimstr("release/") end) } ] | sort_by( .semver | split(".") | map(tonumber) ) | reverse' "$version_v_file" "$release_file" > all_versions.json
70+
71+
# Print all found versions (sorted desc)
72+
echo "All found versions (sorted desc): $(jq '[ .[].semver ]' all_versions.json)"
73+
74+
# Print all found matching branches (sorted by semver desc)
75+
echo "All found matching branches:"
76+
jq -r '.[].name' all_versions.json || echo "No matching branches found."
77+
78+
# Filter to those with semver strictly lower than current
79+
jq --arg semver "$semver" '[ .[] | select( .semver as $v | $semver | split(".") as $c | $v | split(".") as $p | ($p[0] | tonumber) < ($c[0] | tonumber) or (($p[0] | tonumber) == ($c[0] | tonumber) and (($p[1] | tonumber) < ($c[1] | tonumber) or (($p[1] | tonumber) == ($c[1] | tonumber) and ($p[2] | tonumber) < ($c[2] | tonumber)))) ) ]' all_versions.json > filtered_versions.json
80+
81+
# Print filtered versions (still sorted desc, so [0] is highest lower)
82+
echo "Filtered versions (< $semver, sorted desc): $(jq '[ .[].semver ]' filtered_versions.json)"
83+
84+
# Select the highest lower: first in filtered list
85+
if [ "$(jq length filtered_versions.json)" -eq 0 ]; then
86+
echo "Error: No versions lower than $semver found. Cannot determine previous-version-ref." >&2
87+
exit 1
88+
else
89+
highest_lower="$(jq -r '.[0].semver' filtered_versions.json)"
90+
previous_ref="$(jq -r '.[0].name' filtered_versions.json)"
91+
echo "Selected highest version lower than $semver: ${highest_lower}"
92+
echo "Selected branch: ${previous_ref}"
93+
echo "Passing to previous-version-ref: ${previous_ref}"
94+
fi
95+
echo "previous_ref=${previous_ref}" >> "$GITHUB_OUTPUT"
96+
97+
# Print values passed to call-create-release-pr
98+
echo "Inputs to call-create-release-pr:"
99+
echo " checkout-base-branch: main"
100+
echo " release-pr-base-branch: stable"
101+
echo " semver-version: ${semver}"
102+
echo " previous-version-ref: ${previous_ref}"
103+
104+
call-create-release-pr:
105+
if: ${{ github.ref_type == 'branch' && (startsWith(github.ref, 'refs/heads/Version-v') || startsWith(github.ref, 'refs/heads/release/')) }}
106+
needs: extract
107+
permissions:
108+
contents: write
109+
pull-requests: write
110+
uses: ./.github/workflows/create-release-pr.yml
111+
secrets:
112+
github-token: ${{ secrets.PR_TOKEN }}
113+
google-application-creds-base64: ${{ secrets.GCP_RLS_SHEET_ACCOUNT_BASE64 }}
114+
with:
115+
checkout-base-branch: main
116+
release-pr-base-branch: stable
117+
semver-version: ${{ needs.extract.outputs.semver }}
118+
previous-version-ref: ${{ needs.extract.outputs.previous_ref }}

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,47 @@ on:
1616
description: 'Previous release version branch name, tag or commit hash (e.g., Version-vx.y.z, v7.7.0, or 76fbc500034db9779e9ff7ce637ac5be1da0493d)'
1717
required: true
1818

19+
workflow_call:
20+
inputs:
21+
checkout-base-branch:
22+
required: true
23+
type: string
24+
release-pr-base-branch:
25+
required: true
26+
type: string
27+
semver-version:
28+
required: true
29+
type: string
30+
previous-version-ref:
31+
required: true
32+
type: string
33+
secrets:
34+
github-token:
35+
required: false
36+
google-application-creds-base64:
37+
required: false
38+
PR_TOKEN:
39+
required: false
40+
GCP_RLS_SHEET_ACCOUNT_BASE64:
41+
required: false
42+
1943
jobs:
2044
create-release-pr:
2145
name: Create Release Pull Request using Github Tools
22-
uses: MetaMask/github-tools/.github/workflows/create-release-pr.yml@914cbff8a8d58cfe0053e8690a3c0d4b281e27d6
46+
uses: MetaMask/github-tools/.github/workflows/create-release-pr.yml@ddac3ee395896ff15df6fc561ff710efbb0dd3fa
2347
with:
2448
platform: extension
2549
checkout-base-branch: ${{ inputs.checkout-base-branch }}
2650
release-pr-base-branch: ${{ inputs.release-pr-base-branch }}
2751
semver-version: ${{ inputs.semver-version }}
2852
previous-version-ref: ${{ inputs.previous-version-ref }}
29-
github-tools-version: 914cbff8a8d58cfe0053e8690a3c0d4b281e27d6
53+
github-tools-version: ddac3ee395896ff15df6fc561ff710efbb0dd3fa
3054
secrets:
3155
# This token needs write permissions to metamask-extension & read permissions to metamask-planning
32-
github-token: ${{ secrets.PR_TOKEN }}
33-
google-application-creds-base64: ${{ secrets.GCP_RLS_SHEET_ACCOUNT_BASE64 }}
56+
# If called from auto-create-release-pr use the PR_TOKEN passed in as an input, if called manually use github secret token values
57+
# (this is due to github limitations on fetching secrets from called workflows).
58+
github-token: ${{ github.event_name == 'workflow_dispatch' && secrets.PR_TOKEN || secrets.github-token }}
59+
google-application-creds-base64: ${{ github.event_name == 'workflow_dispatch' && secrets.GCP_RLS_SHEET_ACCOUNT_BASE64 || secrets.google-application-creds-base64 }}
3460
permissions:
3561
contents: write
3662
pull-requests: write

0 commit comments

Comments
 (0)