-
Notifications
You must be signed in to change notification settings - Fork 10
141 lines (121 loc) · 4.34 KB
/
pr.yml
File metadata and controls
141 lines (121 loc) · 4.34 KB
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
---
name: Pull request build
on:
pull_request:
# branches:
# - dev
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }}
cancel-in-progress: true
jobs:
build-app:
runs-on: ubuntu-latest
name: Build project
permissions:
contents: read
checks: write
pull-requests: write
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Setup Python 3.13
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: '3.13'
- name: Cache pip repository
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt', 'requirements_test.txt') }}
- name: Prepare python environment
run: |
pip install --upgrade pip
pip install -r requirements.txt -r requirements_test.txt
- name: Lint project
run: |
ruff check app/
ruff format --check app/
mypy --ignore-missing-imports app/
- name: Test project
run: pytest -v --cov --cov-report=xml:coverage.xml --junit-xml junit.xml
- name: Report test summary
uses: EnricoMi/publish-unit-test-result-action@2ceeed2b8f26e15b06c3846719f75354febd9e7b # v2
if: always()
with:
test_changes_limit: 0
files: ./junit.xml
report_individual_runs: true
- name: Push to CodeCov
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
build-docker:
runs-on: ubuntu-latest
name: Build docker
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
persist-credentials: false
- name: Hadolint Dockerfile
id: hadolint
uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
with:
dockerfile: Dockerfile
- name: Get current date
id: getDate
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Build docker image (no push)
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
build-args: |
VCS_REF=${{ github.sha }}
BUILD_DATE=${{ steps.getDate.outputs.date }}
VERSION=testing
tags: tomerfi/switcher_webapi:testing
cache-from: type=gha
cache-to: type=gha,mode=max
e2e-smoke-test:
needs: build-docker
runs-on: ubuntu-latest
name: E2E smoke test
steps:
- name: Checkout sources
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Build image for testing
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
with:
context: .
load: true
tags: switcher_webapi:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run container and test health endpoint
run: |
docker run -d --name test-container -p 8000:8000 switcher_webapi:test
for i in {1..12}; do
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/health || true)
[ "$response" = "200" ] && break
sleep 5
done
docker logs test-container
docker stop test-container
if [ "$response" != "200" ]; then
echo "Health check failed with status $response"
exit 1
fi
echo "Health check passed with status $response"