build: add py3.12 support #319
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] | |
pip install setuptools | |
- 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 |