Skip to content

Commit

Permalink
feat: 🎸 Add Codecov token on package and template
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abelsiqueira committed Jun 4, 2024
1 parent 13f2ce6 commit 2eda556
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/ReusableTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
3 changes: 3 additions & 0 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/TestOnPRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ jobs:
version: "1"
arch: x64
allow_failure: false
run_codecov: true
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
16 changes: 16 additions & 0 deletions docs/src/10-full-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://codecov.io> 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.
Expand Down
10 changes: 10 additions & 0 deletions template/.github/workflows/ReusableTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
3 changes: 3 additions & 0 deletions template/.github/workflows/Test.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test on PRs

on:
pull_request:
Expand All @@ -24,3 +24,6 @@ jobs:
version: "1"
arch: x64
allow_failure: false
run_codecov: true
secrets:
codecov_token: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %}

0 comments on commit 2eda556

Please sign in to comment.