|
1 | 1 | name: Elixir CI |
2 | 2 |
|
3 | | -on: push |
| 3 | +# Define workflow that runs when changes are pushed to the |
| 4 | +# `main` branch or pushed to a PR branch that targets the `main` |
| 5 | +# branch. Change the branch name if your project uses a |
| 6 | +# different name for the main branch like "master" or "production". |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: ["main"] # adapt branch for project |
| 10 | + pull_request: |
| 11 | + branches: ["main"] # adapt branch for project |
4 | 12 |
|
5 | | -jobs: |
6 | | - compile: |
7 | | - runs-on: ubuntu-latest |
8 | | - container: |
9 | | - image: elixir:1.9.4-slim |
10 | | - env: |
11 | | - MIX_ENV: prod |
12 | | - steps: |
13 | | - - uses: actions/checkout@v1 |
14 | | - - name: install dependencies |
15 | | - run: | |
16 | | - mix local.rebar --force |
17 | | - mix local.hex --force |
18 | | - mix deps.get --only prod |
19 | | - - name: compile |
20 | | - run: mix compile --force |
| 13 | +# Sets the ENV `MIX_ENV` to `test` for running tests |
| 14 | +env: |
| 15 | + MIX_ENV: test |
21 | 16 |
|
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
22 | 21 | test: |
23 | | - runs-on: ubuntu-latest |
24 | | - container: |
25 | | - image: elixir:1.9.4-slim |
26 | | - env: |
27 | | - MIX_ENV: test |
| 22 | + runs-on: ubuntu-20.04 |
| 23 | + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} |
| 24 | + strategy: |
| 25 | + # Specify the OTP and Elixir versions to use when building |
| 26 | + # and running the workflow steps. |
| 27 | + matrix: |
| 28 | + otp: ["25.3.2.2", "26.0.1"] # Define the OTP version [required] |
| 29 | + elixir: ["1.14.5", "1.15.0"] # Define the elixir version [required] |
28 | 30 | steps: |
29 | | - - uses: actions/checkout@v1 |
30 | | - - name: install dependencies |
31 | | - run: | |
32 | | - mix local.rebar --force |
33 | | - mix local.hex --force |
34 | | - mix deps.get --only test |
35 | | - - name: test |
36 | | - run: mix test --cover --trace |
37 | | - - name: archive code coverage |
38 | | - uses: actions/upload-artifact@v1 |
| 31 | + # Step: Setup Elixir + Erlang image as the base. |
| 32 | + - name: Set up Elixir |
| 33 | + uses: erlef/setup-beam@v1 |
39 | 34 | with: |
40 | | - name: cover |
41 | | - path: cover |
| 35 | + otp-version: ${{matrix.otp}} |
| 36 | + elixir-version: ${{matrix.elixir}} |
42 | 37 |
|
43 | | - static_code_analysis: |
44 | | - runs-on: ubuntu-latest |
45 | | - container: |
46 | | - image: elixir:1.9.4-slim |
47 | | - env: |
48 | | - MIX_ENV: dev |
49 | | - steps: |
50 | | - - uses: actions/checkout@v1 |
51 | | - - name: install dependencies |
52 | | - run: | |
53 | | - mix local.rebar --force |
54 | | - mix local.hex --force |
55 | | - mix deps.get --only dev |
56 | | - - name: plt cache |
57 | | - uses: actions/cache@v1.1.0 |
| 38 | + # Step: Check out the code. |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v3 |
| 41 | + |
| 42 | + # Step: Define how to cache deps. Restores existing cache if present. |
| 43 | + - name: Cache deps |
| 44 | + id: cache-deps |
| 45 | + uses: actions/cache@v3 |
| 46 | + env: |
| 47 | + cache-name: cache-elixir-deps |
| 48 | + with: |
| 49 | + path: deps |
| 50 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 51 | + restore-keys: | |
| 52 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 53 | +
|
| 54 | + # Step: Define how to cache the `_build` directory. After the first run, |
| 55 | + # this speeds up tests runs a lot. This includes not re-compiling our |
| 56 | + # project's downloaded deps every run. |
| 57 | + - name: Cache compiled build |
| 58 | + id: cache-build |
| 59 | + uses: actions/cache@v3 |
| 60 | + env: |
| 61 | + cache-name: cache-compiled-build |
58 | 62 | with: |
59 | 63 | path: _build |
60 | | - key: ${{ runner.os }}-plt-${{ env.GITHUB_REF }} |
| 64 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
61 | 65 | restore-keys: | |
62 | | - ${{ runner.os }}-plt- |
63 | | - - name: formatted? |
64 | | - run: mix format --check-formatted --dry-run |
65 | | - - name: credo |
66 | | - run: mix credo --verbose |
67 | | - - name: gradient |
| 66 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 67 | + ${{ runner.os }}-mix- |
| 68 | +
|
| 69 | + # Step: Conditionally bust the cache when job is re-run. |
| 70 | + # Sometimes, we may have issues with incremental builds that are fixed by |
| 71 | + # doing a full recompile. In order to not waste dev time on such trivial |
| 72 | + # issues (while also reaping the time savings of incremental builds for |
| 73 | + # *most* day-to-day development), force a full recompile only on builds |
| 74 | + # that are retried. |
| 75 | + - name: Clean to rule out incremental build as a source of flakiness |
| 76 | + if: github.run_attempt != '1' |
| 77 | + run: | |
| 78 | + mix deps.clean --all |
| 79 | + mix clean |
| 80 | + shell: sh |
| 81 | + |
| 82 | + # Step: Download project dependencies. If unchanged, uses |
| 83 | + # the cached version. |
| 84 | + - name: Install dependencies |
| 85 | + run: mix deps.get |
| 86 | + |
| 87 | + # Step: Compile the project treating any warnings as errors. |
| 88 | + # Customize this step if a different behavior is desired. |
| 89 | + - name: Compiles without warnings |
| 90 | + run: mix compile --warnings-as-errors |
| 91 | + |
| 92 | + # Step: Check that the checked in code has already been formatted. |
| 93 | + # This step fails if something was found unformatted. |
| 94 | + # Customize this step as desired. |
| 95 | + - name: Check Formatting |
| 96 | + run: mix format --check-formatted |
| 97 | + |
| 98 | + # Step: Execute the tests. |
| 99 | + - name: Run tests |
| 100 | + if: success() || failure() |
| 101 | + run: mix test |
| 102 | + |
| 103 | + # Step: Run credo. |
| 104 | + - name: Run credo |
| 105 | + if: success() || failure() |
| 106 | + run: mix credo |
| 107 | + |
| 108 | + # Step: Run dialyzer. |
| 109 | + - name: Run dialyzer |
| 110 | + if: success() || failure() |
| 111 | + run: mix dialyzer |
| 112 | + |
| 113 | + # Step: Run gradient. |
| 114 | + - name: Run gradient |
| 115 | + if: success() || failure() |
68 | 116 | run: mix gradient |
69 | | - - name: dialyzer |
70 | | - run: mix dialyzer --halt-exit-status |
|
0 commit comments