Git pre-push hooks #81
This file contains 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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
name: Elixir CI | |
env: | |
MIX_ENV: test | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
permissions: | |
actions: write | |
contents: read | |
jobs: | |
pre_job: | |
name: check for duplicate tasks | |
# continue-on-error: true # Uncomment once integration is finished | |
runs-on: ubuntu-latest | |
# Map a step output to a job output | |
outputs: | |
should_skip: ${{ steps.skip_check.outputs.should_skip }} | |
steps: | |
- id: skip_check | |
uses: fkirc/skip-duplicate-actions@v5 | |
with: | |
paths_ignore: '["**.md", "docs/**"]' | |
cancel_others: true | |
build: | |
needs: pre_job | |
if: needs.pre_job.outputs.should_skip != 'true' | |
name: Build and test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: DeterminateSystems/nix-installer-action@main | |
- uses: DeterminateSystems/magic-nix-cache-action@main | |
- uses: DeterminateSystems/flake-checker-action@main | |
- name: Restore dependencies cache | |
uses: actions/cache@v4 | |
with: | |
path: deps | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: install mix | |
run: nix develop -c mix local.hex | |
- name: Run flakes check | |
run: | | |
nix flake check | |
nix develop -c echo OK | |
- name: Install dependencies | |
run: nix develop -c mix deps.get | |
- name: Retrieve PLT Cache | |
uses: actions/cache@v4 | |
id: plt-cache | |
with: | |
path: priv/plts | |
key: ${{ runner.os }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.*')) }}-${{ hashFiles(format('{0}{1}', github.workspace, '/flake.*')) }} | |
- name: Create PLTs | |
if: steps.plt-cache.outputs.cache-hit != 'true' | |
run: | | |
mkdir -p priv/plts | |
nix develop -c mix dialyzer --plt | |
- name: Run pre-commit checks | |
env: | |
HEAD_REF: ${{ github.head_ref }} | |
BASE_REF: ${{ github.base_ref }} | |
run: | | |
if [[ -n "$HEAD_REF" && -n "$BASE_REF" ]]; then | |
git fetch --depth=1 origin "$BASE_REF" | |
git fetch --depth=1 origin "$HEAD_REF" | |
git branch -c origin/"$HEAD_REF" this_pr | |
nix develop -c pre-commit run --show-diff-on-failure --color=always --from-ref this_pr --to-ref "$BASE_REF" | |
else | |
nix develop -c pre-commit run --show-diff-on-failure --color=always --all-files | |
fi |