Skip to content

Commit

Permalink
feat: log-merge-group-failure (#28799)
Browse files Browse the repository at this point in the history
<!--
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.
  • Loading branch information
itsyoboieltr authored Dec 11, 2024
1 parent 0556088 commit 2bd3db8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ jobs:
name: Run tests
uses: ./.github/workflows/run-tests.yml

wait-for-circleci-workflow-status:
name: Wait for CircleCI workflow status
uses: ./.github/workflows/wait-for-circleci-workflow-status.yml

all-jobs-completed:
name: All jobs completed
runs-on: ubuntu-latest
needs:
- check-workflows
- run-tests
- wait-for-circleci-workflow-status
outputs:
PASSED: ${{ steps.set-output.outputs.PASSED }}
steps:
Expand All @@ -58,3 +63,16 @@ jobs:
if [[ $passed != "true" ]]; then
exit 1
fi
log-merge-group-failure:
name: Log merge group failure
# Only run this job if the merge group event fails, skip on forks
if: ${{ github.event_name == 'merge_group' && failure() && !github.event.repository.fork }}
needs:
- all-jobs-pass
uses: metamask/github-tools/.github/workflows/log-merge-group-failure.yml@6bbad335a01fce1a9ec1eabd9515542c225d46c0
secrets:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
SPREADSHEET_ID: ${{ secrets.GOOGLE_MERGE_QUEUE_SPREADSHEET_ID }}
SHEET_NAME: ${{ secrets.GOOGLE_MERGE_QUEUE_SHEET_NAME }}
30 changes: 30 additions & 0 deletions .github/workflows/wait-for-circleci-workflow-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Wait for CircleCI workflow status

on:
workflow_call:

jobs:
wait-for-circleci-workflow-status:
name: Wait for CircleCI workflow status
runs-on: ubuntu-latest
steps:
- name: Wait for CircleCI workflow status
env:
OWNER: ${{ github.repository_owner }}
REPOSITORY: ${{ github.event.repository.name }}
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
pipeline_id=$(curl --silent "https://circleci.com/api/v2/project/gh/$OWNER/$REPOSITORY/pipeline?branch=$BRANCH" | jq -r ".items[0].id")
workflow_status=$(curl --silent "https://circleci.com/api/v2/pipeline/$pipeline_id/workflow" | jq -r ".items[0].status")
if [ "$workflow_status" == "running" ]; then
while [ "$workflow_status" == "running" ]; do
sleep 30
workflow_status=$(curl --silent "https://circleci.com/api/v2/pipeline/$pipeline_id/workflow" | jq -r ".items[0].status")
done
fi
if [ "$workflow_status" != "success" ]; then
echo "::error::Workflow status is '$workflow_status'. Exiting with error."
exit 1
fi

0 comments on commit 2bd3db8

Please sign in to comment.