Created
November 13, 2022 17:53
-
-
Save thomasedgesmith/ce8117246ee81b6d63e3f8fd1ed7380e to your computer and use it in GitHub Desktop.
Speeding up Phoenix (Elixir) GitHub Action CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: push | |
name: "CI" | |
env: | |
MIX_ENV: test | |
jobs: | |
dependencies: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
elixir: ['1.13.2'] | |
otp: ['24.1.7'] | |
steps: | |
- name: Cancel previous runs | |
uses: styfle/[email protected] | |
with: | |
access_token: ${{ github.token }} | |
- name: Checkout Github repo | |
uses: actions/checkout@v2 | |
- name: Sets up an Erlang/OTP environment | |
uses: erlef/setup-beam@v1 | |
with: | |
elixir-version: ${{ matrix.elixir }} | |
otp-version: ${{ matrix.otp }} | |
- name: Cache Elixir deps | |
id: elixir-deps-cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/deps | |
key: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-deps-${{ hashFiles('**/mix.lock') }} | |
restore-keys: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-deps- | |
- name: Cache Elixir build | |
id: elixir-build-cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/_build | |
key: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build-${{ hashFiles( '**/lib/**/*.{ex,eex}', '**/config/*.exs', '**/mix.exs' ) }} | |
restore-keys: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build-${{ hashFiles('**/mix.lock') }}- | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build- | |
- name: Install dependencies | |
if: steps.elixir-deps-cache.outputs.cache-hit != 'true' | |
run: | | |
mix local.rebar --force | |
mix local.hex --force | |
mix deps.get | |
- name: Compile dependencies | |
if: steps.elixir-deps-cache.outputs.cache-hit != 'true' | |
run: | | |
mix deps.get | |
mix deps.compile | |
mix compile --force --warnings-as-errors | |
static-code-analysis: | |
needs: dependencies | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
elixir: ['1.13.2'] | |
otp: ['24.1.7'] | |
steps: | |
- name: Cancel previous runs | |
uses: styfle/[email protected] | |
with: | |
access_token: ${{ github.token }} | |
- name: Checkout Github repo | |
uses: actions/checkout@v2 | |
- name: Sets up an Erlang/OTP environment | |
uses: erlef/setup-beam@v1 | |
with: | |
elixir-version: ${{ matrix.elixir }} | |
otp-version: ${{ matrix.otp }} | |
- name: Cache Elixir deps | |
id: elixir-deps-cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/deps | |
key: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-deps-${{ hashFiles('**/mix.lock') }} | |
restore-keys: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-deps- | |
- name: Cache Elixir build | |
id: elixir-build-cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/_build | |
key: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build-${{ hashFiles( '**/lib/**/*.{ex,eex}', '**/config/*.exs', '**/mix.exs' ) }} | |
restore-keys: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build-${{ hashFiles('**/mix.lock') }}- | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build- | |
- run: mix format --check-formatted | |
- run: mix credo | |
mix-test: | |
runs-on: ubuntu-latest | |
needs: dependencies | |
strategy: | |
matrix: | |
elixir: ['1.13.2'] | |
otp: ['24.1.7'] | |
services: | |
db: | |
image: postgres:14-alpine | |
ports: ['5432:5432'] | |
env: | |
POSTGRES_PASSWORD: postgres | |
steps: | |
- name: Cancel previous runs | |
uses: styfle/[email protected] | |
with: | |
access_token: ${{ github.token }} | |
- name: Checkout Github repo | |
uses: actions/checkout@v2 | |
- name: Sets up an Erlang/OTP environment | |
uses: erlef/setup-beam@v1 | |
with: | |
elixir-version: ${{ matrix.elixir }} | |
otp-version: ${{ matrix.otp }} | |
- name: Cache Elixir deps | |
id: elixir-deps-cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/deps | |
key: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-deps-${{ hashFiles('**/mix.lock') }} | |
restore-keys: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-deps- | |
- name: Cache Elixir build | |
id: elixir-build-cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/_build | |
key: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build-${{ hashFiles( '**/lib/**/*.{ex,eex}', '**/config/*.exs', '**/mix.exs' ) }} | |
restore-keys: | | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build-${{ hashFiles('**/mix.lock') }}- | |
v1-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-elixir-build- | |
- name: Run Tests | |
run: mix test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment