From c614b0bc97c8b8ed98dc3888a8484ab41e81c12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 4 Dec 2022 15:50:53 +0100 Subject: [PATCH] Run test coverage just on the master branch Since we changed the way we integrate coveralls in commit 8ed8cc8b9, we're getting 6 additional checks displayed in our pull requests. We don't need these checks, and they only add noise. The only reason we use coveralls is to know the test coverage in our master branch. So we're changing the code so coveralls only runs on the master branch. There's also a chance that the test suite will be faster because it doesn't need to keep track of the coverage, although I haven't noticed any significant differences during my tests. I haven't found a more elegant way to say that a certain step should only be run on push on master, so I'm setting the environment variable we were already using. --- .github/workflows/tests.yml | 6 +++++- spec/rails_helper.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6597fc809..0d819d406 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,9 @@ on: permissions: contents: read +env: + TEST_COVERAGE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && 1 || '' }} + jobs: tests: runs-on: ubuntu-latest @@ -23,7 +26,6 @@ jobs: POSTGRES_USER: consul POSTGRES_PASSWORD: "" env: - TEST_COVERAGE: 1 PGUSER: consul POSTGRES_HOST: postgres RAILS_ENV: test @@ -54,6 +56,7 @@ jobs: KNAPSACK_PRO_LOG_LEVEL: info run: bin/knapsack_pro_rspec - name: Coveralls Parallel + if: ${{ env.TEST_COVERAGE == 1 }} uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -72,6 +75,7 @@ jobs: needs: tests steps: - name: Finish coveralls + if: ${{ env.TEST_COVERAGE == 1 }} uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a31152ef8..86c18dc52 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,5 +1,5 @@ ENV["RAILS_ENV"] ||= "test" -if ENV["TEST_COVERAGE"] +if ENV["TEST_COVERAGE"] && !ENV["TEST_COVERAGE"].empty? require "simplecov" require "simplecov-lcov" SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true