From e9b80b832e7dd89ae9a8b4fb1a11b0547d12627d Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:41:13 -0600 Subject: [PATCH] Skip SonarQube scan for PR from fork and allow compare_db workflow from fork (#327) * check if PR is from a fork and skip SonarQube scan if so -- fail job so it is clear that the scan was not run * specify repository of source branch in PR to allow PR from forked repository * change condition to run coverage report generation to only run if the step to check for a fork PR is skipped, meaning the tests should run * fixed syntax error --- .github/workflows/compare_db.yaml | 1 + .github/workflows/sonarqube.yaml | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compare_db.yaml b/.github/workflows/compare_db.yaml index 7ec5a544..d0a3e651 100644 --- a/.github/workflows/compare_db.yaml +++ b/.github/workflows/compare_db.yaml @@ -30,6 +30,7 @@ jobs: with: path: headnew ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} - name: check out baseold code uses: actions/checkout@v4 with: diff --git a/.github/workflows/sonarqube.yaml b/.github/workflows/sonarqube.yaml index 5f8d48a7..5db94deb 100644 --- a/.github/workflows/sonarqube.yaml +++ b/.github/workflows/sonarqube.yaml @@ -43,6 +43,10 @@ jobs: steps: + - name: Check if PR is from a fork + id: check_fork + if: ${{ github.event.pull_request.head.repo.full_name != 'dtcenter/METdataio' }} + run: echo "SonarQube scan cannot be run from a fork"; exit 1 - uses: actions/checkout@v4 with: # Disable shallow clones for better analysis @@ -76,11 +80,11 @@ jobs: - name: Output coverage report run: coverage report -m - if: always() + if: ${{ always() && steps.check_fork.conclusion == 'skipped' }} - name: Generate XML coverage report run: coverage xml - if: always() + if: ${{ always() && steps.check_fork.conclusion == 'skipped' }} - name: Get branch name id: get_branch_name