Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOL GitHub Actions #35

Merged
merged 10 commits into from
Oct 18, 2024
67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Cache and Load Build

on:
workflow_call:
inputs:
command:
required: true
type: string
name:
required: true
type: string

jobs:
reusable-build:
name: ${{ inputs.name }}
runs-on: ubuntu-latest
steps:

#------------------------------------------------
# Checkout repo and setup python
#------------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.11'

#------------------------------------------------
# Load cached venv if cache exists
#------------------------------------------------
- name: Restore cached virtualenv
uses: actions/cache/restore@v4
id: restore-cache
with:
key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('dev_requirements.txt') }}
path: .venv

#------------------------------------------------
# Install dependencies - if cache does not exist
#------------------------------------------------
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install .[DEV]
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV

#------------------------------------------------
# Save venv to cache - if not exists
#------------------------------------------------
- name: Saved cached virtualenv
if: steps.restore-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
path: .venv

#------------------------------------------------
# Run custom command(s) within venv
#------------------------------------------------
- name: Run commands
run: |
source .venv/bin/activate
${{ inputs.command }}
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Continuous Integration

on:
pull_request:
push:
branches: [main, dev]

jobs:
#----------------------------------------------
# Build Environment
#----------------------------------------------
build:
name: Build
uses: ./.github/workflows/build.yml
with:
name: Cache
command: |
python -m pip list
python --version
echo "Build successful"

#----------------------------------------------
# Run Linters
#----------------------------------------------
lint-black:
name: Linter
needs: build
uses: ./.github/workflows/build.yml
with:
name: Black
command: python -m black --check .
lint-isort:
name: Linter
needs: build
uses: ./.github/workflows/build.yml
with:
name: Isort
command: python -m isort --check-only .
lint-mypy:
name: Linter
needs: build
if: false # This condition ensures the job is never executed
uses: ./.github/workflows/build.yml
with:
name: Mypy
command: python -m mypy --verbose 0 .
lint-flake8:
name: Linter
needs: build
uses: ./.github/workflows/build.yml
with:
name: Flake8
command: python -m flake8 .

#----------------------------------------------
# Run Tests
#----------------------------------------------
test-unittest:
name: Tests
needs: [
lint-black,
lint-isort,
lint-mypy,
lint-flake8,
]
# `${{ always() }}` will run the tests regardless of linting success
if: false # This condition ensures the job is never executed
uses: ./.github/workflows/build.yml
with:
name: Unittests
command: pytest tests/