Skip to content

Commit

Permalink
Github Actions Support (exercism#545)
Browse files Browse the repository at this point in the history
* Adding Github Actions support

* Removing previous CI files

* Add dependency caching (dialyzer)
  • Loading branch information
jwarwick authored Oct 30, 2020
1 parent 318824d commit b3027e5
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Maintainers
# Maintainers
config/maintainers.json @exercism/maintainers-admin

# Code owners
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# This workflow will do a clean install of the dependencies and run tests across different versions
#
# Requires scripts:
# - bin/ci.sh
# - bin/ci-check.sh

name: elixir / main ci

on:
push:
branches: [master, main]
workflow_dispatch:

jobs:
precheck:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use Elixir
uses: actions/setup-elixir@v1
with:
otp-version: '22.2'
elixir-version: '1.10.0'

- name: Retrieve Mix Dependencies Cache
uses: actions/cache@v1
id: mix-cache # id to use in retrieve action
with:
path: deps
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install Mix Dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Build Project
run: mix

- name: Retrieve PLT Cache
uses: actions/cache@v1
id: plt-cache
with:
path: priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix dialyzer --plt
- name: Run Prechecks
run: bin/ci-check.sh

ci:
runs-on: ubuntu-latest

strategy:
matrix:
#Note: pick a canonical set of supported versions
elixir: ['1.6.0', '1.7.0']
otp: ['19.0']
include:
- elixir: '1.8.0'
otp: '20.0'
- elixir: '1.9.0'
otp: '20.0'
- elixir: '1.10.0'
otp: '21.0'
- elixir: '1.10.0'
otp: '22.2'

steps:
- uses: actions/checkout@v2
- name: Use Elixir ${{matrix.elixir}} / OTP ${{matrix.otp}}
uses: actions/setup-elixir@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Retrieve Mix Dependencies Cache
uses: actions/cache@v1
id: mix-cache # id to use in retrieve action
with:
path: deps
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install Mix Dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Build Project
run: mix

- name: Run Checks
run: bin/ci.sh
18 changes: 18 additions & 0 deletions .github/workflows/configlet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This workflow will do a fetch the latest configlet binary and lint this repository.

name: configlet

on: [push, pull_request, workflow_dispatch]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Fetch configlet
uses: exercism/github-actions/configlet-ci@master

- name: Configlet Linter
run: configlet lint .
111 changes: 111 additions & 0 deletions .github/workflows/pr.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# This workflow will do a clean install of the dependencies and run tests across different versions
#
# Requires scripts:
# - bin/pr-check.sh
# - bin/pr.sh

name: elixir / pr

on: pull_request

jobs:
precheck:
runs-on: ubuntu-latest

steps:
- name: Checkout PR
uses: actions/checkout@v2

- name: Use Elixir
uses: actions/setup-elixir@v1
with:
otp-version: '22.2'
elixir-version: '1.10.0'

- name: Retrieve Mix Dependencies Cache
uses: actions/cache@v1
id: mix-cache # id to use in retrieve action
with:
path: deps
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install Mix Dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Build Project
run: mix

- name: Retrieve PLT Cache
uses: actions/cache@v1
id: plt-cache
with:
path: priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix dialyzer --plt
# Replace <code-extensions> with file extensions that should trigger this check. Replace with .* to allow anything.
- name: Run exercism/elixir ci pre-check (stub files, config integrity) for changed exercises
run: |
PULL_REQUEST_URL=$(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH")
curl --url $"${PULL_REQUEST_URL}/files" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \
jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(ex|exs|md|json)$")) | .filename' | \
xargs -r bin/pr-check.sh
ci:
runs-on: ubuntu-latest

strategy:
matrix:
elixir: ['1.6.0', '1.7.0']
otp: ['19.0']
include:
- elixir: '1.8.0'
otp: '20.0'
- elixir: '1.9.0'
otp: '20.0'
- elixir: '1.10.0'
otp: '21.0'
- elixir: '1.10.0'
otp: '22.2'

steps:
- uses: actions/checkout@v2
- name: Use Elixir ${{matrix.elixir}} / OTP ${{matrix.otp}}
uses: actions/setup-elixir@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Retrieve Mix Dependencies Cache
uses: actions/cache@v1
id: mix-cache # id to use in retrieve action
with:
path: deps
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Install Mix Dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Build Project
run: mix

# Replace <code-extensions> with file extensions that should trigger running tests. Replace with .* to allow anything.
- name: Run exercism/elixir ci (runs tests) for changed/added exercises
run: |
PULL_REQUEST_URL=$(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH")
curl --url $"${PULL_REQUEST_URL}/files" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \
jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(ex|exs|md|json)$")) | .filename' | \
xargs -r bin/pr.sh
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

26 changes: 26 additions & 0 deletions bin/check_formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# ###
# check_formatting.sh
# ###
# Uses `mix format` to validate formatting of all elixir code
# Looks for trailing whitespace in files
# ###
echo "Running 'mix format'"
mix format --check-formatted
FORMAT_EXIT_CODE="$?"

echo "Checking for trailing whitespace"
# git grep returns a 0 status if there is a match
# so we negate the result for consistency
! git grep --line-number ' $'
GREP_EXIT_CODE="$?"

if [ "$FORMAT_EXIT_CODE" -ne 0 -o "$GREP_EXIT_CODE" -ne 0 ]
then
echo "Formatting checks failed"
exit 1;
fi

echo "Formatting checks passed"
exit 0;
24 changes: 24 additions & 0 deletions bin/ci-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# ###
# ci-check.sh
# ###
# Precheck actions to run on a commit to master
# ###

echo "Running check_formatting.sh"
("bin/check_formatting.sh")
CHECK_FORMAT_EXIT_CODE="$?"

echo "Running dialyzer_check.sh"
("bin/dialyzer_check.sh")
DIALYZER_EXIT_CODE="$?"

if [ "$CHECK_FORMAT_EXIT_CODE" -ne 0 -o "$DIALYZER_EXIT_CODE" -ne 0 ]
then
echo "Precheck failed"
exit 1;
fi

echo "Precheck passed"
exit 0;
20 changes: 20 additions & 0 deletions bin/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# ###
# ci.sh
# ###
# Actions to run on a commit to master
# ###

echo "Running test_exercises.sh"
("bin/test_exercises.sh")
TEST_EXIT_CODE="$?"

if [ "$TEST_EXIT_CODE" -ne 0 ]
then
echo "Tests failed"
exit 1;
fi

echo "Tests passed"
exit 0;
6 changes: 5 additions & 1 deletion bin/dialyzer_check.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/bash

# currently dialyzer is timing out after 30 mins only on elixir 1.7 / otp 19
if elixir --version | grep -q 'Elixir 1.7'; then
echo "skipping dialyzer for Elixir 1.7"
exit 0
fi

mkdir -p ./priv/plts

mkdir -p ./tmp/src
mkdir ./tmp/build

Expand All @@ -15,7 +19,7 @@ do
done

elixirc -o ./_build ./tmp/src/*.exs
mix dialyzer
mix dialyzer --no-check
RESULT=$?
rm -rf ./tmp

Expand Down
Loading

0 comments on commit b3027e5

Please sign in to comment.