-
Notifications
You must be signed in to change notification settings - Fork 12
141 lines (135 loc) · 4.79 KB
/
checks.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
# This workflow will build the project with multiple Python versions, lint, run
# tests, and build and push Docker images.
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: CI
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]
jobs:
Test:
name: Run linting and unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
py-version-img: [
["3.9", "3.9-slim-bookworm"],
["3.10", "3.10-slim-bookworm"],
["3.11", "3.11-slim-bookworm"],
["3.12", "3.12-slim-bookworm"],
]
mongodb-version: ["4.4", "5.0", "6.0", "7.0"]
mongodb-port: [12345]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.py-version-img[0] }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py-version-img[0] }}
- name: Install requirements
run: |
pip install -e .[dev]
- name: Lint with flake8
run: flake8
- name: Run mypy
run: mypy foca
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-port: ${{ matrix.mongodb-port }}
- name: Calculate unit test coverage
run: |
coverage run --source foca -m pytest -W ignore::DeprecationWarning
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: test_unit
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
- name: Run tests on petstore app
env:
DOCKERHUB_ORG: ${{ secrets.DOCKERHUB_ORG }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
export PY_VERSION=${{ matrix.py-version-img[0] }}
export PY_IMAGE=${{ matrix.py-version-img[1] }}
docker build \
-t ${DOCKERHUB_ORG}/${REPO_NAME}:petstore \
-f docker/Dockerfile \
--build-arg PY_IMAGE=${PY_IMAGE} \
.
cd ./examples/petstore
docker-compose up --build -d
cd ../..
sleep 10
pytest ./tests/integration_tests.py
Docker:
runs-on: ubuntu-latest
needs: [Test]
strategy:
fail-fast: true
matrix:
py-version-img-tag: [
["3.9", "3.9-slim-bookworm", ""],
["3.10", "3.10-slim-bookworm", ""],
["3.11", "3.11-slim-bookworm", ""],
["3.12", "3.12-slim-bookworm", "latest"],
]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Build & Publish image to DockerHub
env:
DOCKERHUB_ORG: ${{ secrets.DOCKERHUB_ORG }}
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
REPO_NAME: ${{ github.event.repository.name }}
run: |
set -x
export ON_LATEST=FALSE
export ON_DEFAULT=FALSE
export PY_VERSION=${{ matrix.py-version-img-tag[0] }}
export PY_IMAGE=${{ matrix.py-version-img-tag[1] }}
export PY_TAG=${{ matrix.py-version-img-tag[2] }}
export DEFAULT_BRANCH=${{ github.event.repository.default_branch }}
if [[ "$PY_TAG" == "latest" ]]; then
export ON_LATEST=TRUE
fi
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
export BRANCH_NAME=${GITHUB_REF##*/}
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
export BRANCH_NAME=${GITHUB_HEAD_REF##*/}
else
export BRANCH_NAME=INVALID_EVENT_BRANCH_UNKNOWN
fi
if [[ "$BRANCH_NAME" == "$DEFAULT_BRANCH" ]]; then
export TAG=$(date '+%Y%m%d')
export ON_DEFAULT=TRUE
else
export TAG=$BRANCH_NAME
fi
export TAG="${TAG}-py${PY_VERSION}"
echo "TAG: ${TAG}"
docker build \
-t ${DOCKERHUB_ORG}/${REPO_NAME}:${TAG} \
-f docker/Dockerfile \
--build-arg PY_IMAGE=${PY_IMAGE} \
.
echo $DOCKERHUB_TOKEN | \
docker login -u $DOCKERHUB_LOGIN --password-stdin
docker push ${DOCKERHUB_ORG}/${REPO_NAME}:${TAG}
# if on default branch, we also want to update the "latest" tag
if [[ "$ON_LATEST" = "TRUE" && "$ON_DEFAULT" == "TRUE" ]]; then
docker tag \
${DOCKERHUB_ORG}/${REPO_NAME}:${TAG} \
${DOCKERHUB_ORG}/${REPO_NAME}:latest
docker push ${DOCKERHUB_ORG}/${REPO_NAME}:latest
fi
rm ${HOME}/.docker/config.json