Skip to content

Instantly share code, notes, and snippets.

@ericr3r
Created March 6, 2025 01:07
Show Gist options
  • Save ericr3r/f7f1c0d0e4903a06c5fbed529015141b to your computer and use it in GitHub Desktop.
Save ericr3r/f7f1c0d0e4903a06c5fbed529015141b to your computer and use it in GitHub Desktop.
name: CI/CD Elixir
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
env:
ELIXIR_VERSION: v1.16-otp-26
OTP_VERSION: OTP-26.0
jobs:
ci:
runs-on: ubuntu-latest
name: Compile
env:
MIX_ENV: test
ImageOS: ubuntu22
steps:
- uses: actions/checkout@v4
- name: Setup Elixir
uses: erlef/[email protected]
with:
elixir-version: ${{ env.ELIXIR_VERSION }}
otp-version: ${{ env.OTP_VERSION }}
- name: Cache deps directory
uses: actions/cache@v4
id: cache-deps
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-
- name: Get dependencies
if: steps.cache-deps.outputs.cache-hit != true
run: mix deps.get
- run: mix compile
- name: Check code if formatted
run: mix format --check-formatted
- name: Run tests
run: mix test --max-failures 1 --trace --warnings-as-errors
- name: Cache plt files
uses: actions/cache@v4
env:
EX_OTP_VERSIONS: ${{ steps.setup-beam.outputs.elixir-version }}
KEY_BASE: plt-${{ runner.os }}-${{ env.EX_OTP_VERSIONS }}
with:
path: |
priv/plts
key: |
${{ env.KEY_BASE }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ env.KEY_BASE }}-
- name: Dialyzer static analysis
run: mix dialyzer --format github
- name: Check unused dependencies
run: mix deps.unlock --check-unused
build-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
needs: ci
name: Build Docker image & push to ghcr.io
steps:
- uses: actions/checkout@v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/ericr3r/kanban
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=pr
type=sha,format=short
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:qemu-v7.0.0-28
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
push: true
build-args: |
ELIXIR_VERSION=${{ env.ELIXIR_VERSION }}
OTP_VERSION=${{ env.ERLANG_VERSION }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment