Skip to content

Commit

Permalink
ci(refactor): use composite action to avoid duplication in elixir wor…
Browse files Browse the repository at this point in the history
…kflow
  • Loading branch information
JakobLichterfeld committed Sep 19, 2024
1 parent 953ecdf commit 99682d7
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 114 deletions.
75 changes: 75 additions & 0 deletions .github/actions/setup-elixir-and-cache-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: "Setup Elixir and Cache Dependencies"
description: "Setup Elixir, OTP and cache dependencies"
inputs:
elixir-version:
description: "Elixir version"
required: false
default: "1.16.2"
otp-version:
description: "OTP version"
required: false
default: "26"
cache-name-deps:
description: "Cache name for dependencies"
required: true
cache-name-compiled:
description: "Cache name for compiled build"
required: true
mix-env:
description: "Mix environment"
required: false
default: "dev"
ELIXIR_ASSERT_TIMEOUT:
description: "Elixir assert timeout"
required: false
default: "1000"
outputs:
elixir-version:
description: "The Elixir version used in the setup"
value: ${{ steps.beam.outputs.elixir-version }}
otp-version:
description: "The OTP version used in the setup"
value: ${{ steps.beam.outputs.otp-version }}
runs:
using: "composite"
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup Elixir and OTP
id: beam
uses: erlef/setup-beam@b9c58b0450cd832ccdb3c17cc156a47065d2114f # v1.18.1
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: Cache deps
id: cache-deps
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: deps
key: ${{ runner.os }}-mix-${{ inputs.cache-name-deps }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ inputs.cache-name-deps }}-
- name: Cache compiled build
id: cache-build
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
_build
priv/cldr/locales
key: ${{ runner.os }}-mix-${{ inputs.cache-name-compiled }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ inputs.cache-name-compiled }}-
${{ runner.os }}-mix-
- name: Clean to rule out incremental build as a source of flakiness
if: github.run_attempt > 3
run: |
mix deps.clean --all
mix clean
shell: sh

- name: Install dependencies
run: mix deps.get
shell: sh
153 changes: 39 additions & 114 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,34 @@ on:
- "**/*"
- "!.github/**" # Important: Exclude PRs related to .github from auto-run

env:
CACHE_NAME_DEPS: cache-elixir-deps
CACHE_NAME_COMPILED_DEV: cache-compiled-dev-build
CACHE_NAME_COMPILED_TEST: cache-compiled-test-build
ELIXIR_ASSERT_TIMEOUT: 1000

jobs:
lint:
name: Lint (Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }})
name: Lint
runs-on: ubuntu-20.04

permissions:
contents: read

strategy:
matrix:
include:
- elixir: "1.16.2"
otp: "26"
lint: true

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- uses: erlef/setup-beam@b9c58b0450cd832ccdb3c17cc156a47065d2114f # v1.18.1
id: beam
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}

- name: Cache deps
id: cache-deps
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
- name: Cache compiled build
id: cache-build
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
env:
cache-name: cache-compiled-dev-build
- name: Setup Elixir and Cache Dependencies
id: setup-elixir-and-cache-deps
uses: ./.github/actions/setup-elixir-and-cache-deps
with:
path: |
_build
priv/cldr/locales
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
${{ runner.os }}-mix-
- name: Clean to rule out incremental build as a source of flakiness
if: github.run_attempt > 3
run: |
mix deps.clean --all
mix clean
shell: sh

- name: Restore PLT cache
id: plt_cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
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: Install dependencies
run: mix deps.get
cache-name-deps: ${{ env.CACHE_NAME_DEPS }}
cache-name-compiled: ${{ env.CACHE_NAME_COMPILED_DEV }}
mix-env: dev

- name: Compile without warnings
run: mix compile --warnings-as-errors
shell: sh

- name: Verify that POT files are up to date
run: mix gettext.extract --check-up-to-date
Expand All @@ -96,7 +52,18 @@ jobs:
- name: Check unused dependencies
run: mix deps.unlock --check-unused

- name: Create PLTs
- name: Restore PLT cache
id: plt_cache
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
key: |
${{ runner.os }}-${{ steps.setup-elixir-and-cache-deps.outputs.elixir-version }}-${{ steps.setup-elixir-and-cache-deps.outputs.otp-version }}-plt
restore-keys: |
${{ runner.os }}-${{ steps.setup-elixir-and-cache-deps.outputs.elixir-version }}-${{ steps.setup-elixir-and-cache-deps.outputs.otp-version }}-plt
path: |
priv/plts
- name: Create Persistent Lookup Tables (PLTs) for Dialyzer
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

Expand All @@ -106,27 +73,20 @@ jobs:
if: steps.plt_cache.outputs.cache-hit != 'true'
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
${{ runner.os }}-${{ steps.setup-elixir-and-cache-deps.outputs.elixir-version }}-${{ steps.setup-elixir-and-cache-deps.outputs.otp-version }}-plt
path: |
priv/plts
- name: Run dialyzer
- name: Run dialyzer for static analysis
run: mix dialyzer --format github

test:
name: Test (Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }})
name: Test
runs-on: ubuntu-20.04

permissions:
contents: read

strategy:
matrix:
include:
- elixir: "1.16.2"
otp: "26"
report_coverage: true

services:
db:
image: postgres:16
Expand All @@ -136,62 +96,27 @@ jobs:
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
MIX_ENV: test
ELIXIR_ASSERT_TIMEOUT: 1000

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- uses: erlef/setup-beam@b9c58b0450cd832ccdb3c17cc156a47065d2114f # v1.18.1
id: beam
- name: Setup Elixir and Cache Dependencies
id: setup-elixir-and-cache-deps
uses: ./.github/actions/setup-elixir-and-cache-deps
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
cache-name-deps: ${{ env.CACHE_NAME_DEPS }}
cache-name-compiled: ${{ env.CACHE_NAME_COMPILED_TEST }}
mix-env: test
ELIXIR_ASSERT_TIMEOUT: ${{ env.ELIXIR_ASSERT_TIMEOUT }}

- name: Cache deps
id: cache-deps
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
- name: Cache compiled build
id: cache-build
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
env:
cache-name: cache-compiled-test-build
with:
path: |
_build
priv/cldr/locales
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
${{ runner.os }}-mix-
- name: Clean to rule out incremental build as a source of flakiness
if: github.run_attempt > 3
run: |
mix deps.clean --all
mix clean
- name: Compile without warnings
run: mix compile --warnings-as-errors
shell: sh

- name: Install dependencies
run: mix deps.get

- name: Compile
run: mix compile

- name: Run tests
run: mix test --warnings-as-errors

- name: Check Coverage
if: github.ref == 'refs/heads/master' && matrix.report_coverage
if: github.ref == 'refs/heads/master'
run: mix coveralls.github
continue-on-error: true
env:
Expand Down

0 comments on commit 99682d7

Please sign in to comment.