From 56ef52d64b708da6030172686ce0bccea79693c4 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 13 Jun 2024 13:25:30 +0200 Subject: [PATCH 1/6] Upgrade actions --- .github/workflows/linter.yml | 4 ++-- .github/workflows/publish-test-results.yml | 4 ++-- .github/workflows/test.yml | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 9b1d3fe..e27ef89 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -40,7 +40,7 @@ jobs: # Checkout the code base # ########################## - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # Full git history is needed to get a proper # list of changed files within `super-linter` @@ -50,7 +50,7 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: github/super-linter/slim@v5 + uses: github/super-linter/slim@v6 env: VALIDATE_ALL_CODEBASE: false DEFAULT_BRANCH: main diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 7740a7f..02f5ddd 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -26,8 +26,8 @@ jobs: unzip -d "$name" "$name.zip" done - name: "Publish test results" - uses: EnricoMi/publish-unit-test-result-action/composite@v1 + uses: EnricoMi/publish-unit-test-result-action@v2 with: commit: ${{ github.event.workflow_run.head_sha }} check_name: "Test results" - files: artifacts/**/*-results.xml \ No newline at end of file + files: artifacts/**/*-results.xml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b34d47d..9ea2bcc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,10 @@ jobs: python-version: ["3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' @@ -43,9 +43,9 @@ jobs: - name: Upload test reports (${{ matrix.python-version }}) if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: reports + name: reports-${{ matrix.python-version }} path: | reports/**/* From 33f3d53659052f618868cca8beace420b21e8b20 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 13 Jun 2024 13:27:33 +0200 Subject: [PATCH 2/6] Move codecov upload to publish tests workflow --- .github/workflows/publish-test-results.yml | 20 ++++++++++++++++++-- .github/workflows/test.yml | 7 ------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 02f5ddd..ec1cad8 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -1,4 +1,4 @@ -name: Publish test results +name: Publish test and coverage results on: workflow_run: @@ -8,11 +8,19 @@ on: jobs: publish-test-results: - name: "Publish test results" + name: "Publish test and coverage results" runs-on: ubuntu-latest if: github.event.workflow_run.conclusion != 'skipped' steps: + # Checking out the repo is necessary codecov/codecov-action@v4 to work properly + # Codecov requires source code to process the coverage file and generate coverage + # reports + - name: Checkout Code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_sha }} + - name: Download and Extract Artifacts env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} @@ -25,9 +33,17 @@ jobs: gh api $url > "$name.zip" unzip -d "$name" "$name.zip" done + - name: "Publish test results" uses: EnricoMi/publish-unit-test-result-action@v2 with: commit: ${{ github.event.workflow_run.head_sha }} check_name: "Test results" files: artifacts/**/*-results.xml + + - name: "Upload coverage to Codecov" + if: github.repository_owner == 'Uninett' + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} # not required for forks of public repos diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ea2bcc..416587f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,10 +48,3 @@ jobs: name: reports-${{ matrix.python-version }} path: | reports/**/* - - - name: "Upload coverage to Codecov" - if: github.repository_owner == 'Uninett' - uses: codecov/codecov-action@v4 - with: - fail_ci_if_error: true - token: ${{ secrets.CODECOV_TOKEN }} # not required for forks of public repos From 4c84d24a6579476cd4446990b6acc1e91b71496d Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 13 Jun 2024 13:31:19 +0200 Subject: [PATCH 3/6] Use coverage from all python versions --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 416587f..cf16de8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,8 +9,6 @@ jobs: test: name: "Python ${{ matrix.python-version }}" runs-on: ubuntu-latest - env: - USING_COVERAGE: '3.11' strategy: max-parallel: 4 From d5217a416be89b0226ba96e74a2f981f413038c2 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 13 Jun 2024 13:35:06 +0200 Subject: [PATCH 4/6] Upload PR number and base SHA as artifact For later use in configuring codecov --- .github/workflows/test.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf16de8..52dd5a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,8 @@ jobs: python-version: ["3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -46,3 +47,24 @@ jobs: name: reports-${{ matrix.python-version }} path: | reports/**/* + + upload-pr-number-base-sha: + name: Save PR number and base SHA in artifact + runs-on: ubuntu-latest + if: ${{ github.event.number && always() }} + env: + PR_NUMBER: ${{ github.event.number }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + steps: + - name: Make PR number file + run: | + mkdir -p ./extra + echo $PR_NUMBER > ./extra/pr_number + - name: Make base SHA file + run: | + echo $BASE_SHA > ./extra/base_sha + - name: Upload PR number file and base SHA file + uses: actions/upload-artifact@v4 + with: + name: extra + path: extra/ From be326fd4ace02d500e4beb65b9c2eec1950ed2e0 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 13 Jun 2024 13:38:23 +0200 Subject: [PATCH 5/6] Only publish test results/coverage if Uninett repo When running this workflow in a fork context we do not have the necessary permissions --- .github/workflows/publish-test-results.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index ec1cad8..7464fee 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -10,7 +10,7 @@ jobs: publish-test-results: name: "Publish test and coverage results" runs-on: ubuntu-latest - if: github.event.workflow_run.conclusion != 'skipped' + if: github.event.workflow_run.conclusion != 'skipped' && github.repository_owner == 'Uninett' steps: # Checking out the repo is necessary codecov/codecov-action@v4 to work properly @@ -42,7 +42,6 @@ jobs: files: artifacts/**/*-results.xml - name: "Upload coverage to Codecov" - if: github.repository_owner == 'Uninett' uses: codecov/codecov-action@v4 with: fail_ci_if_error: true From 079b385b081284a898c2b860c3fd47807d2be3df Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 13 Jun 2024 13:39:20 +0200 Subject: [PATCH 6/6] Use artifacts to configure codecov --- .github/workflows/publish-test-results.yml | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml index 7464fee..9d328c5 100644 --- a/.github/workflows/publish-test-results.yml +++ b/.github/workflows/publish-test-results.yml @@ -41,8 +41,31 @@ jobs: check_name: "Test results" files: artifacts/**/*-results.xml + - name: Read PR number file + if: ${{ hashFiles('artifacts/extra/pr_number') != '' }} + run: | + pr_number=$(cat artifacts/extra/pr_number) + re='^[0-9]+$' + if [[ $pr_number =~ $re ]] ; then + echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV + fi + + - name: Read base SHA file + if: ${{ hashFiles('artifacts/extra/base_sha') != '' }} + run: | + base_sha=$(cat artifacts/extra/base_sha) + re='[0-9a-f]{40}' + if [[ $base_sha =~ $re ]] ; then + echo "BASE_SHA=$base_sha" >> $GITHUB_ENV + fi + - name: "Upload coverage to Codecov" uses: codecov/codecov-action@v4 with: fail_ci_if_error: true - token: ${{ secrets.CODECOV_TOKEN }} # not required for forks of public repos + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + override_branch: ${{ github.event.workflow_run.head_branch}} + override_commit: ${{ github.event.workflow_run.head_sha}} + commit_parent: ${{ env.BASE_SHA }} + override_pr: ${{ env.PR_NUMBER }}