From 398f9427df3e4b5c1dd29065b1c044e43b49d1d5 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 7 Sep 2022 11:45:00 +0200 Subject: [PATCH 1/4] Only run sonarqube task if tokens are not empty to avoid failure --- .github/workflows/tests.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81262f1e9f..64f67a477e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,9 +1,9 @@ name: Test on: - pull_request: {} + pull_request: { } push: - branches: [main, develop] + branches: [ main, develop ] # Enrich gradle.properties for CI/CD env: @@ -18,6 +18,10 @@ jobs: concurrency: group: ${{ github.ref == 'refs/heads/main' && format('unit-tests-main-{0}', github.sha) || github.ref == 'refs/heads/develop' && format('unit-tests-develop-{0}', github.sha) || format('unit-tests-{0}', github.ref) }} cancel-in-progress: true + env: + GITHUB_TOKEN: ${{ secrets.SONARQUBE_GITHUB_API_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }} steps: - uses: actions/checkout@v3 with: @@ -48,12 +52,12 @@ jobs: emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true emulator-build: 7425822 - script: | + script: | ./gradlew gatherGplayDebugStringTemplates $CI_GRADLE_ARG_PROPERTIES ./gradlew unitTestsWithCoverage $CI_GRADLE_ARG_PROPERTIES ./gradlew instrumentationTestsWithCoverage $CI_GRADLE_ARG_PROPERTIES ./gradlew generateCoverageReport $CI_GRADLE_ARG_PROPERTIES -# NB: continue-on-error marks steps.tests.conclusion = 'success' but leaves stes.tests.outcome = 'failure' + # NB: continue-on-error marks steps.tests.conclusion = 'success' but leaves stes.tests.outcome = 'failure' - name: Run all the codecoverage tests at once (retry if emulator failed) uses: reactivecircus/android-emulator-runner@v2 if: always() && steps.tests.outcome == 'failure' # don't run if previous step succeeded. @@ -70,12 +74,11 @@ jobs: ./gradlew unitTestsWithCoverage $CI_GRADLE_ARG_PROPERTIES ./gradlew instrumentationTestsWithCoverage $CI_GRADLE_ARG_PROPERTIES ./gradlew generateCoverageReport $CI_GRADLE_ARG_PROPERTIES - - run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES - if: always() # we may have failed a previous step and retried, that's OK - env: - GITHUB_TOKEN: ${{ secrets.SONARQUBE_GITHUB_API_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }} + + # we may have failed a previous step and retried, that's OK + - name: Publish results to Sonar + if: ${{ env.GITHUB_TOKEN != '' && env.SONAR_TOKEN != '' && env.ORG_GRADLE_PROJECT_SONAR_LOGIN != '' }} + run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES - name: Format unit test results if: always() From 41f75eed508bf15bf08455f64ca92cae4f4d2aee Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 7 Sep 2022 11:49:31 +0200 Subject: [PATCH 2/4] Adding changelog entry --- changelog.d/7057.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7057.misc diff --git a/changelog.d/7057.misc b/changelog.d/7057.misc new file mode 100644 index 0000000000..ded1229319 --- /dev/null +++ b/changelog.d/7057.misc @@ -0,0 +1 @@ +CI: only run sonarqube task when token is known From b60c279c068ab10ff865fc2b47955d493d663775 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 7 Sep 2022 12:14:03 +0200 Subject: [PATCH 3/4] Re-adding "always()" expression in the condition --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 64f67a477e..2639612834 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -77,7 +77,7 @@ jobs: # we may have failed a previous step and retried, that's OK - name: Publish results to Sonar - if: ${{ env.GITHUB_TOKEN != '' && env.SONAR_TOKEN != '' && env.ORG_GRADLE_PROJECT_SONAR_LOGIN != '' }} + if: ${{ always() && env.GITHUB_TOKEN != '' && env.SONAR_TOKEN != '' && env.ORG_GRADLE_PROJECT_SONAR_LOGIN != '' }} run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES - name: Format unit test results From ff9add5a0c3b7083217c598727b9d678ed9c571f Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 7 Sep 2022 12:15:12 +0200 Subject: [PATCH 4/4] Re-adding env variables section inside the sonarqube job --- .github/workflows/tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2639612834..cd7e26f3cf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,10 +18,6 @@ jobs: concurrency: group: ${{ github.ref == 'refs/heads/main' && format('unit-tests-main-{0}', github.sha) || github.ref == 'refs/heads/develop' && format('unit-tests-develop-{0}', github.sha) || format('unit-tests-{0}', github.ref) }} cancel-in-progress: true - env: - GITHUB_TOKEN: ${{ secrets.SONARQUBE_GITHUB_API_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }} steps: - uses: actions/checkout@v3 with: @@ -77,6 +73,10 @@ jobs: # we may have failed a previous step and retried, that's OK - name: Publish results to Sonar + env: + GITHUB_TOKEN: ${{ secrets.SONARQUBE_GITHUB_API_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }} if: ${{ always() && env.GITHUB_TOKEN != '' && env.SONAR_TOKEN != '' && env.ORG_GRADLE_PROJECT_SONAR_LOGIN != '' }} run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES