-
Notifications
You must be signed in to change notification settings - Fork 1
235 lines (223 loc) · 7.71 KB
/
test.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Test
on:
push:
branches:
- develop
- master
- staging
- release/*
- feature/*
- bugfix/*
- hotfix/*
# pull_request:
# branches: [ develop, master ]
# types: [ synchronize, opened, reopened, ready_for_review ]
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
defaults:
run:
shell: bash
permissions:
id-token: write
attestations: write
jobs:
changes:
if: (github.event_name != 'pull_request'
|| github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name)
|| github.event_name == 'create'
runs-on: ubuntu-latest
timeout-minutes: 1
defaults:
run:
shell: bash
outputs:
run_tests: ${{ steps.changes.outputs.run_tests }}
steps:
- name: Checkout code
uses: actions/[email protected]
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
with:
base: ${{ github.ref }}
token: ${{ github.token }}
filters: .github/file-filters.yml
test:
needs: [ changes ]
if: needs.changes.outputs.run_tests == 'true'
runs-on: ubuntu-latest
outputs:
image: ${{ env.IMAGE }}
commit: ${{env.sha_short}}
build_date: ${{env.BUILD_DATE}}
branch: ${{env.BRANCH}}
services:
redis:
image: redis:7.4.0
ports:
- 16379:6379
db:
image: postgres:14
env:
POSTGRES_DATABASE: country_workspace
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: postgres
ports:
- 15432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DOCKER_DEFAULT_PLATFORM: linux/amd64
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
DATABASE_URL: postgres://postgres:postgres@localhost:15432/country_workspace
CELERY_BROKER_URL: redis://localhost:16379/1
CACHE_URL: redis://localhost:16379/2
DOCKER_BUILDKIT: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Hack container for local development
if: ${{ env.ACT }}
run: |
echo /home/runner/externals/node20/bin >> $GITHUB_PATH
- name: Hack container for local development
run: |
echo BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: "unicef/hope-country-workspace"
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{raw}}
- name: DockerHub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: last_commit
uses: ./.github/actions/last_commit
- id: calc
shell: bash
run: |
set -x
LOCK_SHA=$(sha1sum uv.lock docker/bin/* docker/conf/* docker/Dockerfile | sha1sum | awk '{print $1}' | cut -c 1-8)
IMAGE=$(echo '${{env.DOCKER_METADATA_OUTPUT_JSON}}' | jq '.tags[0]')
echo "checksum=$LOCK_SHA" >> "$GITHUB_ENV"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +"%Y-%m-%d %H:%M" )" >> $GITHUB_ENV
echo "IMAGE=$IMAGE" >> $GITHUB_ENV
- name: Build Test Image
run: |
docker build \
--target tests \
-t ${{env.IMAGE}} \
--cache-from "type=gha" \
--cache-to "type=gha,mode=max" \
-f docker/Dockerfile .
- name: Run Test suite
run: |
mkdir output
docker run --rm \
--network host \
-e PYTHONPATH=/app/src \
-e DATABASE_URL=${DATABASE_URL} \
-e CELERY_BROKER_URL=${CELERY_BROKER_URL} \
-e CACHE_URL=${CACHE_URL} \
-e SECRET_KEY=super-secret-key-just-for-testing \
-e HOPE_API_URL="https://dev-hope.unitst.org/api/rest/" \
-e HOPE_API_TOKEN=${{ secrets.HOPE_API_TOKEN }} \
-e AURORA_API_URL="https://uni-hope-ukr-sr-dev.unitst.org/api/" \
-e AURORA_API_TOKEN=${{ secrets.AURORA_API_TOKEN }} \
-v "./output/:/app/output" \
-v "./src/:/app/src" \
-v "./tests:/app/tests" \
-v "./pytest.ini:/app/pytest.ini" \
-t ${{env.IMAGE}} \
pytest tests/ --selenium -n auto -v --maxfail=5 --migrations --cov-report xml:./output/coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
continue-on-error: true
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
files: /app/output/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: false
name: codecov-${{env.GITHUB_REF_NAME}}
release:
needs: [ test ]
runs-on: ubuntu-latest
services:
redis1:
image: redis:7.4.0
ports:
- 5379:6379
db1:
image: postgres:14
env:
POSTGRES_HOST: db1
POSTGRES_DATABASE: country_workspace
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: postgres
ports:
- 4432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DOCKER_DEFAULT_PLATFORM: linux/amd64
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
DATABASE_URL: postgres://postgres:postgres@localhost:4432/country_workspace
CELERY_BROKER_URL: redis://localhost:5379/1
CACHE_URL: redis://localhost:5379/2
DOCKER_BUILDKIT: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: DockerHub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Distro
run: |
docker build \
--target dist \
--cache-from "type=gha" \
--cache-to "type=gha,mode=max" \
--build-arg "GIT_SHA=${{needs.test.outputs.commit}}" \
--build-arg "BUILD_DATE=${{needs.test.outputs.build_date}}" \
--build-arg "BRANCH=${{needs.test.outputs.branch}}" \
-t ${{needs.test.outputs.image}} \
-f docker/Dockerfile .
#
# - name: Docker Integrity Check
# run: |
# docker run --rm \
# --network host \
# -e DATABASE_URL=${DATABASE_URL} \
# -e CELERY_BROKER_URL=${CELERY_BROKER_URL} \
# -e CACHE_URL=${CACHE_URL} \
# -e SECRET_KEY=super-secret-key-just-for-testing \
# -e HOPE_API_URL="https://dev-hope.unitst.org/api/rest/" \
# -e HOPE_API_TOKEN=${{ secrets.HOPE_API_TOKEN }} \
# -e AURORA_API_URL="https://uni-hope-ukr-sr-dev.unitst.org/api/" \
# -e AURORA_API_TOKEN=${{ secrets.AURORA_API_TOKEN }} \
# -t ${{needs.test.outputs.image}} \
# django-admin upgrade
- name: Publish images
run: |
docker push ${{needs.test.outputs.image}}
docker inspect ${{needs.test.outputs.image}} | jq -r '.[0].Config.Labels'
echo "::notice::✅ Image ${{needs.test.outputs.image}} built and pushed"