From b9ad9c1eec4270e7d8aabe583583e61e932f065e Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sat, 27 Apr 2024 22:30:15 +0100 Subject: [PATCH 1/7] Use Devel::Cover in CI --- .circleci/config.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 87bc8d437..320541bbf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,9 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference +--- +# Use the latest 2.1 version of CircleCI pipeline process engine. See: +# https://circleci.com/docs/2.0/configuration-reference version: 2.1 +orbs: + codecov: codecov/codecov@4.1.0 # Orchestrate or schedule a set of jobs workflows: docker-compose: @@ -47,7 +51,18 @@ jobs: - run: command: | pushd metacpan-docker - docker-compose exec -T api_test prove -lr --jobs 2 t + docker-compose exec -T api_test cpm install -g Devel::Cover + name: install Devel::Cover + - run: + command: | + pushd metacpan-docker + docker-compose exec -T api_test env HARNESS_PERL_SWITCHES=-MDevel::Cover prove -lr --jobs 2 t + name: run tests with coverage + - run: + command: | + pushd metacpan-docker + docker-compose exec -T api_test cover + name: generate coverage report - run: command: | pushd metacpan-docker @@ -56,3 +71,4 @@ jobs: docker ps -a | head name: docker-compose logs when: on_fail + - codecov/upload From 0429f55c7d482851616df0823d0a67dfb5e4dc5d Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sat, 27 Apr 2024 22:58:56 +0100 Subject: [PATCH 2/7] Upload coverage without using orb --- .circleci/config.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 320541bbf..c90f51716 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,8 +2,6 @@ # Use the latest 2.1 version of CircleCI pipeline process engine. See: # https://circleci.com/docs/2.0/configuration-reference version: 2.1 -orbs: - codecov: codecov/codecov@4.1.0 # Orchestrate or schedule a set of jobs workflows: docker-compose: @@ -51,7 +49,7 @@ jobs: - run: command: | pushd metacpan-docker - docker-compose exec -T api_test cpm install -g Devel::Cover + docker-compose exec -T api_test cpm install -g Devel::Cover Devel::Cover::Report::Codecov Devel::Cover::Report::Codecovbash name: install Devel::Cover - run: command: | @@ -63,6 +61,11 @@ jobs: pushd metacpan-docker docker-compose exec -T api_test cover name: generate coverage report + - run: + command: | + pushd metacpan-docker + docker-compose exec -T api_test cover -report codecov + name: upload coverage report - run: command: | pushd metacpan-docker @@ -71,4 +74,3 @@ jobs: docker ps -a | head name: docker-compose logs when: on_fail - - codecov/upload From 35a9cbd4bbce870f34980cfbca8418b2ac7a3120 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sun, 28 Apr 2024 09:55:37 +0100 Subject: [PATCH 3/7] Ensure some CircleCI env vars are available inside container before trying to ship report --- .circleci/config.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c90f51716..4212dff14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,15 @@ jobs: - run: command: | pushd metacpan-docker - docker-compose exec -T api_test cover -report codecov + docker-compose exec -T \ + -e CIRCLE_PROJECT_USERNAME="$CIRCLE_PROJECT_USERNAME" \ + -e CIRCLE_PROJECT_REPONAME="$CIRCLE_PROJECT_REPONAME" \ + -e CIRCLE_BUILD_NUM="$CIRCLE_BUILD_NUM" \ + -e CIRCLE_NODE_INDEX="$CIRCLE_NODE_INDEX" \ + -e CIRCLE_SHA1="$CIRCLE_SHA1" \ + -e CIRCLE_BRANCH="$CIRCLE_BRANCH" \ + -e CIRCLE_PR_NUMBER="$CIRCLE_PR_NUMBER" \ + api_test cover -report codecov name: upload coverage report - run: command: | From f26395a4c3e8c34e367fa2de76044c3ea62344da Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sun, 28 Apr 2024 10:08:03 +0100 Subject: [PATCH 4/7] Switch CircleCI resource class from medium to large --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4212dff14..06b4cd26f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ workflows: jobs: build-and-test: machine: true - resource_class: medium + resource_class: large steps: - run: name: docker-compose version From c82120d48ee8315c5b8bd2918dc367d66cc22f07 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sun, 28 Apr 2024 11:15:24 +0100 Subject: [PATCH 5/7] Upload coverage report from outside of the container --- .circleci/config.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 06b4cd26f..7c9daa8d6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -63,16 +63,11 @@ jobs: name: generate coverage report - run: command: | - pushd metacpan-docker - docker-compose exec -T \ - -e CIRCLE_PROJECT_USERNAME="$CIRCLE_PROJECT_USERNAME" \ - -e CIRCLE_PROJECT_REPONAME="$CIRCLE_PROJECT_REPONAME" \ - -e CIRCLE_BUILD_NUM="$CIRCLE_BUILD_NUM" \ - -e CIRCLE_NODE_INDEX="$CIRCLE_NODE_INDEX" \ - -e CIRCLE_SHA1="$CIRCLE_SHA1" \ - -e CIRCLE_BRANCH="$CIRCLE_BRANCH" \ - -e CIRCLE_PR_NUMBER="$CIRCLE_PR_NUMBER" \ - api_test cover -report codecov + pushd metacpan-docker/src/metacpan-api + sudo apt install cpanminus + sudo cpanm --notest Devel::Cover Devel::Cover::Report::Codecov Devel::Cover::Report::Codecovbash + sudo chown -R circleci.circleci cover_db + cover -report codecov -ignore etc/metacpan.pl name: upload coverage report - run: command: | From 0e2cb0e9fa5d11172ffafa034d12978aef3aa443 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sun, 28 Apr 2024 11:24:27 +0100 Subject: [PATCH 6/7] Ignore more files when running coverage --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7c9daa8d6..020adccfa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,7 +54,7 @@ jobs: - run: command: | pushd metacpan-docker - docker-compose exec -T api_test env HARNESS_PERL_SWITCHES=-MDevel::Cover prove -lr --jobs 2 t + docker-compose exec -T api_test env HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,^t/|^test-data/|^etc/" prove -lr --jobs 2 t name: run tests with coverage - run: command: | @@ -67,7 +67,7 @@ jobs: sudo apt install cpanminus sudo cpanm --notest Devel::Cover Devel::Cover::Report::Codecov Devel::Cover::Report::Codecovbash sudo chown -R circleci.circleci cover_db - cover -report codecov -ignore etc/metacpan.pl + cover -report codecov name: upload coverage report - run: command: | From 74eb5a406cb6cffe616fada245c182bb5d68262e Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Sun, 28 Apr 2024 12:06:20 +0100 Subject: [PATCH 7/7] Don't build coverage report twice --- .circleci/config.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 020adccfa..a2f64e547 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,21 +46,26 @@ jobs: pushd metacpan-docker ./src/metacpan-api/wait-for-es.sh http://localhost:9200 elasticsearch_test -- name: wait for ES + # We are running coverage inside the container, but creating the report + # from outside of the container, so Devel::Cover is installed twice. We + # are relying on environment variables from the host to be available when + # we publish the report, so we publish from the host rather than trying + # to propagate env variables to the container. There is a CircleCI orb + # that can publish the report for us, but it is hard to debug. I had to + # set up the following config in order to debug the orb, so we may as + # well keep it around for now. - run: command: | pushd metacpan-docker - docker-compose exec -T api_test cpm install -g Devel::Cover Devel::Cover::Report::Codecov Devel::Cover::Report::Codecovbash + docker-compose exec -T api_test cpm install -g Devel::Cover name: install Devel::Cover - run: command: | pushd metacpan-docker docker-compose exec -T api_test env HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,^t/|^test-data/|^etc/" prove -lr --jobs 2 t name: run tests with coverage - - run: - command: | - pushd metacpan-docker - docker-compose exec -T api_test cover - name: generate coverage report + # The report ends up being owned by root. We need to chown it so that + # the cover command can make changes to it. - run: command: | pushd metacpan-docker/src/metacpan-api