Skip to content

Commit

Permalink
ci: integrate codecov and tests run (#8867)
Browse files Browse the repository at this point in the history
This avoids running tests twice
  • Loading branch information
alexgarel authored Aug 16, 2023
1 parent f6bdca1 commit a44f325
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 47 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/codecov.yml

This file was deleted.

21 changes: 17 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ on:
# - ".github/CODEOWNERS"
# - ".github/PULL_REQUEST_TEMPLATE.md"
# - ".editorconfig"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

# those are just until we de-activate their mandatory
Expand Down Expand Up @@ -101,8 +101,21 @@ jobs:
uses: ishworkh/docker-image-artifact-download@v1
with:
image: "openfoodfacts-server/backend:dev"
- name: test
run: make tests
- name: tests
run: |
make codecov_prepare
make COVER_OPTS='-e HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,tests/"' tests
- name: generate coverage results
# even if tests failed
if: always()
run: |
make coverage_txt
make codecov
- uses: codecov/codecov-action@v3
if: always()
with:
files: cover_db/codecov.json


tests_dev:
name: Test make dev
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ html/js/jquery*
html/js/*nivo-zoom*
html/js/sigma*

# coverage data
/cover_db

# Env files
.env*

Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ tail:
@echo "🥫 Reading logs (Apache2, Nginx) …"
tail -f logs/**/*

cover:
@echo "🥫 running …"
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb
${DOCKER_COMPOSE_TEST} run --rm backend perl -I/opt/product-opener/lib -I/opt/perl/local/lib/perl5 /opt/product-opener/scripts/build_lang.pl
${DOCKER_COMPOSE_TEST} run --rm -e HARNESS_PERL_SWITCHES="-MDevel::Cover" backend prove -l tests/unit
${DOCKER_COMPOSE_TEST} stop
codecov_prepare:
@echo "🥫 Preparing to run code coverage…"
mkdir -p cover_db
${DOCKER_COMPOSE_TEST} run --rm backend cover -delete
mkdir -p cover_db

codecov:
@echo "🥫 running …"
@echo "🥫 running cover to generate a report usable by codecov "
${DOCKER_COMPOSE_TEST} run --rm backend cover -report codecovbash

coverage_txt:
@echo "🥫 running cover to generate text report …"
${DOCKER_COMPOSE_TEST} run --rm backend cover

#----------#
Expand Down Expand Up @@ -239,10 +239,11 @@ lint: lint_perltidy

tests: build_lang_test unit_test integration_test

# add COVER_OPTS='-e HARNESS_PERL_SWITCHES="-MDevel::Cover"' if you want to trigger code coverage report generation
unit_test:
@echo "🥫 Running unit tests …"
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb
${DOCKER_COMPOSE_TEST} run -T --rm backend prove -l --jobs ${CPU_COUNT} -r tests/unit
${DOCKER_COMPOSE_TEST} run ${COVER_OPTS} -T --rm backend prove -l --jobs ${CPU_COUNT} -r tests/unit
${DOCKER_COMPOSE_TEST} stop
@echo "🥫 unit tests success"

Expand All @@ -253,7 +254,7 @@ integration_test:
# this is the place where variables are important
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron
# note: we need the -T option for ci (non tty environment)
${DOCKER_COMPOSE_TEST} exec -T backend prove -l -r tests/integration
${DOCKER_COMPOSE_TEST} exec ${COVER_OPTS} -T backend prove -l -r tests/integration
${DOCKER_COMPOSE_TEST} stop
@echo "🥫 integration tests success"

Expand Down Expand Up @@ -299,13 +300,15 @@ bash:

# check perl compiles, (pattern rule) / but only for newer files
%.pm %.pl: _FORCE
if [ -f $@ ]; then perl -c -CS -Ilib $@; else true; fi
@if [[ -f $@ ]]; then perl -c -CS -Ilib $@; else true; fi


# TO_CHECK look at changed files (compared to main) with extensions .pl, .pm, .t
# filter out obsolete scripts
# the ls at the end is to avoid removed files.
# the first commad is to check we have git (to avoid trying to run this line inside the container on check_perl*)
# We have to finally filter out "." as this will the output if we have no file
TO_CHECK=$(shell git diff origin/main --name-only | grep '.*\.\(pl\|pm\|t\)$$' | xargs ls -d 2>/dev/null | grep -v "^.$$" )
TO_CHECK=$(shell [ -x "`which git 2>/dev/null`" ] && git diff origin/main --name-only | grep '.*\.\(pl\|pm\|t\)$$' | grep -v "scripts/obsolete" | xargs ls -d 2>/dev/null | grep -v "^.$$" )

check_perl_fast:
@echo "🥫 Checking ${TO_CHECK}"
Expand Down

0 comments on commit a44f325

Please sign in to comment.