-
Notifications
You must be signed in to change notification settings - Fork 10
138 lines (124 loc) · 4.57 KB
/
tests.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
name: Testing
on:
push:
branches:
- main
- dev
- experimental
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
jobs:
# For the setup idea using Docker Buildx, see StackOverflow answer [1].
# [2] might also be very useful. [3] and [4] are generally about Docker
# cache management (within GitHub Actions). Note that the GitHub Actions cache
# is different from the GitHub Container Registry (ghcr).
#
# [1] https://stackoverflow.com/a/75544124/
# [2] https://www.deploysentinel.com/blog/docker-buildx-cache-with-github-actions
# [3] https://docs.docker.com/build/ci/github-actions/cache/
# [4] https://docs.docker.com/build/cache/backends/
build-mampf:
name: Build MaMpf
environment: testing
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
# see https://github.com/orgs/MaMpf-HD/packages?repo_name=mampf
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push docker image to GHCR
working-directory: docker/test
# We don't use the docker/build-push-action here since it doesn't
# support passing custom docker compose files (just dockerfiles).
#
# See this link for a reference of target options:
# https://docs.docker.com/build/bake/reference/#target
#
# Note it's essential to use the inline type such that the build cache
# is embedded in the image. See the Cache storage backends:
# https://docs.docker.com/build/cache/backends/
# https://docs.docker.com/reference/cli/docker/buildx/build/#cache-to
#
# Push image and cache separately to GHCR, since otherwise inline mode
# does not support mode=max caching.
# https://github.com/moby/buildkit?tab=readme-ov-file#registry-push-image-and-cache-separately
run: >
docker buildx bake
--allow=fs.read=/home/runner/work/mampf/mampf
-f ./docker-compose.yml -f ./docker-compose.cicd.build.yml
--set mampf.output=type=image,name=ghcr.io/mampf-hd/mampftest:image,push=true
--set mampf.cache-from=type=registry,ref=ghcr.io/mampf-hd/mampftest:buildcache
--set mampf.cache-to=type=registry,ref=ghcr.io/mampf-hd/mampftest:buildcache,mode=max
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
permissions: write-all
needs: build-mampf
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull MaMpf image (from GHCR)
working-directory: docker/test
run: >
docker pull ghcr.io/mampf-hd/mampftest:image
- name: Run unit tests
working-directory: docker/test
run: >
docker compose -f docker-compose.yml -f docker-compose.cicd.yml
run --entrypoint="" mampf sh -c
"RAILS_ENV=test bundle exec rspec --format RSpec::Github::Formatter"
- name: Report test coverage to codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: ./coverage/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
# Cypress end-to-end (e2e) tests
e2e-tests:
name: e2e (Cypress)
runs-on: ubuntu-latest
permissions: write-all
needs: build-mampf
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull MaMpf image (from GHCR)
working-directory: docker/test
run: >
docker pull ghcr.io/mampf-hd/mampftest:image
- name: Run Cypress tests
working-directory: docker/test
run: >
docker compose
-f ./docker-compose.yml -f docker-compose.cicd.yml
-f ./cypress.yml
run cypress