From 2eda556e536da41c5a122189e8624235aaa8a734 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Tue, 4 Jun 2024 16:26:16 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20Codecov=20token=20?= =?UTF-8?q?on=20package=20and=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add CODECOV_TOKEN to the tests. This is done via the reusable workflow secrets key. This is done both for the package and for the template. Add information to the full guide on how to add a CODECOV_TOKEN to your repo. ✅ Closes: #101, #150 --- .github/workflows/ReusableTest.yml | 10 ++++++++++ .github/workflows/Test.yml | 3 +++ .github/workflows/TestOnPRs.yml | 3 +++ docs/src/10-full-guide.md | 16 ++++++++++++++++ template/.github/workflows/ReusableTest.yml | 10 ++++++++++ template/.github/workflows/Test.yml.jinja | 3 +++ ...lifiedPRTest %}TestOnPRs.yml{% endif %}.jinja | 5 ++++- 7 files changed, 49 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ReusableTest.yml b/.github/workflows/ReusableTest.yml index 00eff2b1..a27ee8f1 100644 --- a/.github/workflows/ReusableTest.yml +++ b/.github/workflows/ReusableTest.yml @@ -19,6 +19,13 @@ on: required: false type: boolean default: false + run_codecov: + required: false + type: boolean + default: false + secrets: + codecov_token: + required: true jobs: test: @@ -44,6 +51,9 @@ jobs: env: TMPDIR: "${{ runner.temp }}" - uses: julia-actions/julia-processcoverage@v1 + if: ${{ inputs.run_codecov }} - uses: codecov/codecov-action@v4 + if: ${{ inputs.run_codecov }} with: file: lcov.info + token: ${{ secrets.codecov_token }} diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index ff040a9e..8feb7ebd 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -15,6 +15,9 @@ jobs: version: ${{ matrix.version }} arch: ${{ matrix.arch }} allow_failure: ${{ matrix.allow_failure }} + run_codecov: ${{ matrix.version == "1" && matrix.os == "ubuntu-latest" }} + secrets: + codecov_token: ${{ secrets.CODECOV_TOKEN }} strategy: fail-fast: false matrix: diff --git a/.github/workflows/TestOnPRs.yml b/.github/workflows/TestOnPRs.yml index 609c7408..2bba72bc 100644 --- a/.github/workflows/TestOnPRs.yml +++ b/.github/workflows/TestOnPRs.yml @@ -24,3 +24,6 @@ jobs: version: "1" arch: x64 allow_failure: false + run_codecov: true + secrets: + codecov_token: ${{ secrets.CODECOV_TOKEN }} diff --git a/docs/src/10-full-guide.md b/docs/src/10-full-guide.md index 02180b5b..7ce37d22 100644 --- a/docs/src/10-full-guide.md +++ b/docs/src/10-full-guide.md @@ -78,6 +78,22 @@ julia> DocumenterTools.genkeys(user="UserName", repo="PackageName.jl") Follow the instruction in the terminal. +### Enable Codecov for code coverage + +If you don't have a Codecov account, go to and create one now. +After creating an account and logging in, you will see your main page with a list of your packages. +Select the one that you are creating, it will open a configuration page. + +On the configuration page, select "Using GitHub Actions" as your CI. +The first step in the list given you the `CODECOV_TOKEN`. Click on the "repository secret" link on that page. +It should lead you to the GitHub settings > secrets and variables > actions, under a "New secret" screen. +Write `CODECOV_TOKEN` on the "Name" field and paste the token that you see on codecov on the "Secret" field. +Click "Add secret". + +Step 2 is not necessary because it is already present in the template. + +The next time that the tests are run, the coverage page will be updated, and the badge will be fixed. + ### Add key for Copier.yml workflow (or delete it) You can reapply the template in the future. This is normally a manual job, specially because normally there are conflicts. diff --git a/template/.github/workflows/ReusableTest.yml b/template/.github/workflows/ReusableTest.yml index a528f0b4..12431f28 100644 --- a/template/.github/workflows/ReusableTest.yml +++ b/template/.github/workflows/ReusableTest.yml @@ -19,6 +19,13 @@ on: required: false type: boolean default: false + run_codecov: + required: false + type: boolean + default: false + secrets: + codecov_token: + required: true jobs: test: @@ -37,6 +44,9 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 + if: ${{ inputs.run_codecov }} - uses: codecov/codecov-action@v4 + if: ${{ inputs.run_codecov }} with: file: lcov.info + token: ${{ secrets.codecov_token }} diff --git a/template/.github/workflows/Test.yml.jinja b/template/.github/workflows/Test.yml.jinja index f5873667..5318fba5 100644 --- a/template/.github/workflows/Test.yml.jinja +++ b/template/.github/workflows/Test.yml.jinja @@ -23,6 +23,9 @@ jobs: version: {% raw %}${{ matrix.version }}{% endraw %} arch: {% raw %}${{ matrix.arch }}{% endraw %} allow_failure: {% raw %}${{ matrix.allow_failure }}{% endraw %} + run_codecov: {% raw %}${{ matrix.version == "1" && matrix.os == "ubuntu-latest" }}{% endraw %} + secrets: + codecov_token: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %} strategy: fail-fast: false matrix: diff --git a/template/.github/workflows/{% if SimplifiedPRTest %}TestOnPRs.yml{% endif %}.jinja b/template/.github/workflows/{% if SimplifiedPRTest %}TestOnPRs.yml{% endif %}.jinja index 0ccf4d74..71e30189 100644 --- a/template/.github/workflows/{% if SimplifiedPRTest %}TestOnPRs.yml{% endif %}.jinja +++ b/template/.github/workflows/{% if SimplifiedPRTest %}TestOnPRs.yml{% endif %}.jinja @@ -1,4 +1,4 @@ -name: Test +name: Test on PRs on: pull_request: @@ -24,3 +24,6 @@ jobs: version: "1" arch: x64 allow_failure: false + run_codecov: true + secrets: + codecov_token: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %}