Merge branch 'master' of https://github.com/bandirom/django-template … #118
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: Tests | |
env: | |
COVERAGE_THRESHOLD: 80 | |
DOCKER_IMAGE_REPO: bandirom/django-template | |
on: | |
workflow_call: | |
secrets: | |
DOCKER_HUB_USERNAME: | |
required: true | |
DOCKER_HUB_ACCESS_TOKEN: | |
required: true | |
push: | |
branches-ignore: | |
- master | |
tags-ignore: | |
- v* | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: "Build and Push Dev Image" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
- name: Set environment docker tag | |
id: set-docker-tag | |
run: | | |
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}") | |
echo "DOCKER_TAG=${BRANCH_NAME}" >> $GITHUB_ENV | |
- name: Set environment docker image | |
run: echo "DOCKER_IMAGE=${{ env.DOCKER_IMAGE_REPO }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build and Push Dev Image with Cache | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.DOCKER_IMAGE }} | |
file: docker/dev/web/Dockerfile | |
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }} | |
cache-to: type=inline | |
test: | |
name: "Run Tests" | |
runs-on: ubuntu-latest | |
needs: [ build ] | |
env: | |
SECRET_KEY: dummy | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: postgres | |
POSTGRES_HOST: postgres | |
POSTGRES_PORT: 5432 | |
steps: | |
- name: Set environment docker tag | |
run: | | |
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}") | |
echo "DOCKER_TAG=${BRANCH_NAME}" >> $GITHUB_ENV | |
- name: Set environment docker image | |
run: echo "DOCKER_IMAGE=${{ env.DOCKER_IMAGE_REPO }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV | |
- name: Pull Docker Image | |
run: docker pull ${{ env.DOCKER_IMAGE }} | |
- name: Migration Check | |
run: docker run --entrypoint="" ${{ env.DOCKER_IMAGE }} python manage.py makemigrations --check | |
- name: Run Tests | |
run: docker run --entrypoint="" ${{ env.DOCKER_IMAGE }} pytest | |
services: | |
postgres: | |
image: postgres:15.1-alpine | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
env: | |
POSTGRES_PASSWORD: postgres | |
test_isort: | |
runs-on: ubuntu-latest | |
steps: | |
- name: CheckOut Repo | |
uses: actions/checkout@v4 | |
- name: Run isort | |
run: | | |
pip install isort | |
cd web | |
isort . --check | |
test_black: | |
runs-on: ubuntu-latest | |
steps: | |
- name: CheckOut Repo | |
uses: actions/checkout@v4 | |
- name: Run black | |
id: tests | |
run: | | |
pip install black | |
cd web | |
black . --check | |
test_flake8: | |
runs-on: ubuntu-latest | |
steps: | |
- name: CheckOut Repo | |
uses: actions/checkout@v4 | |
- name: Run Flake8 | |
run: | | |
pip install flake8 | |
cd web | |
flake8 . |