-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (175 loc) · 5.86 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: CI
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
merge_group:
jobs:
setup:
name: asdf and Elixir dependencies
timeout-minutes: 15
runs-on: ubuntu-latest
outputs:
cache-key-asdf: ${{ steps.cache-keys.outputs.asdf }}
cache-key-mix-deps: ${{ steps.cache-keys.outputs.mix-deps }}
cache-key-node-modules: ${{ steps.cache-keys.outputs.node-modules }}
cache-key-node-modules-restore: ${{ steps.cache-keys.outputs.node-modules }}
steps:
- uses: actions/checkout@v4
- name: Set cache keys
id: cache-keys
run: |
echo "asdf-restore=cache-asdf-" >> $GITHUB_OUTPUT
echo "asdf=cache-asdf-${{ hashFiles('.tool-versions') }}" >> $GITHUB_OUTPUT
echo "mix-deps-restore=cache-mix-deps-" >> $GITHUB_OUTPUT
echo "mix-deps=cache-mix-deps-${{ hashFiles('mix.exs', 'mix.lock', '.tool-versions') }}" >> $GITHUB_OUTPUT
echo "node-modules-restore=cache-node-modules-" >> $GITHUB_OUTPUT
echo "node-modules=cache-node-modules-${{ hashFiles('package-lock.json', '.tool-versions') }}" >> $GITHUB_OUTPUT
- name: asdf cache
uses: actions/cache@v4
with:
path: ~/.asdf
key: ${{ steps.cache-keys.outputs.asdf }}
restore-keys: ${{ steps.cache-keys.outputs.asdf-restore }}
id: asdf-cache
- uses: asdf-vm/actions/install@v3
# only run `asdf install` if we didn't hit the cache
if: steps.asdf-cache.outputs.cache-hit != 'true'
- name: Setup asdf environment
uses: mbta/actions/reshim-asdf@v2
- name: mix rebar and hex
run: |
mix local.rebar --force
mix local.hex --force
# mix rebar and hex are cached with asdf, not with mix
if: steps.asdf-cache.outputs.cache-hit != 'true'
- name: Restore Mix cache, with partial
id: mix-deps-cache
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ steps.cache-keys.outputs.mix-deps }}
restore-keys: ${{ steps.cache-keys.outputs.mix-deps-restore }}
- name: Install and compile Mix dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
mix deps.get
MIX_ENV=test mix deps.compile
elixir:
name: Build and test Elixir
timeout-minutes: 15
runs-on: ubuntu-latest
needs: setup
env:
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: localhost
DATABASE_NAME: orbit_test
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: ${{env.DATABASE_USERNAME}}
POSTGRES_PASSWORD: ${{env.DATABASE_PASSWORD}}
POSTGRES_DB: ${{env.DATABASE_NAME}}
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: asdf cache
uses: actions/cache/restore@v4
with:
path: ~/.asdf
key: ${{ needs.setup.outputs.cache-key-asdf }}
- name: Setup asdf environment
uses: mbta/actions/reshim-asdf@v2
- uses: actions/checkout@v4
- name: Restore Mix cache
uses: actions/cache/restore@v4
with:
path: |
deps
_build
key: ${{ needs.setup.outputs.cache-key-mix-deps }}
- name: Compile (warnings as errors)
run: mix compile --force --warnings-as-errors
- name: Credo
run: mix credo
- name: Check formatting
run: mix format --check-formatted
- name: Run tests
run: mix test
env:
DATABASE_USERNAME: ${{env.DATABASE_USERNAME}}
DATABASE_PASSWORD: ${{env.DATABASE_PASSWORD}}
DATABASE_HOST: ${{env.DATABASE_HOST}}
DATABASE_NAME: ${{env.DATABASE_NAME}}
- uses: mbta/actions/dialyzer@v2
- name: Check for unused dependencies
run: mix deps.unlock --check-unused
- name: Sobelow (security analysis)
run: mix sobelow
frontend:
name: Frontend tests
timeout-minutes: 15
runs-on: ubuntu-latest
needs: setup
steps:
- name: asdf cache
uses: actions/cache/restore@v4
with:
path: ~/.asdf
key: ${{ needs.setup.outputs.cache-key-asdf }}
- name: Setup asdf environment
uses: mbta/actions/reshim-asdf@v2
- uses: actions/checkout@v4
- name: Restore Mix cache
uses: actions/cache/restore@v4
with:
path: |
deps
_build
key: ${{ needs.setup.outputs.cache-key-mix-deps }}
- name: Restore node_modules cache, with partial
id: node-modules-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ needs.setup.outputs.cache-key-node-modules }}
restore-keys: ${{ needs.setup.outputs.cache-key-node-modules-restore }}
- name: npm ci
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci
- name: npm test
run: npm test
docker:
name: Check that the Docker container will build and run
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: docker build
uses: docker/build-push-action@v6
with:
context: .
load: true
- name: docker compose build
run: docker compose build
- name: docker compose up
run: docker compose up --wait
- name: ensure running properly
run: docker compose exec --no-TTY orbit wget --spider -S http://localhost:4001/_health
- name: show docker container logs
run: docker compose logs orbit
if: ${{ !cancelled() }}