Skip to content

Move codecov analysis to a dedicated workflow #2

Move codecov analysis to a dedicated workflow

Move codecov analysis to a dedicated workflow #2

Workflow file for this run

name: Code coverage
on:
push:
branches:
- master
pull_request:
defaults:
run:
shell: bash
permissions: {}
jobs:
codecov:
strategy:
fail-fast: false
matrix:
go-version: [1.24.x]
platform: [ubuntu-22.04]
permissions:
id-token: write # required for Vault
contents: read
runs-on: ${{ matrix.platform }}
if: ${{ github.ref == 'refs/heads/master' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Run tests with code coverage
run: |
go version
export GOMAXPROCS=2
echo "mode: set" > coverage.txt
for pkg in $(go list ./... | grep -v vendor); do
list=$(go list -test -f '{{ join .Deps "\n"}}' $pkg | grep go.k6.io/k6 | grep -v vendor || true)
if [ -n "$list" ]; then
list=$(echo "$list" | cut -f1 -d ' ' | sort -u | paste -sd, -)
fi
go test -p 2 -timeout 800s --coverpkg="$list" -coverprofile=$(echo $pkg | tr / -).coverage $pkg
done
grep -h -v "^mode:" *.coverage >> coverage.txt
rm -f *.coverage
# Sets CODECOV_TOKEN as an environment variable for the next step
- name: Get Codecov token
# Skip this step if the PR is from a fork, as we can't fetch secrets for forks.
if: github.event.pull_request.head.repo.full_name == github.repository
uses: grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets/v1.2.1
with:
repo_secrets: |
CODECOV_TOKEN=CODECOV_TOKEN:CODECOV_TOKEN
- name: Upload coverage to Codecov
if: github.event.pull_request.head.repo.full_name == github.repository
env:
CODECOV_BASH_VERSION: 1.0.1
CODECOV_BASH_SHA512SUM: d075b412a362a9a2b7aedfec3b8b9a9a927b3b99e98c7c15a2b76ef09862aeb005e91d76a5fd71b511141496d0fd23d1b42095f722ebcd509d768fba030f159e
run: |
curl -fsSLO "https://raw.githubusercontent.com/codecov/codecov-bash/${CODECOV_BASH_VERSION}/codecov"
echo "$CODECOV_BASH_SHA512SUM codecov" | sha512sum -c -
bash ./codecov
- name: Generate coverage HTML report
run: go tool cover -html=coverage.txt -o coverage.html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: test-coverage-report-${{ matrix.platform }}
path: coverage.html