Skip to content

Commit

Permalink
WMDP-195: Automatically run linting/formatting/tests in CI for PRs an…
Browse files Browse the repository at this point in the history
…d merges to main (#21)

WMDP-195: Automatically run linting/formatting/tests in CI for PRs and merges to main
  • Loading branch information
chouinar authored Sep 21, 2022
1 parent d7d6247 commit 5aa4080
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 22 deletions.
41 changes: 29 additions & 12 deletions .github/workflows/api-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,50 @@ on:
- main
paths:
- app/**
# this workflow should be updated/merged when WMDP-123. etc are merged
- .github/workflows/api-checks.yml
pull_request:
paths:
- app/**
- .github/workflows/api-checks.yml

defaults:
run:
working-directory: ./app

env:
# Some commands in the Makefile check if this is set
# and add additional parameters to the commands called
CI: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run Linting
run: |
echo "Placeholder until linting is installed"
exit 0
- name: build container
run: make build

- name: Run format check
run: make format-check

- name: Run linting
run: make lint
security:
runs-on: ubutntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Security Check
run: |
echo "Placeholder until security tools are installed"
exit 0
run: make lint-security
test:
needs: [lint, security]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: test for multi-headed migration situation
run: make test args="-x tests/api/db/test_migrations.py::test_only_single_head_revision_in_migrations"

- name: Start tests
run: |
echo "Placeholder until tests are written"
exit 0
run: make test-coverage
20 changes: 14 additions & 6 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ db-migrate-heads: ## Show migrations marked as a head
test:
$(PY_RUN_CMD) pytest $(args)

test-coverage:
$(PY_RUN_CMD) coverage run --branch --source=api -m pytest $(args)
$(PY_RUN_CMD) coverage report

test-coverage-report: ## Open HTML test coverage report
$(PY_RUN_CMD) coverage html --directory .coverage_report
open .coverage_report/index.html

##################################################
# Formatting and linting
##################################################
Expand All @@ -127,6 +135,10 @@ format:
$(PY_RUN_CMD) isort --atomic api tests
$(PY_RUN_CMD) black api tests

format-check:
$(PY_RUN_CMD) isort --atomic --check-only api tests
$(PY_RUN_CMD) black --check api tests

lint: lint-spectral lint-py

lint-py: lint-flake lint-mypy lint-poetry-version
Expand All @@ -144,13 +156,9 @@ lint-spectral:
docker run --rm --tty --cap-drop=ALL --network=none --read-only --volume=$(PWD):/tmp:ro \
stoplight/spectral:6 lint /tmp/openapi.yml --ruleset /tmp/.spectral.yaml $(SPECTRAL_POSTPROC)

test-coverage:
$(PY_RUN_CMD) coverage run --branch --source=api -m pytest $(args)
$(PY_RUN_CMD) coverage report
lint-security: # https://bandit.readthedocs.io/en/latest/index.html
$(PY_RUN_CMD) bandit -r . --number 3 --skip B101 -ll -x ./.venv

test-coverage-report: ## Open HTML test coverage report
$(PY_RUN_CMD) coverage html --directory .coverage_report
open .coverage_report/index.html

##################################################
# Scripts
Expand Down
82 changes: 78 additions & 4 deletions app/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mypy = "^0.971"
moto = {extras = ["s3"], version = "^4.0.2"}
types-pytz = "^2022.2.1"
coverage = "^6.4.4"
bandit = "^1.7.4"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down Expand Up @@ -77,6 +78,8 @@ warn_unused_ignores = true

plugins = ["sqlalchemy.ext.mypy.plugin"]



[[tool.mypy.overrides]]
# Migrations are generated without "-> None"
# for the returns. Rather than require manually
Expand Down

0 comments on commit 5aa4080

Please sign in to comment.