Skip to content

Test, Build & Push

Test, Build & Push #41

Workflow file for this run

# This is a basic workflow to help you get started with Actions
name: Test, Build & Push
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
paths:
- '**.py'
- '.github/workflows/main.yml'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Create env file
uses: SpicyPizza/[email protected]
with:
file_name: config.env
directory: data/
envkey_JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
envkey_JSON_SECRET_KEY: ${{ secrets.JSON_SECRET_KEY }}
envkey_ALGORITHM: ${{ secrets.ALGORITHM }}
envkey_ACCESS_TOKEN_EXPIRE_MINUTES: ${{ secrets.ACCESS_TOKEN_EXPIRE_MINUTES }}
envkey_ENABLE_REGISTRATIONS: ${{ secrets.ENABLE_REGISTRATIONS }}
envkey_ENCRYPT_JSON: ${{ secrets.ENCRYPT_JSON }}
envkey_RELOAD: ${{ secrets.RELOAD }}
envkey_HOST: ${{ secrets.HOST }}
envkey_PORT: ${{ secrets.PORT }}
envkey_DATA_DIR: ${{ secrets.DATA_DIR }}
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies if cache doesn't exist
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction
- name: Run tests and generate coverage report
run: cd src; poetry run python -m pytest ../tests/ -v --cov ./ --cov-report xml:/tmp/coverage.xml
- name: Upload coverage
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: /tmp/coverage.xml
docker:
needs: test
runs-on: ubuntu-latest
steps:
- name: Set tag env
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-7)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/todo-fastapi:${{ env.GITHUB_SHA_SHORT }}, ${{ secrets.DOCKER_HUB_USERNAME }}/todo-fastapi:latest