Skip to content

Commit

Permalink
ci: send code coverage to DeepSource
Browse files Browse the repository at this point in the history
* generate coverage in binary fmt
* update .gitignore
* publish textfmt artifacts ready to be applied in VSCode
* job_go_test: covermode=count
* job_compose_test: now builds with `-race`
    this makes the integration test only slightly slower (around +10%)
    unlike the abismal effect in unit test (10x)
  • Loading branch information
altergui committed Sep 20, 2023
1 parent 8ef1e6a commit 2fb60a7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 41 deletions.
137 changes: 96 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,61 @@ jobs:
env:
LOG_PANIC_ON_INVALIDCHARS: true # check that log lines contains no invalid chars (evidence of format mismatch)
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go environment
uses: actions/setup-go@v4
- uses: actions/checkout@v3
- uses: benjlevesque/[email protected] # sets env.SHA to the first 7 chars of github.sha
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- run: mkdir -p "$PWD/gocoverage-unit/"
- name: Run Go test (and collect code coverage)
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/dev' # quicker, non-race test in case it's a PR or push to dev
run: go test -coverprofile=unit.covdata.txt ./...
# quicker, non-race test in case it's a PR or push to dev
if: github.event_name == 'pull_request' ||
github.ref == 'refs/heads/dev'
run: go test ./...
-cover -covermode=count -args -test.gocoverdir="$PWD/gocoverage-unit/"
- name: Run Go test -race (and collect code coverage)
if: github.event_name == 'push' && github.ref != 'refs/heads/dev' # this is further limited to selected branches at the beginning of this file
run: go test -coverprofile=unit.covdata.txt -vet=off -timeout=15m -race ./... # note that -race can easily make the crypto stuff 10x slower
- name: Store code coverage artifact
# note that -race can easily make the crypto stuff 10x slower
# this is further limited to selected branches at the beginning of this file
if: github.event_name == 'push' &&
github.ref != 'refs/heads/dev'
run: go test ./...
-race -timeout=15m -vet=off
-cover -covermode=atomic -args -test.gocoverdir="$PWD/gocoverage-unit/"
- name: Store code coverage artifact (unit)
uses: actions/upload-artifact@v3
with:
name: unit-covdata
path: unit.covdata.txt
name: gocoverage-unit@${{ env.SHA }}
path: gocoverage-unit/

job_compose_test:
runs-on: [self-hosted, ci2-1]
steps:
- name: Check out the repo
uses: actions/checkout@v3
- uses: actions/checkout@v3
- uses: benjlevesque/[email protected] # sets env.SHA to the first 7 chars of github.sha
- name: Run compose script
env:
TESTSUITE_BUILD_TAG: ${{ github.sha }}
COMPOSE_PROJECT_NAME: testsuite_${{ github.run_id }} # unique name for docker-compose (needed for concurrent job runs)
COMPOSE_DVOTE_PORT_MAPPING: "9090" # this binds gateway0 to a random available port on docker host (needed for concurrent job runs)
COMPOSE_HOST_PATH: ${{ github.workspace }}/dockerfiles/testsuite
LOG_PANIC_ON_INVALIDCHARS: true # check that log lines contains no invalid chars (evidence of format mismatch)
GOCOVERDIR: "./gocoverage/" # collect code coverage when running binaries
GOCOVERDIR: "./gocoverage-integration/" # collect code coverage when running binaries
CONCURRENT: 1 # run all the start_test.sh tests concurrently
BUILDARGS: "-race" # this makes the integration test only slightly slower (around +10%) unlike the abismal effect in unit test (10x)
run: |
cd dockerfiles/testsuite && ./start_test.sh
- name: Store code coverage artifact
- name: Store code coverage artifact (integration)
uses: actions/upload-artifact@v3
with:
name: integration-covdata
path: dockerfiles/testsuite/gocoverage/covdata.txt
name: gocoverage-integration@${{ env.SHA }}
path: dockerfiles/testsuite/gocoverage-integration/

job_go_build_for_mac:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release')
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go environment
uses: actions/setup-go@v4
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Run go build for Mac
Expand All @@ -137,31 +144,67 @@ jobs:
# It's surprisingly hard with some deps like bazil.org/fuse.
GOOS=darwin go build ./...
job_upload_coverage:
name: Publish code coverage
runs-on: ubuntu-latest
call-docker-release:
name: Docker
needs: [job_go_checks, job_go_test, job_compose_test]
if: github.event_name == 'push' # this is limited to selected branches at the beginning of this file
uses: vocdoni/vocdoni-node/.github/workflows/docker-release.yml@main
secrets: inherit
with:
image-tag: ${{ github.ref_name }}

job_gocoverage_textfmt:
name: Convert coverage (bin->txt)
continue-on-error: true # never mark the whole CI as failed because of this job
needs: [job_go_test, job_compose_test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Fetch coverage (unit)
uses: actions/download-artifact@v3
- uses: benjlevesque/[email protected] # sets env.SHA to the first 7 chars of github.sha
- uses: actions/download-artifact@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: false
- name: Convert gocoverage format
run: |
go tool covdata textfmt -i=gocoverage-unit@${{ env.SHA }}/ \
-o gocoverage-unit@${{ env.SHA }}.txt
go tool covdata textfmt -i=gocoverage-integration@${{ env.SHA }}/ \
-o gocoverage-integration@${{ env.SHA }}.txt
go tool covdata textfmt -i=gocoverage-unit@${{ env.SHA }}/,gocoverage-integration@${{ env.SHA }}/ \
-o gocoverage-merged@${{ env.SHA }}.txt
# the merge might fail if unit ran with a different covermode than integration (set vs count vs atomic)
- name: Store code coverage artifact (all, textfmt)
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: unit-covdata
- name: Fetch coverage (integration)
uses: actions/download-artifact@v3
name: gocoverage-all-textfmt@${{ env.SHA }}
path: gocoverage-*.txt

job_gocoverage_coveralls:
name: Publish coverage (Coveralls)
runs-on: ubuntu-latest
needs: [job_gocoverage_textfmt]
continue-on-error: true # never mark the whole CI as failed because of this job
steps:
- uses: actions/checkout@v3
- uses: benjlevesque/[email protected] # sets env.SHA to the first 7 chars of github.sha
- uses: actions/download-artifact@v3
with:
name: integration-covdata

name: gocoverage-all-textfmt@${{ env.SHA }}
- name: Send coverage to coveralls.io (unit)
if: ${{ always() }}
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: unit.covdata.txt
path-to-profile: gocoverage-unit@${{ env.SHA }}.txt
flag-name: unit
parallel: true
- name: Send coverage to coveralls.io (integration)
if: ${{ always() }}
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: covdata.txt
path-to-profile: gocoverage-integration@${{ env.SHA }}.txt
flag-name: integration
parallel: true
- name: Tell coveralls.io we're done
Expand All @@ -170,11 +213,23 @@ jobs:
with:
parallel-finished: true

call-docker-release:
name: Docker
needs: [job_go_checks, job_go_test, job_compose_test]
if: github.event_name == 'push' # this is limited to selected branches at the beginning of this file
uses: vocdoni/vocdoni-node/.github/workflows/docker-release.yml@main
secrets: inherit
with:
image-tag: ${{ github.ref_name }}
job_gocoverage_deepsource:
name: Publish coverage (DeepSource)
runs-on: ubuntu-latest
needs: [job_gocoverage_textfmt]
continue-on-error: true # never mark the whole CI as failed because of this job
steps:
- uses: actions/checkout@v3
- uses: benjlevesque/[email protected] # sets env.SHA to the first 7 chars of github.sha
- uses: actions/download-artifact@v3
with:
name: gocoverage-all-textfmt@${{ env.SHA }}
- name: Send coverage to DeepSource
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
run: |
# Install the CLI
curl https://deepsource.io/cli | sh
# Send the report to DeepSource
./bin/deepsource report --analyzer test-coverage --key go --value-file gocoverage-merged@${{ env.SHA }}.txt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ zkCircuits

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
gocoverage*

# Docker files and dirs
env.local
Expand Down

0 comments on commit 2fb60a7

Please sign in to comment.