From ad8b62ca3364e8be1168bb920c4e1924480fe11a Mon Sep 17 00:00:00 2001 From: Chris Keele Date: Sat, 13 Apr 2024 23:42:59 -0500 Subject: [PATCH] Work on test coverage reporting. --- .github/workflows/test-matrix.yml | 47 ++++++++++++++++- .github/workflows/test-status.yml | 86 +++++++++++++++++++++++++++++++ .github/workflows/test-suite.yml | 5 +- mix.exs | 7 ++- 4 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/test-status.yml diff --git a/.github/workflows/test-matrix.yml b/.github/workflows/test-matrix.yml index 47cac5f..22676be 100644 --- a/.github/workflows/test-matrix.yml +++ b/.github/workflows/test-matrix.yml @@ -1,17 +1,22 @@ name: Test ❯ Matrix +# Runs tests and typechecking against the full battalion +# of supported OS, Erlang/OTP, and Elixir versions. on: + # Allow running from GitHub UI. workflow_dispatch: {} + # Run on all pull requests to important branches. pull_request: branches: - latest - release + # Run on all pushes to important branches. push: branches: - - release - latest + - release env: MIX_ENV: test @@ -418,8 +423,46 @@ jobs: elixir-version: ${{ matrix.elixir }} otp-version: ${{ matrix.otp }} + - name: Restore mix dependency installation cache + id: mix-deps-get-cache + uses: actions/cache@v4 + with: + path: | + deps + mix.lock + key: cache-${{ vars.CACHE_VERSION }}-os-${{ runner.os }}-${{ steps.beam-versions.outputs.otp-version }}-${{ steps.beam-versions.outputs.elixir-version }}-mix-deps-get-mix-exs-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.exs')) }} + + - name: Install mix dependencies + if: steps.mix-deps-get-cache.outputs.cache-hit != 'true' + run: mix deps.get + + - name: Restore mix dependency compilation cache + id: mix-deps-compile-cache + uses: actions/cache@v4 + with: + path: _build + key: cache-${{ vars.CACHE_VERSION }}-os-${{ runner.os }}-${{ steps.beam-versions.outputs.otp-version }}-${{ steps.beam-versions.outputs.elixir-version }}-mix-deps-compile-mix-lock-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Compile mix dependencies + if: steps.mix-deps-compile-cache.outputs.cache-hit != 'true' + run: mix deps.compile + + - name: Restore mix typecheck cache + id: mix-typecheck-cache + uses: actions/cache@v4 + with: + path: priv/plts + key: cache-${{ vars.CACHE_VERSION }}-os-${{ runner.os }}-${{ steps.beam-versions.outputs.otp-version }}-${{ steps.beam-versions.outputs.elixir-version }}-mix-typecheck + + - name: Setup typechecking + if: steps.mix-typecheck-cache.outputs.cache-hit != 'true' + run: mix typecheck.build-cache + + - name: Run typecheck tasks + run: mix typecheck + results: - name: Test Matrix Action Results + name: Test Matrix Results runs-on: ubuntu-22.04 if: ${{ always() }} diff --git a/.github/workflows/test-status.yml b/.github/workflows/test-status.yml new file mode 100644 index 0000000..e7110d8 --- /dev/null +++ b/.github/workflows/test-status.yml @@ -0,0 +1,86 @@ +name: Test ❯ Status +# Runs tests with coverage and updates related systems. + +on: + # Allow running from GitHub UI. + workflow_dispatch: {} + + # Update status on all pull requests to important branches. + push: + branches: + - latest + - release + + # Update status on all pushes to important branches. + pull_request: + branches: + - latest + - release + +env: + MIX_ENV: test + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +concurrency: + group: test-status-${{ github.ref }} + cancel-in-progress: true + +jobs: + status: + if: github.event_name == 'push' || github.event.pull_request_target.merged == true + name: Reporting Test Suite Status + runs-on: ${{ vars.PREFERRED_OS }} + + steps: + - uses: actions/checkout@v4 + + - name: Install Erlang & Elixir + id: beam-versions + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ vars.PREFERRED_ELIXIR }} + otp-version: ${{ vars.PREFERRED_OTP }} + + - name: Restore mix dependency installation cache + id: mix-deps-get-cache + uses: actions/cache@v4 + with: + path: | + deps + mix.lock + key: cache-${{ vars.CACHE_VERSION }}-os-${{ runner.os }}-${{ steps.beam-versions.outputs.otp-version }}-${{ steps.beam-versions.outputs.elixir-version }}-mix-deps-get-mix-exs-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.exs')) }} + + - name: Install mix dependencies + if: steps.mix-deps-get-cache.outputs.cache-hit != 'true' + run: mix deps.get + + - name: Restore mix dependency compilation cache + id: mix-deps-compile-cache + uses: actions/cache@v4 + with: + path: _build + key: cache-${{ vars.CACHE_VERSION }}-os-${{ runner.os }}-${{ steps.beam-versions.outputs.otp-version }}-${{ steps.beam-versions.outputs.elixir-version }}-mix-deps-compile-mix-lock-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Compile mix dependencies + if: steps.mix-deps-compile-cache.outputs.cache-hit != 'true' + run: mix deps.compile + + - name: Report test suite coverage + run: mix test.coverage.report + + results: + name: Test Status Results + runs-on: ${{ vars.PREFERRED_OS }} + + if: ${{ always() }} + needs: + - status + + steps: + - name: Test Status Succeeded + if: ${{ needs.status.result == 'success' }} + run: exit 0 + + - name: Test Status Failed + if: ${{ needs.status.result == 'failure' }} + run: exit 1 diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index f003174..4976f9f 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -1,7 +1,10 @@ name: Test ❯ Suite +# Runs tests, typechecking, and linting. on: + # Allow running from GitHub UI. - workflow_dispatch + # Run on all pushes. - push env: @@ -146,7 +149,7 @@ jobs: continue-on-error: true results: - name: Test Suites Action Results + name: Test Suite Results runs-on: ubuntu-20.04 if: ${{ always() }} diff --git a/mix.exs b/mix.exs index f3095e1..0d63f61 100644 --- a/mix.exs +++ b/mix.exs @@ -128,7 +128,11 @@ defmodule Erlex.MixProject do "typecheck.build-cache": "dialyzer --plt --format dialyxir", "typecheck.clean": "dialyzer.clean", "typecheck.explain": "dialyzer.explain --format dialyxir", - "typecheck.run": "dialyzer --format dialyxir" + "typecheck.run": "dialyzer --format dialyxir", + + # Test tasks + "test.coverage": "coveralls", + "test.coverage.report": "coveralls.github" ] end @@ -153,6 +157,7 @@ defmodule Erlex.MixProject do defp deps() do [ # {:dialyxir, "~> 1.4", only: @dev_envs, runtime: false, override: true}, # Transative dependency on ErlEx + {:excoveralls, "~> 0.18", only: :test}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false} ] ++ deps(:credo) end