-
Notifications
You must be signed in to change notification settings - Fork 7
125 lines (116 loc) · 3.29 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
name: Tests
env:
COVERAGE_THRESHOLD: 80
DOCKER_IMAGE_REPO: bandirom/django-template
on:
workflow_call:
secrets:
DOCKER_HUB_USERNAME:
required: true
DOCKER_HUB_ACCESS_TOKEN:
required: true
push:
branches-ignore:
- master
tags-ignore:
- v*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: "Build and Push Dev Image"
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Set environment docker tag
id: set-docker-tag
run: |
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}")
echo "DOCKER_TAG=${BRANCH_NAME}" >> $GITHUB_ENV
- name: Set environment docker image
run: echo "DOCKER_IMAGE=${{ env.DOCKER_IMAGE_REPO }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and Push Dev Image with Cache
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.DOCKER_IMAGE }}
file: docker/dev/web/Dockerfile
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}
cache-to: type=inline
test:
name: "Run Tests"
runs-on: ubuntu-latest
needs: [ build ]
env:
SECRET_KEY: dummy
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
steps:
- name: Set environment docker tag
run: |
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}")
echo "DOCKER_TAG=${BRANCH_NAME}" >> $GITHUB_ENV
- name: Set environment docker image
run: echo "DOCKER_IMAGE=${{ env.DOCKER_IMAGE_REPO }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
- name: Pull Docker Image
run: docker pull ${{ env.DOCKER_IMAGE }}
- name: Migration Check
run: docker run --entrypoint="" ${{ env.DOCKER_IMAGE }} python manage.py makemigrations --check
- name: Run Tests
run: docker run --entrypoint="" ${{ env.DOCKER_IMAGE }} pytest
services:
postgres:
image: postgres:15.1-alpine
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_PASSWORD: postgres
test_isort:
runs-on: ubuntu-latest
steps:
- name: CheckOut Repo
uses: actions/checkout@v4
- name: Run isort
run: |
pip install isort
cd web
isort . --check
test_black:
runs-on: ubuntu-latest
steps:
- name: CheckOut Repo
uses: actions/checkout@v4
- name: Run black
id: tests
run: |
pip install black
cd web
black . --check
test_flake8:
runs-on: ubuntu-latest
steps:
- name: CheckOut Repo
uses: actions/checkout@v4
- name: Run Flake8
run: |
pip install flake8
cd web
flake8 .