-
Notifications
You must be signed in to change notification settings - Fork 18
168 lines (150 loc) · 5.32 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
name: Build & test
on:
pull_request:
paths:
- "backend/**"
- "frontend/**"
- "docs/docs/setup/config.toml"
- "util/dev-config/*"
- ".deployment/templates/config.toml"
- "util/dummy-login/dist/index.js"
- ".github/workflows/ci.yml"
- ".github/workflows/deploy.yml"
push:
branches:
- "*"
tags-ignore:
- "*"
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: --deny warnings
jobs:
main:
runs-on: ubuntu-20.04
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: tobira
POSTGRES_PASSWORD: tobira
POSTGRES_DB: tobira
ports:
- 5432:5432
options: '--name tobira_pg'
steps:
- uses: actions/checkout@v3
- name: Restore backend cache
uses: Swatinem/rust-cache@v2
with:
workspaces: backend
# Frontend cache: only the NPM folder is cached, not the node_modules, as
# recommended here: https://github.com/actions/cache/blob/main/examples.md#node---npm
- name: Restore NPM cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }}
# Figure out build mode
- name: Determine build mode
run: |
if [[ "$GITHUB_REPOSITORY" == "elan-ev/tobira" ]] && [ "$GITHUB_REF" == "refs/heads/master" ]; then
echo "ci_cargo_flags=--release" >> $GITHUB_ENV
echo "ci_targetdir=target/release" >> $GITHUB_ENV
echo "ci_webpack_flags=production" >> $GITHUB_ENV
else
echo "ci_cargo_flags=--features=embed-in-debug" >> $GITHUB_ENV
echo "ci_targetdir=target/debug" >> $GITHUB_ENV
echo "ci_webpack_flags=development" >> $GITHUB_ENV
fi
# The actual building and testing!
- name: Installing frontend dependencies (npm ci)
working-directory: frontend
run: npm ci
- name: Generate GraphQL query types
working-directory: frontend
run: npx relay-compiler
- name: Lint frontend
working-directory: frontend
run: npx eslint --max-warnings 0 .
- name: Build frontend
working-directory: frontend
run: npx webpack --mode=${{ env.ci_webpack_flags }}
- name: Typecheck frontend
working-directory: frontend
run: npx tsc
- name: Build backend
working-directory: backend
run: cargo build ${{ env.ci_cargo_flags }}
- name: Test backend
working-directory: backend
run: cargo test
- name: Move Tobira binary
run: mv backend/${{ env.ci_targetdir }}/tobira tobira
- name: Compress Tobira binary
run: objcopy --compress-debug-sections tobira
- name: Make sure `schema.graphql` is up to date
run: ./tobira export-api-schema | diff -u --color=always - frontend/src/schema.graphql
- name: Make sure `docs/docs/setup/config.toml` is up to date
run: ./tobira write-config | diff -u --color=always - docs/docs/setup/config.toml
# Test DB migrations
- name: Download latest DB dump
run: curl --silent --output db-dump.xz https://s3.opencast-niedersachsen.de/tobira/db-dump-latest.xz
- name: Decompress DB dump
run: xz -d db-dump.xz
# We need to use the same version as the DB, so we use 'docker exec'
- name: Restore DB dump
run: |
docker exec -i tobira_pg pg_restore \
--dbname postgresql://tobira:tobira@localhost/postgres \
--clean \
--create \
--if-exists \
< db-dump || true
- name: Run migrations
run: ./tobira db migrate --config util/dev-config/config.toml
# UI tests
- name: Start docker containers
working-directory: util/containers
run: |
docker-compose -f docker-compose.yml up -d \
tobira-auth-proxy \
tobira-login-handler \
tobira-meilisearch
- name: Rebuild search index
working-directory: backend
run: cargo run -- search-index update
- name: Install Playwright browsers
working-directory: frontend
run: npx playwright install --with-deps
- name: Run playwright tests
working-directory: frontend
run: npx playwright test
- name: Upload test results
# A test might need a retry to succeed or run longer than expected.
# In these cases the results should also be saved, since they might
# indicate what went wrong. Hence `always()` instead of on `failure()`.
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: frontend/playwright-report/
retention-days: 7
# Prepare the ID (used in the subdomain) for deployment. This has to be done
# here because in the `deploy` workflow, we don't have access to the correct
# `GITHUB_REF` anymore.
- name: Write deploy ID to file
run: ./.deployment/deploy-id.sh "$GITHUB_REF" > deploy-id
# Archive files to be used in the `deploy` workflow
- name: Archive deployment files as artifact
uses: actions/upload-artifact@v3
with:
name: test-deployment-files
path: |
tobira
util/dev-config/logo-large.svg
util/dev-config/logo-small.svg
util/dev-config/logo-large-dark.svg
util/dev-config/favicon.svg
deploy-id
.deployment/templates/config.toml
util/dummy-login/dist/index.js