-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (100 loc) · 3.29 KB
/
ci_cd.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
name: CI/CD
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
MIX_ENV: test
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_NAME: test_db
jobs:
ci:
name: CI
runs-on: ubuntu-latest
services:
postgres:
# Dockerhub image
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: ".tool-versions"
version-type: "strict"
# Step: Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: cache-deps
uses: actions/cache@v3
env:
cache-name: cache-elixir-deps
with:
path: deps
key: deps-${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
# Step: Define how to cache the `_build` directory. After the first run,
# this speeds up tests runs a lot. This includes not re-compiling our
# project's downloaded deps every run.
- name: Cache compiled build
id: cache-build
uses: actions/cache@v3
env:
cache-name: cache-compiled-build
with:
path: _build
key: _build-${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
_build-${{ runner.os }}-mix-${{ env.cache-name }}-
_build-${{ runner.os }}-mix-
# Step: Conditionally bust the cache when job is re-run.
# Sometimes, we may have issues with incremental builds that are fixed by
# doing a full recompile. In order to not waste dev time on such trivial
# issues (while also reaping the time savings of incremental builds for
# *most* day-to-day development), force a full recompile only on builds
# that are retried.
- name: Clean to rule out incremental build as a source of flakiness
if: github.run_attempt != '1'
run: |
mix deps.clean --all
mix clean
shell: sh
- name: Install deps, compile deps, and build PLTs
run: mix do deps.get, deps.compile, dialyzer --plt
- name: Run Check
run: mix check
env:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
cd:
name: Deploy apps
needs: [ci]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy website
run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_WEBSITE_API_TOKEN }}
- name: Deploy metrics app
run: flyctl deploy --remote-only ./livebook/
env:
FLY_API_TOKEN: ${{ secrets.FLY_METRICS_API_TOKEN }}