Last active
March 9, 2025 16:01
-
-
Save dkarter/3dba1a1e7b7c4a5c1bd3d740356fb8a3 to your computer and use it in GitHub Desktop.
Elixir 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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
compile: | |
name: Compile | |
runs-on: ubuntu-latest | |
env: | |
MIX_ENV: test | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Task | |
uses: arduino/setup-task@v2 | |
with: | |
# prevent rate limits by github: https://github.com/arduino/setup-task#repo-token | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup runtime deps with mise | |
uses: jdx/mise-action@v2 | |
- name: Cache deps/_build dirs | |
uses: actions/cache@v4 | |
id: cache-deps | |
with: | |
path: | | |
app/deps | |
app/_build | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/app/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: Install Hex | |
if: steps.cache-deps.outputs.cache-hit == 'true' | |
run: task ci:hex:install | |
- name: Get Deps | |
if: steps.cache-deps.outputs.cache-hit != 'true' | |
run: task ci:deps:get | |
- name: Compile | |
run: task ci:compile | |
- name: Xref cyclical compile deps | |
run: task ci:xref | |
- name: Test | |
run: task ci:test | |
# TODO: move similar steps to reusable actions | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
env: | |
MIX_ENV: test | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Task | |
uses: arduino/setup-task@v2 | |
with: | |
# prevent rate limits by github: https://github.com/arduino/setup-task#repo-token | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup runtime deps with mise | |
uses: jdx/mise-action@v2 | |
- name: Cache deps/_build dirs | |
uses: actions/cache@v4 | |
id: cache-deps | |
with: | |
path: | | |
app/deps | |
app/_build | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/app/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: Install Hex | |
if: steps.cache-deps.outputs.cache-hit == 'true' | |
run: task ci:hex:install | |
- name: Get Deps | |
if: steps.cache-deps.outputs.cache-hit != 'true' | |
run: task ci:deps:get | |
- name: Test | |
run: task ci:test | |
# TODO: move similar steps to reusable actions | |
format: | |
name: Format | |
runs-on: ubuntu-latest | |
env: | |
MIX_ENV: test | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Task | |
uses: arduino/setup-task@v2 | |
with: | |
# prevent rate limits by github: https://github.com/arduino/setup-task#repo-token | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup runtime deps with mise | |
uses: jdx/mise-action@v2 | |
- name: Cache deps/_build dirs | |
uses: actions/cache@v4 | |
id: cache-deps | |
with: | |
path: | | |
app/deps | |
app/_build | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/app/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: Install Hex | |
if: steps.cache-deps.outputs.cache-hit == 'true' | |
run: task ci:hex:install | |
- name: Get Deps | |
if: steps.cache-deps.outputs.cache-hit != 'true' | |
run: task ci:deps:get | |
- name: Test | |
run: task ci:format:check |
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
# yaml-language-server: $schema=https://taskfile.dev/schema.json | |
# NOTE: this file lives in taskfiles/ci.yml | |
version: 3 | |
env: | |
MIX_ENV: test | |
tasks: | |
run: | |
desc: Runs the ci pipeline locally | |
# since this runs synchronously, it's best to order these by speed to get | |
# the best "fail-fast" experience | |
cmds: | |
- task: deps:get | |
- task: compile | |
- task: xref | |
- task: format:check | |
- task: test | |
- cmd: | | |
echo ---------------------- | lolcrab | |
echo Completed Successfully | lolcrab | |
echo ---------------------- | lolcrab | |
silent: true | |
deps:get: | |
desc: Downloads the Elixir dependencies | |
cmd: mix deps.get | |
compile: | |
desc: Compiles the Elixir project, and fails on warnings | |
cmd: mix compile --warnings-as-errors | |
hex:install: | |
desc: Force install hex | |
cmd: mix local.hex --force | |
xref: | |
desc: Check for cyclical compile dependencies | |
cmd: mix xref graph --label compile-connected --fail-above 0 | |
test: | |
desc: Runs the tests with fail-fast | |
cmd: mix test --max-failures 1 --trace --warnings-as-errors | |
format:check: | |
desc: Runs the tests with fail-fast | |
cmd: mix format --check-formatted |
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
# yaml-language-server: $schema=https://taskfile.dev/schema.json | |
# NOTE: this file lives in the root of your project | |
version: 3 | |
includes: | |
ci: | |
taskfile: ./taskfiles/ci.yml | |
# I have the phoenix app in ./app, so setting the dir here ensures that all the tasks below run inside that cwd | |
dir: app | |
tasks: | |
gh:run:watch: | |
desc: Watch latest run | |
cmd: | | |
last_run=$(gh run list --workflow 'ci.yml' --limit 1 --json databaseId | jq -r '.[0].databaseId') | |
gh run watch $last_run | |
silent: true | |
gh:run:view: | |
desc: View latest run | |
cmd: | | |
last_run=$(gh run list --workflow 'ci.yml' --limit 1 --json databaseId | jq -r '.[0].databaseId') | |
gh run view $last_run | |
silent: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment