tests added #110
Workflow file for this run
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
# 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.11 | |
PYTHONUNBUFFERED: 1 | |
# cache ------------------------------------ | |
# | |> migrations -------- | |
# |> undefined-and-unused-variables |> dependencies ------ | |
# |> bad-docstrings | | |
# |> code-complexity |> tests -------|> pages | |
# |> naming-conventions |> linter |> dockerhub | |
# |> unexpected-behaviors | |
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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }} | |
- name: Calculate initial MD5 for Pipfile.lock | |
id: calculate-md5-1 | |
run: echo "MD5_1=$(python -m scripts.md5 ./Pipfile.lock)" >> $GITHUB_ENV | |
# Cache Pipenv packages | |
- name: Cache Pipenv packages | |
uses: actions/cache@v2 | |
id: cache | |
with: | |
path: | | |
~/.local/share/virtualenvs | |
~/.cache/pip | |
key: ${{ runner.os }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# Install Pipenv | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit == 'true' | |
run: | | |
pip install pipenv | |
- name: Calculate updated MD5 for Pipfile.lock | |
id: calculate-md5-2 | |
run: echo "MD5_2=$(python -m scripts.md5 ./Pipfile.lock)" >> $GITHUB_ENV | |
- name: Check Pipfile.lock is up-to-date | |
run: | | |
if [ "$MD5_1" != "$MD5_2" ]; then | |
echo "Pipfile.lock is out of date. Please run 'pipenv lock --dev' and commit the updated Pipfile.lock."; | |
exit 1; | |
fi | |
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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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, dependencies] | |
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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# Install Pipenv | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit == 'true' | |
run: | | |
pip install pipenv | |
- name: Run tests | |
run: | | |
pipenv run pcov_ci | |
- 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, dependencies] | |
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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# Install Pipenv | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit == 'true' | |
run: | | |
pip install pipenv | |
- name: Linter | |
run: | | |
pipenv run format | |
pages: | |
needs: tests | |
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 }}-pipenv3-${{ hashFiles('**/Pipfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pipenv3- | |
# 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 }} |