Skip to content

Commit 2eda807

Browse files
committed
Refactor all workflows to be composite actions
1 parent be06c31 commit 2eda807

31 files changed

Lines changed: 1285 additions & 1326 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Add Issue/PR to Project By Team'
2+
3+
inputs:
4+
project-url:
5+
description: 'URL of the GitHub Project where items should be added.'
6+
required: true
7+
team-name:
8+
description: 'Team name to match for PR review_requested or requested_team.'
9+
required: true
10+
team-label:
11+
description: 'Label that indicates the Issue/PR belongs to the team.'
12+
required: true
13+
filter-enabled:
14+
description: 'If true, only add items that match the team criteria. If false, add every item.'
15+
required: false
16+
default: 'true'
17+
github-token:
18+
description: 'GitHub token with access to the project.'
19+
required: true
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Add item to project board
25+
uses: actions/add-to-project@v1.0.2
26+
# If filtering is disabled, the condition is always true.
27+
# If filtering is enabled, then:
28+
# - For PRs, check that the PR either has the specified team in requested_team
29+
# or contains the team label.
30+
# - For Issues, check that the issue contains the team label.
31+
if: |
32+
inputs.filter-enabled != 'true' ||
33+
((github.event_name == 'pull_request' &&
34+
(
35+
github.event.requested_team.name == inputs.team-name ||
36+
contains(github.event.pull_request.labels.*.name, inputs.team-label) ||
37+
contains(github.event.pull_request.requested_teams.*.name, inputs.team-name)
38+
)
39+
)
40+
||
41+
(github.event_name == 'issues' &&
42+
(
43+
contains(github.event.issue.labels.*.name, inputs.team-label)
44+
)
45+
))
46+
with:
47+
project-url: ${{ inputs.project-url }}
48+
github-token: ${{ inputs.github-token }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Add Team Label
2+
description: "Adds a GitHub team label to a pull request based on the author's entry in the MetaMask topology file."
3+
4+
inputs:
5+
team-label-token:
6+
description: 'GitHub token with access to read topology.json and add labels to PRs.'
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
# Fetch the team label for the PR author from topology.json and expose it as a step output.
13+
- name: Get team label
14+
id: get-team-label
15+
env:
16+
GH_TOKEN: ${{ inputs.team-label-token }}
17+
USER: ${{ github.event.pull_request.user.login }}
18+
shell: bash
19+
run: |
20+
# Stream topology.json through jq, find the first team where USER appears in members, pm, em, or tl, and emit
21+
# its githubLabel.name value.
22+
team_label=$(gh api -H 'Accept: application/vnd.github.raw' 'repos/metamask/metamask-planning/contents/topology.json' | jq -r --arg USER "$USER" '.[] | select(any(.members[]?; . == $USER) or (.pm // empty) == $USER or (.em // empty) == $USER or (.tl // empty) == $USER) | .githubLabel.name' | head -n 1)
23+
if [ -z "$team_label" ]; then
24+
echo "::error::Team label not found for author: $USER. Please open a pull request with your GitHub handle and team label to update topology.json at https://github.com/MetaMask/MetaMask-planning/blob/main/topology.json"
25+
exit 1
26+
fi
27+
echo "TEAM_LABEL=$team_label" >> "$GITHUB_OUTPUT"
28+
29+
# Apply the retrieved label to the pull request using the GitHub CLI.
30+
- name: Add team label
31+
env:
32+
GH_TOKEN: ${{ secrets.TEAM_LABEL_TOKEN }}
33+
PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
34+
TEAM_LABEL: ${{ steps.get-team-label.outputs.TEAM_LABEL }}
35+
shell: bash
36+
run: |
37+
gh issue edit "$PULL_REQUEST_URL" --add-label "$TEAM_LABEL"
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: Create Release Pull Request
2+
3+
inputs:
4+
checkout-base-branch:
5+
required: true
6+
description: 'The base branch, tag, or SHA for git operations.'
7+
release-pr-base-branch:
8+
required: true
9+
description: 'The base branch, tag, or SHA for the release pull request.'
10+
semver-version:
11+
required: true
12+
description: 'A semantic version, e.g.: "x.y.z".'
13+
mobile-build-version:
14+
required: false
15+
description: 'The build version for the mobile platform.'
16+
previous-version-ref:
17+
required: true
18+
description: 'Previous release version branch name, tag or commit hash (e.g., release/7.7.0, v7.7.0, or 76fbc500034db9779e9ff7ce637ac5be1da0493d). For hotfix releases, pass the literal string "null".'
19+
mobile-template-sheet-id:
20+
required: false
21+
description: 'The Mobile testing sheet template id.'
22+
default: '1012668681' # prod sheet template
23+
extension-template-sheet-id:
24+
required: false
25+
description: 'The Extension testing sheet template id.'
26+
default: '295804563' # prod sheet template
27+
test-only:
28+
required: false
29+
description: 'If true, the release will be marked as a test release.'
30+
default: 'false'
31+
release-sheet-google-document-id:
32+
required: false
33+
description: 'The Google Document ID for the release notes.'
34+
default: '1tsoodlAlyvEUpkkcNcbZ4PM9HuC9cEM80RZeoVv5OCQ' # Prod Release Document
35+
platform:
36+
required: true
37+
description: 'The platform for which the release PR is being created. Must be one of: mobile, extension.'
38+
git-user-name:
39+
description: 'Git user name for commits. Defaults to metamaskbot.'
40+
default: 'metamaskbot'
41+
git-user-email:
42+
description: 'Git user email for commits. Defaults to metamaskbot@users.noreply.github.com.'
43+
default: 'metamaskbot@users.noreply.github.com'
44+
github-token:
45+
description: 'GitHub token used for authentication.'
46+
required: true
47+
google-application-creds-base64:
48+
description: 'Google application credentials base64 encoded.'
49+
required: true
50+
github-tools-repository:
51+
description: 'The GitHub repository containing the GitHub tools. Defaults to the GitHub tools action repositor, and usually does not need to be changed.'
52+
required: false
53+
default: ${{ github.action_repository }}
54+
github-tools-ref:
55+
description: 'The SHA of the action to use. Defaults to the current action ref, and usually does not need to be changed.'
56+
required: false
57+
default: ${{ github.action_ref }}
58+
59+
runs:
60+
using: composite
61+
steps:
62+
# Step 1: Checkout invoking repository (metamask-mobile | metamask-extension )
63+
- name: Checkout invoking repository
64+
uses: actions/checkout@v4
65+
with:
66+
fetch-depth: 0
67+
ref: ${{ inputs.checkout-base-branch }}
68+
token: ${{ inputs.github-token }}
69+
70+
# Step 2: Checkout github-tools repository
71+
- name: Checkout github-tools repository
72+
uses: actions/checkout@v4
73+
with:
74+
repository: ${{ inputs.github-tools-repository }}
75+
ref: ${{ inputs.github-tools-ref }}
76+
path: github-tools
77+
78+
# Step 3: Setup environment
79+
- name: Checkout and setup environment
80+
uses: MetaMask/action-checkout-and-setup@v2
81+
with:
82+
is-high-risk-environment: true
83+
84+
# Step 4: Print Input Values
85+
- name: Print Input Values
86+
env:
87+
PLATFORM: ${{ inputs.platform }}
88+
CHECKOUT_BASE_BRANCH: ${{ inputs.checkout-base-branch }}
89+
RELEASE_PR_BASE_BRANCH: ${{ inputs.release-pr-base-branch }}
90+
SEMVER_VERSION: ${{ inputs.semver-version }}
91+
PREVIOUS_VERSION_REF: ${{ inputs.previous-version-ref }}
92+
TEST_ONLY: ${{ inputs.test-only }}
93+
MOBILE_BUILD_VERSION: ${{ inputs.mobile-build-version }}
94+
MOBILE_TEMPLATE_SHEET_ID: ${{ inputs.mobile-template-sheet-id }}
95+
EXTENSION_TEMPLATE_SHEET_ID: ${{ inputs.extension-template-sheet-id }}
96+
RELEASE_SHEET_GOOGLE_DOCUMENT_ID: ${{ inputs.release-sheet-google-document-id }}
97+
GIT_USER_NAME: ${{ inputs.git-user-name }}
98+
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
99+
shell: bash
100+
run: |
101+
echo "Input Values:"
102+
echo "-------------"
103+
echo "Platform: $PLATFORM"
104+
echo "Checkout Base Branch: $CHECKOUT_BASE_BRANCH"
105+
echo "Release PR Base Branch: $RELEASE_PR_BASE_BRANCH"
106+
echo "Semver Version: $SEMVER_VERSION"
107+
echo "Previous Version Reference: $PREVIOUS_VERSION_REF"
108+
echo "Test Only Mode: $TEST_ONLY"
109+
if [[ "$PLATFORM" == "mobile" ]]; then
110+
echo "Mobile Build Version: $MOBILE_BUILD_VERSION"
111+
fi
112+
echo "Mobile Template Sheet ID: $MOBILE_TEMPLATE_SHEET_ID"
113+
echo "Extension Template Sheet ID: $EXTENSION_TEMPLATE_SHEET_ID"
114+
echo "Release Sheet Google Document ID: $RELEASE_SHEET_GOOGLE_DOCUMENT_ID"
115+
echo "Git User Name: $GIT_USER_NAME"
116+
echo "Git User Email: $GIT_USER_EMAIL"
117+
echo "-------------"
118+
119+
# Step 5: Create Release PR
120+
- name: Create Release PR
121+
id: create-release-pr
122+
shell: bash
123+
env:
124+
GITHUB_TOKEN: ${{ inputs.github-token }}
125+
BASE_BRANCH: ${{ inputs.release-pr-base-branch }}
126+
GITHUB_REPOSITORY_URL: '${{ github.server_url }}/${{ github.repository }}'
127+
TEST_ONLY: ${{ inputs.test-only }}
128+
GOOGLE_DOCUMENT_ID: ${{ inputs.release-sheet-google-document-id }}
129+
GOOGLE_APPLICATION_CREDENTIALS_BASE64: ${{ secrets.google-application-creds-base64 }}
130+
NEW_VERSION: ${{ inputs.semver-version }}
131+
MOBILE_TEMPLATE_SHEET_ID: ${{ inputs.mobile-template-sheet-id }}
132+
EXTENSION_TEMPLATE_SHEET_ID: ${{ inputs.extension-template-sheet-id }}
133+
PLATFORM: ${{ inputs.platform }}
134+
PREVIOUS_VERSION_REF: ${{ inputs.previous-version-ref }}
135+
SEMVER_VERSION: ${{ inputs.semver-version }}
136+
MOBILE_BUILD_VERSION: ${{ inputs.mobile-build-version }}
137+
GIT_USER_NAME: ${{ inputs.git-user-name }}
138+
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
139+
working-directory: ${{ github.workspace }}
140+
run: |
141+
# Execute the script from github-tools
142+
./github-tools/.github/scripts/create-platform-release-pr.sh \
143+
"$PLATFORM" \
144+
"$PREVIOUS_VERSION_REF" \
145+
"$SEMVER_VERSION" \
146+
"$MOBILE_BUILD_VERSION" \
147+
"$GIT_USER_NAME" \
148+
"$GIT_USER_EMAIL"
149+
150+
# Step 6: Upload commits.csv as artifact (if generated)
151+
- name: Upload commits.csv artifact
152+
if: ${{ hashFiles('commits.csv') != '' }}
153+
uses: actions/upload-artifact@v4
154+
with:
155+
name: commits-csv
156+
path: commits.csv
157+
if-no-files-found: error
158+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Flaky Test Report
2+
3+
inputs:
4+
repository:
5+
description: 'Repository name (e.g. metamask-extension)'
6+
required: true
7+
workflow_id:
8+
description: 'Workflow ID to analyze (e.g. main.yml)'
9+
required: true
10+
github-token:
11+
description: 'GitHub token with repo and actions:read access'
12+
required: true
13+
slack-webhook-flaky-tests:
14+
description: 'Slack webhook URL for flaky test reports'
15+
required: true
16+
17+
runs:
18+
using: composite
19+
steps:
20+
- name: Checkout github-tools repository
21+
uses: actions/checkout@v4
22+
with:
23+
repository: MetaMask/github-tools
24+
path: github-tools
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version-file: ./github-tools/.nvmrc
30+
cache-dependency-path: ./github-tools/yarn.lock
31+
cache: yarn
32+
33+
- name: Enable Corepack
34+
working-directory: ./github-tools
35+
shell: bash
36+
run: corepack enable
37+
38+
- name: Install dependencies
39+
working-directory: ./github-tools
40+
shell: bash
41+
run: yarn --immutable
42+
43+
- name: Run flaky test report script
44+
env:
45+
REPOSITORY: ${{ inputs.repository }}
46+
WORKFLOW_ID: ${{ inputs.workflow_id }}
47+
GITHUB_TOKEN: ${{ inputs.github-token }}
48+
SLACK_WEBHOOK_FLAKY_TESTS: ${{ inputs.slack-webhook-flaky-tests }}
49+
working-directory: ./github-tools
50+
shell: bash
51+
run: node .github/scripts/create-flaky-test-report.mjs
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Get Release Timelines
2+
3+
inputs:
4+
version:
5+
required: true
6+
description: The version of the release.
7+
github-token:
8+
required: true
9+
description: The GitHub token used for authentication.
10+
runway-app-id:
11+
required: true
12+
description: The Runway application ID.
13+
runway-api-key:
14+
required: true
15+
description: The Runway API key.
16+
github-tools-repository:
17+
description: 'The GitHub repository containing the GitHub tools. Defaults to the GitHub tools action repositor, and usually does not need to be changed.'
18+
required: false
19+
default: ${{ github.action_repository }}
20+
github-tools-ref:
21+
description: 'The SHA of the action to use. Defaults to the current action ref, and usually does not need to be changed.'
22+
required: false
23+
default: ${{ github.action_ref }}
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: Checkout GitHub tools repository
29+
uses: actions/checkout@v5
30+
with:
31+
repository: ${{ inputs.github-tools-repository }}
32+
ref: ${{ inputs.github-tools-ref }}
33+
path: ./github-tools
34+
35+
- name: Get release timelines
36+
env:
37+
OWNER: ${{ github.repository_owner }}
38+
REPOSITORY: ${{ github.event.repository.name }}
39+
VERSION: ${{ inputs.version }}
40+
RUNWAY_APP_ID: ${{ inputs.runway-app-id }}
41+
RUNWAY_API_KEY: ${{ inputs.runway-api-key }}
42+
GH_TOKEN: ${{ inputs.github-token }}
43+
shell: bash
44+
run: ./github-tools/.github/scripts/get-release-timelines.sh
45+
46+
- name: Upload artifact release-timelines-${{ inputs.version }}.csv
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: release-timelines-${{ inputs.version }}.csv
50+
path: release-timelines-${{ inputs.version }}.csv

0 commit comments

Comments
 (0)