Skip to content

Instantly share code, notes, and snippets.

@starbelly
Created September 17, 2023 18:52
Show Gist options
  • Save starbelly/f423c2a3e059fa9c5e2647e4b5a7b175 to your computer and use it in GitHub Desktop.
Save starbelly/f423c2a3e059fa9c5e2647e4b5a7b175 to your computer and use it in GitHub Desktop.
simple example for caching with a composite action
# .github/actions/setup/action.yaml
name: "mix cache"
description: "Setup an elixir mix project and restore cache"
inputs:
cache-version:
description: "Optional cache version. Any string is valid. Default to '0'"
required: false
default: 0
outputs:
cache-hit:
description: "Forward actions/cache cache-hit output"
value: ${{ steps.mix-cache.outputs.cache-hit }}
runs:
using: "composite" # Mandatory parameter
steps:
- name: get tool versions
run: ./.github/scripts/gh_get_tool_versions.sh
id: versions
- name: setup
uses: erlef/setup-beam@v1
with:
otp-version: ${{ steps.versions.outputs.otp-version }}
elixir-version: ${{ steps.versions.outputs.elixir-version }}
- name: restore-deps
uses: actions/cache@v1
with:
path: deps
key: ${{ runner.os }}-mix-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ inputs.cache-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
- name: restore-build
uses: actions/cache@v1
with:
path: _build
key: ${{ runner.os }}-build-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ inputs.cache-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
# .github/actions/setup/action.yaml
name: "dialyzer-cache"
description: "Setup an elixir mix project and restore cache"
inputs:
cache-version:
description: "Optional cache version. Any string is valid. Default to '0'"
required: false
default: 0
outputs:
cache-hit:
description: "Forward actions/cache cache-hit output"
value: ${{ steps.mix-cache.outputs.cache-hit }}
runs:
using: "composite" # Mandatory parameter
steps:
- name: setup
uses: ./.github/actions/setup
with: inputs.cache-version
---
name: ci
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]
env:
MIX_ENV: test
cache-version: '0'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup
- uses: ./.github/actions/setup
with:
cache-version: env.cache-version
- name: deps.get
run: mix deps.get
- name: compile
run: mix compile --warnings-as-errors
format:
name: Format
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup
- uses: ./.github/actions/setup
with:
cache-version: env.cache-version
- name: format
run: mix format --check-formatted
credo:
name: Credo
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup
- uses: ./.github/actions/setup
with:
cache-version: env.cache-version
- name: credo
run: mix credo --config-name=currently_passing
dialyzer:
needs: build
name: Dialyzer
runs-on: ubuntu-latest
env:
MIX_ENV: dev
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup
uses: ./.github/actions/setup
with:
cache-version: env.cache-version
- name: restore-dev-build
uses: actions/cache@v1
with:
path: _build
key: ${{ runner.os }}-build-${{ steps.versions.outputs.otp-version }}-${{ steps.versions.outputs.elixir-version }}-${{ env.cache-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
- name: restore-plts
uses: actions/cache@v1
with:
path: ~/.plts
key: ${{ runner.os }}-dialyzer-${{ steps.versions.outputs.otp-version }}-${{ steps.versions.outputs.elixir-version }}-${{ env.cache-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
- name: dialyze
run: mix dialyzer
test:
needs: build
name: Test
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup-project
uses: ./.github/actions/setup-project
with:
cache-version: env.cache-version
- name: test
run: mix coveralls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment