-
Notifications
You must be signed in to change notification settings - Fork 5
144 lines (120 loc) · 4.11 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# See output: https://github.com/barsoom/ex-remit/actions
# Set up from these instructions: https://github.com/actions/setup-elixir
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
# Wait for previous run to complete, to avoid concurrent deployment.
# https://github.community/t/how-to-limit-concurrent-workflow-runs/16844/17
# https://github.com/softprops/turnstyle
wait-for-completion:
runs-on: ubuntu-latest
timeout-minutes: 4
steps:
- name: Wait for any previous runs to finish
uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 10
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tests:
needs: wait-for-completion
runs-on: ubuntu-latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
services:
db:
image: postgres:14.4 # Keep in sync with dev.yml
ports: ["5432:5432"]
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: "remit_test"
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up Elixir
id: beam
uses: erlef/setup-beam@v1
with:
# NOTE: Keep in sync with elixir_buildpack.config and asdf's .tool-versions.
elixir-version: "1.16.1"
otp-version: "26.2.2"
- name: Cache deps
id: cache-deps
uses: actions/cache@v3
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
- name: Cache compiled build
id: cache-build
uses: actions/cache@v3
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
${{ runner.os }}-mix-
# Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
- name: Cache PLT
uses: actions/cache@v3
id: plt_cache
with:
path: priv/plts
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
- name: Install deps
run: mix deps.get
- name: Check Formatting
run: mix format --check-formatted
- name: Compile in dev mode
run: mix compile --warnings-as-errors
# {:mix_audit, "~> 2.0", only: [:dev, :test], runtime: false}
- name: Check vulnerable packages
run: mix deps.audit
- name: Check retired packages
run: mix hex.audit
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt
# {:credo, "~> 1.6", only: [:dev, :test], runtime: false}
- name: Credo
run: mix credo
- name: Compile in test mode
env:
MIX_ENV: test
run: mix compile --warnings-as-errors
- name: Run tests
run: mix test
# {:dialyxir, "~> 1.0", only: [:dev], runtime: false}
- name: Run dialyzer
run: mix dialyzer --format github
# Based on: https://mikecoutermarsh.com/github-actions-deploy-to-heroku/
deploy:
needs: tests
runs-on: ubuntu-latest
# Only if we're on master – not with PRs.
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Heroku credentials
env:
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
run: echo "machine git.heroku.com password $HEROKU_API_TOKEN" >> ~/.netrc
- name: Deploy
env:
HEROKU_APP_NAME: "ex-remit"
# Migrations are run by Heroku release phase: see Procfile.
run: git push https://git.heroku.com/$HEROKU_APP_NAME.git origin/master:master