From 418746c08759aebc101c27782aa18edb02392e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Thu, 27 Jun 2024 23:52:40 +0200 Subject: [PATCH] chore: split Elixir tasks Split CI tasks related to Elixir to improve build times by parallelizing different steps. --- .github/workflows/elixir.yml | 162 +++++++++++++++++++++++++++ .github/workflows/staging_linter.yml | 60 ---------- mix.exs | 2 +- 3 files changed, 163 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/elixir.yml delete mode 100644 .github/workflows/staging_linter.yml diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml new file mode 100644 index 00000000..cc18f954 --- /dev/null +++ b/.github/workflows/elixir.yml @@ -0,0 +1,162 @@ +name: Elixir tests +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} + +jobs: + deps: + name: Fetch deps + runs-on: u22-arm-runner + + steps: + - uses: actions/checkout@v4 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '25.3.2.7' + elixir-version: '1.17' + - name: Cache Mix + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-mix- + - name: Install dependencies + run: | + mix local.hex --force + mix local.rebar --force + mix deps.get + + format: + name: Formatting checks + runs-on: u22-arm-runner + needs: [deps] + + steps: + - uses: actions/checkout@v4 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '25.3.2.7' + elixir-version: '1.17' + - name: Cache Mix + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-mix- + - name: Run format check + run: mix format --check-formatted + + credo: + name: Code style + runs-on: u22-arm-runner + needs: [deps] + + steps: + - uses: actions/checkout@v4 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '25.3.2.7' + elixir-version: '1.17' + - name: Cache Mix + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-mix- + - run: mix deps.compile credo --include-children + - name: Credo checks + run: mix credo --strict --mute-exit-status + + tests: + name: Run tests + runs-on: u22-arm-runner + needs: [deps] + + steps: + - uses: actions/checkout@v4 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '25.3.2.7' + elixir-version: '1.17' + - name: Cache Mix + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-mix- + - name: Cache Build + uses: actions/cache@v3 + with: + path: _build + key: ${{ runner.os }}-build-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-build- + - name: Set up Rust + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - name: Compile + env: + MIX_ENV: test + run: mix compile + - name: Set up Postgres + run: docker-compose -f ./docker-compose.db.yml up -d + - name: Run main database migrations + run: mix ecto.migrate --prefix _supavisor --log-migrator-sql + - name: Start epmd + run: epmd -daemon + - name: Run tests + run: mix test + + dialyzer: + name: Dialyze + runs-on: u22-arm-runner + needs: [deps] + + steps: + - uses: actions/checkout@v4 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '25.3.2.7' + elixir-version: '1.17' + - name: Cache Mix + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: | + ${{ runner.os }}-mix- + - name: Set up Rust + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - name: Retrieve PLT Cache + uses: actions/cache@v3 + id: plt-cache + with: + path: priv/plts + key: ${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + - name: Create PLTs + if: steps.plt-cache.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix dialyzer.build + - name: Run dialyzer + run: mix dialyzer diff --git a/.github/workflows/staging_linter.yml b/.github/workflows/staging_linter.yml deleted file mode 100644 index eff46c84..00000000 --- a/.github/workflows/staging_linter.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Staging Formatting Checks -on: - pull_request: - branches: - - main -env: - SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} -jobs: - format: - name: Formatting Checks - runs-on: u22-arm-runner - - steps: - - uses: actions/checkout@v4 - - name: Setup Elixir - uses: erlef/setup-beam@v1 - with: - otp-version: '25.3.2.7' - elixir-version: '1.17' - - name: Set up Rust - uses: dtolnay/rust-toolchain@v1 - with: - toolchain: stable - - name: Cache Mix - uses: actions/cache@v3 - with: - path: deps - key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - restore-keys: | - ${{ runner.os }}-mix- - - name: Install dependencies - run: | - mix local.hex --force - mix local.rebar --force - mix deps.get - - name: Run format check - run: mix format --check-formatted - - name: Credo checks - run: mix credo --strict --mute-exit-status - - name: Set up Postgres - run: docker-compose -f ./docker-compose.db.yml up -d - - name: Run main database migrations - run: mix ecto.migrate --prefix _supavisor --log-migrator-sql - - name: Retrieve PLT Cache - uses: actions/cache@v3 - id: plt-cache - with: - path: priv/plts - key: ${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - - name: Create PLTs - if: steps.plt-cache.outputs.cache-hit != 'true' - run: | - mkdir -p priv/plts - mix dialyzer.build - - name: Run dialyzer - run: mix dialyzer - - name: Start epmd - run: epmd -daemon - - name: Run tests - run: mix test diff --git a/mix.exs b/mix.exs index b079454b..c34ededf 100644 --- a/mix.exs +++ b/mix.exs @@ -50,7 +50,7 @@ defmodule Supavisor.MixProject do {:joken, "~> 2.5.0"}, {:cloak_ecto, "~> 1.2.0"}, {:meck, "~> 0.9.2", only: :test}, - {:credo, "~> 1.6.4", only: [:dev, :test], runtime: false}, + {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.1.0", only: [:dev], runtime: false}, {:benchee, "~> 1.1.0", only: :dev}, {:prom_ex, "~> 1.8.0"},