Skip to content

Commit 2bd3db8

Browse files
authored
feat: log-merge-group-failure (#28799)
<!-- 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** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28799?quickstart=1) This PR integrates the new reusable workflow (MetaMask/github-tools#31) that can be used to write data to google sheets when the merge group event fails. Environment variables (= GitHub secrets) are required to configure: - GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_SERVICE_ACCOUNT: The google service account that is used for authentication with the google sheets api. - The service account needs to have access to the google sheet you intend to operate on. To give access to the google sheet, you need to click the "Share" button in the top-right corner. Enter the service account's email (can be found on google cloud console), give "Editor" permissions. After this, the service account will have access to this spreadsheet, allowing read and write operations. - SPREADSHEET_ID: unique identifier that can be found in the url when you open the google sheet - SHEET_NAME: name of a sheet in a spreadsheet that can be found on the bottom Short summary of what happens in the workflow: 1. Google api authentication setup 2. Check if current date exists in the spreadsheet 3. If current date exists, increment number of PRs by 1 4. If current date does not exist, create a new row with the current date, and the number 1 (so that it can be incremented later, if more merge group events fail on the same day). Spreadsheet here: https://docs.google.com/spreadsheets/d/11niHgT_E2YzzXHXQSxX5LNdA6i0GG5aa-OZWvn7_-o4 Dashboard here: https://lookerstudio.google.com/u/1/reporting/e7e8f90e-72aa-4128-ae01-6305bf3393f4/page/p_pz1dszarmd ## **Related issues** Fixes: MetaMask/MetaMask-planning#3400 ## **Manual testing steps** 1. When the workflow runs, depending on the state of the spreadsheet: - If the current date already exists, the number of PRs removed from the merge queue should be incremented by 1. - If the current date does not exist, a new row should be added with the current date, and the number of PRs should be set to 1. I created a private repository to test it, and there it worked. The actual production usage can only be tested if we merge and see if anything gets removed from the merge queue, in this case the spreadsheet should get updated. ## **Screenshots/Recordings** Not applicable ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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 0556088 commit 2bd3db8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.github/workflows/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ jobs:
3232
name: Run tests
3333
uses: ./.github/workflows/run-tests.yml
3434

35+
wait-for-circleci-workflow-status:
36+
name: Wait for CircleCI workflow status
37+
uses: ./.github/workflows/wait-for-circleci-workflow-status.yml
38+
3539
all-jobs-completed:
3640
name: All jobs completed
3741
runs-on: ubuntu-latest
3842
needs:
3943
- check-workflows
4044
- run-tests
45+
- wait-for-circleci-workflow-status
4146
outputs:
4247
PASSED: ${{ steps.set-output.outputs.PASSED }}
4348
steps:
@@ -58,3 +63,16 @@ jobs:
5863
if [[ $passed != "true" ]]; then
5964
exit 1
6065
fi
66+
67+
log-merge-group-failure:
68+
name: Log merge group failure
69+
# Only run this job if the merge group event fails, skip on forks
70+
if: ${{ github.event_name == 'merge_group' && failure() && !github.event.repository.fork }}
71+
needs:
72+
- all-jobs-pass
73+
uses: metamask/github-tools/.github/workflows/log-merge-group-failure.yml@6bbad335a01fce1a9ec1eabd9515542c225d46c0
74+
secrets:
75+
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
76+
GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
77+
SPREADSHEET_ID: ${{ secrets.GOOGLE_MERGE_QUEUE_SPREADSHEET_ID }}
78+
SHEET_NAME: ${{ secrets.GOOGLE_MERGE_QUEUE_SHEET_NAME }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Wait for CircleCI workflow status
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
wait-for-circleci-workflow-status:
8+
name: Wait for CircleCI workflow status
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Wait for CircleCI workflow status
12+
env:
13+
OWNER: ${{ github.repository_owner }}
14+
REPOSITORY: ${{ github.event.repository.name }}
15+
BRANCH: ${{ github.head_ref || github.ref_name }}
16+
run: |
17+
pipeline_id=$(curl --silent "https://circleci.com/api/v2/project/gh/$OWNER/$REPOSITORY/pipeline?branch=$BRANCH" | jq -r ".items[0].id")
18+
workflow_status=$(curl --silent "https://circleci.com/api/v2/pipeline/$pipeline_id/workflow" | jq -r ".items[0].status")
19+
20+
if [ "$workflow_status" == "running" ]; then
21+
while [ "$workflow_status" == "running" ]; do
22+
sleep 30
23+
workflow_status=$(curl --silent "https://circleci.com/api/v2/pipeline/$pipeline_id/workflow" | jq -r ".items[0].status")
24+
done
25+
fi
26+
27+
if [ "$workflow_status" != "success" ]; then
28+
echo "::error::Workflow status is '$workflow_status'. Exiting with error."
29+
exit 1
30+
fi

0 commit comments

Comments
 (0)