Skip to content

ci: add treefmt as code formatting multiplexer, refactor CI to avoid duplication, reorg CI into DevOps workflow #3471

ci: add treefmt as code formatting multiplexer, refactor CI to avoid duplication, reorg CI into DevOps workflow

ci: add treefmt as code formatting multiplexer, refactor CI to avoid duplication, reorg CI into DevOps workflow #3471

Workflow file for this run

name: Elixir CI
on:
push:
paths:
- "**/*"
- "!.github/**" # Important: Exclude PRs related to .github from auto-run
pull_request:
branches: ["master"]
paths:
- "**/*"
- "!.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:
check_paths:
uses: ./.github/workflows/check_paths.yml
verify_dependencies_and_static_analysis:
name: Verify dependencies, POT files, unused dependencies, static analysis
needs: check_paths
if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule'
runs-on: ubuntu-20.04
permissions:
contents: read
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Elixir and Cache Dependencies
id: setup-elixir-and-cache-deps
uses: ./.github/actions/setup-elixir-and-cache-deps
with:
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
- name: Spell check
uses: crate-ci/typos@c16dc8f5b4a7ad6211464ecf136c69c851e8e83c # v1.22.9
- name: Check formatting
run: mix format --check-formatted
- name: Check unused dependencies
run: mix deps.unlock --check-unused
- 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
- name: Save PLT cache
id: plt_cache_save
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
if: steps.plt_cache.outputs.cache-hit != 'true'
with:
key: |
${{ 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 for static analysis
run: mix dialyzer --format github
test:
name: Test
needs:
- check_paths
- verify_dependencies_and_static_analysis
if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'schedule'
runs-on: ubuntu-20.04
permissions:
contents: read
services:
db:
image: postgres:16
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Elixir and Cache Dependencies
id: setup-elixir-and-cache-deps
uses: ./.github/actions/setup-elixir-and-cache-deps
with:
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: Compile without warnings
run: mix compile --warnings-as-errors
shell: sh
- name: Run tests
run: mix test --warnings-as-errors
- name: Check Coverage
if: github.ref == 'refs/heads/master'
run: mix coveralls.github
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}