Skip to content

Commit

Permalink
chore: split Elixir tasks
Browse files Browse the repository at this point in the history
Split CI tasks related to Elixir to improve build times by parallelizing
different steps.
  • Loading branch information
hauleth committed Jun 28, 2024
1 parent 76464ae commit c934dc0
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 68 deletions.
301 changes: 301 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
name: Elixir tests
on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
LANG: C.UTF-8
LC_ALL: C.UTF-8

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@v4
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 deps.get

compile-dev:
name: Compile project in dev env
runs-on: u22-arm-runner
needs: [deps]

env:
MIX_ENV: dev

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@v4
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@v4
with:
path: |
_build/${{ env.MIX_ENV }}
!_build/${{ env.MIX_ENV }}/lib/supavisor/native
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.MIX_ENV }}-
- name: Cache native
uses: actions/cache@v4
id: native-cache
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Set up Rust
uses: dtolnay/rust-toolchain@v1
if: steps.native-cache.outputs.cache-hit != 'true'
with:
toolchain: stable
- name: Cache native deps
uses: actions/cache@v4
if: steps.native-cache.outputs.cache-hit != 'true'
with:
path: |
_build/${{ env.MIX_ENV }}/lib/supavisor/native
key: ${{ runner.os }}-cargo-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/Cargo.lock')) }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.MIX_ENV }}-
- name: Compile
run: mix compile

compile-test:
name: Compile project in test env
runs-on: u22-arm-runner
needs: [deps]

env:
MIX_ENV: test

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@v4
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@v4
with:
path: |
_build/${{ env.MIX_ENV }}
!_build/${{ env.MIX_ENV }}/lib/supavisor/native
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.MIX_ENV }}-
- name: Cache native
uses: actions/cache@v4
id: native-cache
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Set up Rust
uses: dtolnay/rust-toolchain@v1
if: steps.native-cache.outputs.cache-hit != 'true'
with:
toolchain: stable
- name: Cache native deps
uses: actions/cache@v4
if: steps.native-cache.outputs.cache-hit != 'true'
with:
path: |
_build/${{ env.MIX_ENV }}/lib/supavisor/native
key: ${{ runner.os }}-cargo-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/Cargo.lock')) }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.MIX_ENV }}-
- name: Compile
run: mix compile

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@v4
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: [compile-dev]

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@v4
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@v4
with:
path: |
_build/dev
!_build/dev/lib/supavisor/native
key: ${{ runner.os }}-build-dev-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-dev-
- name: Cache native
uses: actions/cache@v4
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Cache native
uses: actions/cache@v4
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Credo checks
run: mix credo --strict --mute-exit-status

tests:
name: Run tests
runs-on: u22-arm-runner
needs: [compile-test]

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@v4
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@v4
with:
path: |
_build/test
!_build/test/lib/supavisor/native
key: ${{ runner.os }}-build-test-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-test-
- name: Cache native
uses: actions/cache@v4
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Set up Postgres
run: docker-compose -f ./docker-compose.db.yml up -d
- name: Start epmd
run: epmd -daemon
- name: Run tests
run: mix test

dialyzer:
name: Dialyze
runs-on: u22-arm-runner
needs: [compile-dev]

steps:
- uses: actions/checkout@v4
- name: Setup Elixir
id: beam
uses: erlef/setup-beam@v1
with:
otp-version: '25.3.2.7'
elixir-version: '1.17'
- name: Cache Mix
uses: actions/cache@v4
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@v4
with:
path: |
_build/dev
!_build/dev/lib/supavisor/native
key: ${{ runner.os }}-build-dev-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-dev-
- name: Cache native
uses: actions/cache@v4
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Retrieve PLT Cache
uses: actions/cache@v4
id: plt-cache
with:
path: _build/dev/*.plt
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
60 changes: 0 additions & 60 deletions .github/workflows/staging_linter.yml

This file was deleted.

10 changes: 7 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ defmodule Supavisor.MixProject do
def application do
[
mod: {Supavisor.Application, []},
extra_applications: [:logger, :runtime_tools, :os_mon, :ssl, :partisan]
extra_applications:
[:logger, :runtime_tools, :os_mon, :ssl, :partisan] ++ extra_applications(Mix.env())
]
end

defp extra_applications(:test), do: [:common_test]
defp extra_applications(_), do: []

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
Expand All @@ -50,8 +54,8 @@ 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},
{:dialyxir, "~> 1.1.0", only: [:dev], runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev], runtime: false},
{:benchee, "~> 1.1.0", only: :dev},
{:prom_ex, "~> 1.8.0"},
{:open_api_spex, "~> 3.16"},
Expand Down
Loading

0 comments on commit c934dc0

Please sign in to comment.