From 2bd3db8994097460d535698ec9d9f0731f610610 Mon Sep 17 00:00:00 2001 From: Norbert Elter <72046715+itsyoboieltr@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:22:33 +0400 Subject: [PATCH] feat: log-merge-group-failure (#28799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** [![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 (https://github.com/MetaMask/github-tools/pull/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: https://github.com/MetaMask/MetaMask-planning/issues/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. --- .github/workflows/main.yml | 18 +++++++++++ .../wait-for-circleci-workflow-status.yml | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/wait-for-circleci-workflow-status.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2554557b9c35..c7907455701d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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 }} diff --git a/.github/workflows/wait-for-circleci-workflow-status.yml b/.github/workflows/wait-for-circleci-workflow-status.yml new file mode 100644 index 000000000000..18e5ef7825d5 --- /dev/null +++ b/.github/workflows/wait-for-circleci-workflow-status.yml @@ -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