Skip to content

merge

merge #2028

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Check
on:
push: {}
pull_request: {}
env:
PYTHON_VERSION: 3.12.3
PYTHONUNBUFFERED: 1
APP_URL: https://4geeks.com
# cache ------------------------------------
# | |> dependencies
# |> undefined-and-unused-variables |> migrations
# |> bad-docstrings |
# |> code-complexity |> tests -------|> dockerhub
# |> naming-conventions |> linter
# |> unexpected-behaviors |> pages
jobs:
cache:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.cache.outputs.cache-hit }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install dependencies using Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install pipenv
pipenv install --dev
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Determine Pipenv virtual environment location
run: |
echo "Virtualenv location: $(pipenv --venv)"
migrations:
needs: cache
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Check migrations
run: |
pipenv run python ./scripts/pending_migrations.py
dependencies:
needs: cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Calculate initial MD5 for Pipfile.lock
id: calculate-md5-1
run: pipenv run pip freeze -r requirements.txt > requirements.txt
- name: Update dependencies
run: |
pipenv update --dev --bare
- name: Calculate updated MD5 for Pipfile.lock
id: calculate-md5-2
run: pipenv run pip freeze -r requirements2.txt > requirements2.txt
- name: Check Pipfile.lock is up-to-date
run: diff requirements.txt requirements2.txt
undefined-and-unused-variables:
needs: cache
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Check for undefined variables
run: pipenv run flake8 --select=F
# bad-docstrings:
# needs: cache
# runs-on: ubuntu-latest
# continue-on-error: true
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python ${{ env.PYTHON_VERSION }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# # Cache Pipenv packages
# - name: Cache Pipenv packages
# uses: actions/cache@v2
# id: cache
# with:
# path: |
# ~/.local/share/virtualenvs
# ~/.cache/pip
# key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# # Install Pipenv
# - name: Install dependencies
# if: steps.cache.outputs.cache-hit == 'true'
# run: |
# pip install pipenv
# - name: Check for undefined variables
# run: pipenv run flake8 --select=D
# code-complexity:
# needs: cache
# runs-on: ubuntu-latest
# continue-on-error: true
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python ${{ env.PYTHON_VERSION }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# # Cache Pipenv packages
# - name: Cache Pipenv packages
# uses: actions/cache@v2
# id: cache
# with:
# path: |
# ~/.local/share/virtualenvs
# ~/.cache/pip
# key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# # Install Pipenv
# - name: Install dependencies
# if: steps.cache.outputs.cache-hit == 'true'
# run: |
# pip install pipenv
# - name: Check for undefined variables
# run: pipenv run flake8 --select=C
naming-conventions:
needs: cache
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Check for undefined variables
run: pipenv run flake8 --select=N
unexpected-behaviors:
needs: cache
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Check for undefined variables
run: pipenv run flake8 --select=B
tests:
needs: [migrations]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Run tests
run: |
pipenv run pcov_ci
# codecov stop working
# - uses: codecov/codecov-action@v3
# if: ${{ github.event_name == 'pull_request' || github.repository == 'breatheco-de/apiv2' }}
# with:
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
# files: ./coverage.xml # optional
# flags: unittests # optional
# name: codecov-umbrella # optional
# fail_ci_if_error: true # optional (default = false)
# verbose: true # optional (default = false)
- name: Upload coverage data to coveralls.io
if: ${{ github.event_name == 'pull_request' || github.repository == 'breatheco-de/apiv2' }}
run: |
pipenv run coveralls --service=github
env:
GITHUB_TOKEN: ${{ github.token }}
linter:
needs: [migrations]
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Linter
run: |
pipenv run format
pages:
needs: [migrations]
if: >-
github.repository == 'breatheco-de/apiv2' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/development'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
# Cache Pipenv packages
- name: Cache Pipenv packages
uses: actions/cache@v2
id: cache
with:
path: |
~/.local/share/virtualenvs
~/.cache/pip
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.PYTHON_VERSION }}-
# Install Pipenv
- name: Install dependencies
if: steps.cache.outputs.cache-hit == 'true'
run: |
pip install pipenv
- name: Deploy docs
run: pipenv run mkdocs gh-deploy --force
dockerhub:
needs: tests
runs-on: ubuntu-latest
if: >-
github.repository == 'breatheco-de/apiv2' &&
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development')
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: geeksacademy/breathecode
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}