From 09f4c158aa2039b4d29c7a1315fa6367dbd915c1 Mon Sep 17 00:00:00 2001 From: Alex Pearwin Date: Wed, 25 Oct 2023 15:17:07 +0100 Subject: [PATCH] Add CI. --- .github/workflows/ci.yaml | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..cfc9402 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,79 @@ +# Inspired by a combination of: +# - https://github.com/rrrene/credo/blob/master/.github/workflows/ci-workflow.yml +# - https://elixirforum.com/t/using-github-action-cache/37922/2 +name: "Lint and test" +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-22.04 + env: + ImageOS: ubuntu22 + steps: + - uses: actions/checkout@v3 + - uses: erlef/setup-beam@v1 + id: beam + with: + otp-version: '25' + elixir-version: '1.15' + + # Dependencies. + - name: Restore dependencies cache + uses: actions/cache@v2 + id: deps_cache + with: + key: | + ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-deps + path: | + deps + - name: Download dependencies + run: mix deps.get + - name: Compile dependencies + run: mix deps.compile + + # Build. + - name: Restore build cache + uses: actions/cache@v2 + id: build_cache + with: + key: | + ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build + path: | + _build + - name: Compile project + run: mix compile --warnings-as-errors + + # Formatting, linting, and type checking. + - name: Check formatting + run: mix format --check-formatted + - name: Check lint + run: mix credo --strict + - name: Restore PLT cache + uses: actions/cache@v2 + id: plt_cache + with: + key: | + ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt + restore-keys: | + ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt + path: | + priv/plts + - name: Create PLTs + if: steps.plt_cache.outputs.cache-hit != 'true' + run: mix dialyzer --plt + - name: Check typespecs + run: mix dialyzer --format github + + # Tests. + - name: Check tests + run: mix test