From f2b43927944d0599fb20d032aff7b3000686413c Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 25 Sep 2024 07:44:14 -0700 Subject: [PATCH] chore: Add skip label to bypass sonarcloud (#11425) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Adds logic in the `sonar-cloud-quality-gate-status` step in the CI that checks for the existence of `skip-sonar-cloud` label. If it exists, the step is bypassed and passes. If the label doesn't exist, it checks the sonar cloud quality gate status as usual. Also removes the redundant `sonar-cloud` dependency in the `all-jobs-pass` step ## **Related issues** Fixes: #11403 ## **Manual testing steps** - Apply `skip-sonar-cloud` label - Manually re-run `ci.yml` jobs - Notice the `sonar-cloud-quality-gate-status` step logs that it is skipped and the status checks is green - Afterwards, remove `skip-sonar-cloud` label - Manually re-run `ci.yml` jobs - Notice the `sonar-cloud-quality-gate-status` step runs as usual ## **Screenshots/Recordings** ### **Before** ### **After** With label applied https://github.com/MetaMask/metamask-mobile/actions/runs/11026106803/job/30622332596?pr=11425 Without label applied **https://github.com/MetaMask/metamask-mobile/actions/runs/11026106803/job/30623782793** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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/ci.yml | 54 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dc2626eae8..64bd5bea831 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -222,6 +222,10 @@ jobs: uses: actions/checkout@v3 - name: SonarCloud Quality Gate Status id: sonar-status + env: + REPO: ${{ github.repository }} + ISSUE_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Skip step if event is a PR if [[ "${{ github.event_name }}" != "pull_request" ]]; then @@ -229,31 +233,40 @@ jobs: exit 0 fi - sleep 30 + # Bypass step if skip-sonar-cloud label is found + LABEL=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/labels" | \ + jq -r '.[] | select(.name=="skip-sonar-cloud") | .name') - PROJECT_KEY="metamask-mobile" - PR_NUMBER="${{ github.event.pull_request.number }}" - SONAR_TOKEN="${{ secrets.SONAR_TOKEN }}" + if [[ "$LABEL" == "skip-sonar-cloud" ]]; then + echo "skip-sonar-cloud label found. Skipping SonarCloud Quality Gate check." + else + sleep 30 - if [ -z "$PR_NUMBER" ]; then - echo "No pull request number found. Failing the check." - exit 1 - fi + PROJECT_KEY="metamask-mobile" + PR_NUMBER="${{ github.event.pull_request.number }}" + SONAR_TOKEN="${{ secrets.SONAR_TOKEN }}" - RESPONSE=$(curl -s -u "$SONAR_TOKEN:" \ - "https://sonarcloud.io/api/qualitygates/project_status?projectKey=$PROJECT_KEY&pullRequest=$PR_NUMBER") - echo "SonarCloud API Response: $RESPONSE" + if [ -z "$PR_NUMBER" ]; then + echo "No pull request number found. Failing the check." + exit 1 + fi - STATUS=$(echo "$RESPONSE" | jq -r '.projectStatus.status') + RESPONSE=$(curl -s -u "$SONAR_TOKEN:" \ + "https://sonarcloud.io/api/qualitygates/project_status?projectKey=$PROJECT_KEY&pullRequest=$PR_NUMBER") + echo "SonarCloud API Response: $RESPONSE" - if [[ "$STATUS" == "ERROR" ]]; then - echo "Quality Gate failed." - exit 1 - elif [[ "$STATUS" == "OK" ]]; then - echo "Quality Gate passed." - else - echo "Could not determine Quality Gate status." - exit 1 + STATUS=$(echo "$RESPONSE" | jq -r '.projectStatus.status') + + if [[ "$STATUS" == "ERROR" ]]; then + echo "Quality Gate failed." + exit 1 + elif [[ "$STATUS" == "OK" ]]; then + echo "Quality Gate passed." + else + echo "Could not determine Quality Gate status." + exit 1 + fi fi check-workflows: name: Check workflows @@ -277,7 +290,6 @@ jobs: scripts, unit-tests, check-workflows, - sonar-cloud, js-bundle-size-check, sonar-cloud-quality-gate-status, ]