Update ci.yml #15
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
name: CI | |
on: | |
push: | |
branches: | |
- "main" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
needs: [ container-scan ] | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/fastapi-starter:latest | |
unit-testing: | |
runs-on: ubuntu-latest | |
steps: | |
- name : Checkout code | |
uses : actions/checkout@v4 | |
- name: Setup Python | |
uses : actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements-dev.txt | |
pip install -r requirements.txt | |
pip install -r requirements-test.txt | |
- name: Formating and linting | |
run: | | |
black . | |
isort ./api | |
autoflake --in-place -r ./api | |
continue-on-error: true | |
- name : Run tests | |
run : pytest ./tests/tests.py | |
- name: Run coverage | |
run : coverage run -m pytest ./tests/tests.py | |
- name: Publish Coverage Report | |
run : coverage report -m | |
container-scan: | |
runs-on: ubuntu-latest | |
needs: [ unit-testing ] | |
steps: | |
- name : Checkout code | |
uses: actions/checkout@v4 | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: '${{ secrets.DOCKERHUB_USERNAME }}/fastapi-starter:latest' | |
format: 'table' | |
exit-code: '1' |