-
-
Notifications
You must be signed in to change notification settings - Fork 56
134 lines (109 loc) · 4.01 KB
/
backend.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
name: Backend CI
# Enable Buildkit and let compose use it to speed up image building
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL: True
defaults:
run:
working-directory: ./
on:
pull_request:
branches: [ "master", "main" ]
paths-ignore: [ "docs/**" ]
push:
branches: [ "master", "main" ]
paths-ignore: [ "docs/**" ]
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: false
dotnet: false
haskell: false
large-packages: true
docker-images: true
swap-storage: true
- name: Checkout Code Repository
uses: actions/[email protected]
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
- name: Run pre-commit
uses: pre-commit/[email protected]
# With no caching at all the entire ci process takes 4m 30s to complete!
pytest:
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: false
dotnet: false
haskell: false
large-packages: true
docker-images: true
swap-storage: true
- name: Checkout Code Repository
uses: actions/[email protected]
- name: Store Codecov Env Flags
run: |
# use bash variable expression to get the substring
ci_env=`bash <(curl -s https://codecov.io/env)`
echo "$ci_env"
- name: Build the Stack
run: docker compose -f test.yml build
- name: Run DB Migrations
run: docker compose -f test.yml run --rm django python manage.py migrate
- name: Collect Static Files
run: docker compose -f test.yml run --rm django python manage.py collectstatic
- name: Verify Docker Containers
run: |
docker compose -f test.yml ps
- name: Inspect Docker Network
run: |
docker network inspect $(docker compose -f test.yml ps -q | xargs docker inspect --format='{{range .NetworkSettings.Networks}}{{.NetworkID}}{{end}}' | uniq)
- name: Capture Docker Compose Logs
if: failure()
run: |
docker compose -f test.yml logs --no-color > docker-compose-logs.txt
- name: Upload Docker Compose Logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: docker-compose-logs
path: docker-compose-logs.txt
- name: Build Pytest Coverage File
run: |
docker compose -f test.yml run django coverage run -m pytest --cov-report=xml --cov
- name: Upload Coverage Reports to Codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
COMMIT_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || env.GITHUB_SHA }}
run: |
# use bash variable expression to get the substring
ci_env=`bash <(curl -s https://codecov.io/env)`
docker compose -f test.yml run $ci_env django /bin/codecov -v -t ${CODECOV_TOKEN} -R . -f coverage.xml -C ${COMMIT_SHA}
- name: Tear down the Stack
run: docker compose -f test.yml down