Skip to content

Instantly share code, notes, and snippets.

@PJUllrich
Created January 14, 2020 22:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PJUllrich/98b72de7dc0041b1f02c6e4f4652a7e2 to your computer and use it in GitHub Desktop.
Save PJUllrich/98b72de7dc0041b1f02c6e4f4652a7e2 to your computer and use it in GitHub Desktop.
name: Elixir CI
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres:11
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v1.0.0
- uses: actions/setup-elixir@v1.0.0
with:
otp-version: 22.0
elixir-version: 1.9.4
- uses: actions/setup-node@v1
with:
node-version: 12
- name: Install chromedriver
run: |
wget https://chromedriver.storage.googleapis.com/78.0.3904.105/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
# Cache NPM packages
- name: Retrieve NPM Packages Cache
uses: actions/cache@v1
id: npm-cache
with:
path: assets/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles(format('{0}{1}', github.workspace, '/assets/package-lock.json')) }}
# Install NPM Packages only if cache was not hit
- name: Install NPM Packages
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm install --prefix assets
# Cache Mix Dependencies based on mix.lock
- name: Retrieve Mix Dependencies Cache
uses: actions/cache@v1
id: mix-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
# Get Mix Dependencies only if cache was not hit
- name: Install Mix Dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
# Compile and deploy assets to priv
- name: Deploy assets
run: npm run deploy --prefix ./assets
# Cache the _build folder
- name: Retrieve Build Cache
uses: actions/cache@v1
id: build-cache
with:
path: _build
key: ${{ runner.os }}-build-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
# Compile mix dependencies if the _build folder was not cached
- name: Compile Mix Dependencies
if: steps.build-cache.outputs.cache-hit != 'true'
run: MIX_ENV=test mix deps.compile
# Run the tests
- name: Run Tests
run: mix test
@tomekowal
Copy link

Pretty great setup! Compiling deps first and then the code is a neat trick.
I am using this file as a reference :)
I only changed one thing. I've added elixir and OTP versions to cache keys. I used matrix strategy for that even though there will be only one build in the matrix.

    strategy:
      matrix:
        elixir-version: [1.9.4]
        otp-version: [22.2]

    steps:
    - uses: actions/checkout@v2
    - name: Setup elixir
      uses: actions/setup-elixir@v1
      with:
        elixir-version: ${{ matrix.elixir-version }}
        otp-version: ${{ matrix.otp-version }}
        key: ${{ runner.os }}-${{ matrix.otp-version }}-${{ matrix.elixir-version }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

@PJUllrich
Copy link
Author

Uh! Yes! That's a great idea! I'll steal that from you if you don't mind :P

@tomekowal
Copy link

Of course, I don't mind :) That's why I am sharing it :) And to let you know that I've found your setup with separate step for compiling deps very useful! :)

I also added Dialyxir to my setup with separate step for compiling PLTs and another one for actual check: https://github.com/tomekowal/composable_html/blob/master/.github/workflows/elixir.yml

The dialyzer part is not perfect because it requires repeating priv/plts in elixir.yml and mix.exs but does the job :)

@jc00ke
Copy link

jc00ke commented Mar 20, 2020

Wow, lots of good thing here, thank you!
Unless you need a specific version of Chrome/Driver, it's installed by default on ubuntu-latest
https://github.com/actions/virtual-environments/blob/master/images/linux/Ubuntu1804-README.md

@phosphene
Copy link

Wow, lots of good thing here, thank you!
Unless you need a specific version of Chrome/Driver, it's installed by default on ubuntu-latest
https://github.com/actions/virtual-environments/blob/master/images/linux/Ubuntu1804-README.md

Good work. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment