Skip to content

Merge pull request #36 from Bubhux/development #224

Merge pull request #36 from Bubhux/development

Merge pull request #36 from Bubhux/development #224

name: Django CI/CD Master
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build_and_test:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run linting
run: flake8
- name: Run tests with pytest
env:
SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
DEBUG: 0
run: pytest
- name: Run Django tests
run: python manage.py test
- name: Run tests with coverage
run: |
coverage run --omit=*/tests.py manage.py test
- name: Check test coverage
run: coverage report --fail-under=80
build_and_push_to_dockerhub:
needs: build_and_test
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
run: |
docker buildx build --load --file Dockerfile --tag bubhux/bubhux-oc-image-build:${{ github.sha }} --tag bubhux/bubhux-oc-image-build:latest .
docker push bubhux/bubhux-oc-image-build:${{ github.sha }}
docker push bubhux/bubhux-oc-image-build:latest
- name: Set IMAGE_ID environment variable
run: |
IMAGE_ID=$(docker inspect --format='{{.Id}}' bubhux/bubhux-oc-image-build:${{ github.sha }})
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
- name: Tag Docker image with commit hash
run: |
docker tag bubhux/bubhux-oc-image-build:${{ github.sha }} bubhux/bubhux-oc-image-build:commit-${{ github.sha }}
# deploy_to_heroku:
# needs: build_and_push_to_dockerhub
# runs-on: ubuntu-22.04
#
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
#
# - name: Install Heroku CLI
# run: curl https://cli-assets.heroku.com/install.sh | sh
#
# - name: Purge Heroku cache
# run: |
# heroku plugins:install heroku-repo
# heroku repo:purge_cache -a ${{ secrets.HEROKU_APP_NAME }}
#
# - name: Log in to Heroku Container Registry
# run: heroku container:login
# env:
# HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
#
# - name: Push to Heroku Container Registry
# run: heroku container:push -a ${{ secrets.HEROKU_APP_NAME }} web
#
# - name: Deploy to Heroku
# run: |
# HEROKU_DEBUG=1 heroku container:release -a ${{ secrets.HEROKU_APP_NAME }} web