Skip to content

Commit

Permalink
Merge pull request #199 from jamescurtin/add-test-and-lint
Browse files Browse the repository at this point in the history
Add test and lint framework
  • Loading branch information
iragm authored Sep 2, 2024
2 parents 96571c2 + f537463 commit 98b3383
Show file tree
Hide file tree
Showing 53 changed files with 15,515 additions and 8,464 deletions.
48 changes: 48 additions & 0 deletions .github/scripts/test-and-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! /usr/bin/env bash
set -euo pipefail

RUFF_MODE=''
RUFF_FLAGS=''

usage() {
cat << EOF >&2
Usage: $0 [OPTIONS]
Options:
--ci Run in CI mode: run all tests, lints, and formatting.
Fail if changes are required
-f, --format Format the code
-F, --format-check Run the formatter and fail if changes would be made
-h, --help Show this message and exit
EOF
}

process_args() {
while test $# -gt 0
do
case "$1" in
--ci) IS_CI='true'
;;
--format | -f) RUFF_MODE='format'
;;
--format-check | -F) RUFF_MODE='format'
RUFF_FLAGS='--check'
;;
--help | -h) usage;
exit 0
;;
*) usage;
exit 1;
;;
esac
shift
done
}

process_args "$@"

if [ -z ${IS_CI+x} ]; then
eval "ruff ${RUFF_MODE} /home/app/web ${RUFF_FLAGS}"
else
ruff format /home/app/web --check
fi
38 changes: 38 additions & 0 deletions .github/scripts/update-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /usr/bin/env bash
set -euo pipefail

UPGRADE_DEPS=''

usage() {
cat << EOF >&2
Usage: $0 [OPTIONS]
Options:
-u, --upgrade Upgrade all dependencies to the latest version
DEFAULT: Without setting this flag, only new dependencies are added
-h, --help Show this message and exit
EOF
}

process_args() {
while test $# -gt 0
do
case "$1" in
--upgrade | -u) UPGRADE_DEPS='--upgrade'
;;
--help | -h) usage;
exit 0
;;
*) usage;
exit 1;
;;
esac
shift
done
}

process_args "$@"

docker compose up -d

eval "docker exec django pip-compile ./requirements.in ${UPGRADE_DEPS}"
eval "docker exec django pip-compile ./requirements-test.in ${UPGRADE_DEPS}"
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test
on:
push:
pull_request:
branches: [master]

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./.github/scripts/prepare-ci.sh
- run: docker compose run --rm test --ci
17 changes: 15 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"python.linting.pylintEnabled": false,
"python.linting.banditEnabled": true,
"python.linting.enabled": true
}
"python.linting.enabled": true,
"ruff.enable": true,
"ruff.codeAction.fixViolation": {
"enable": true
},
"ruff.lint.enable": true,
"ruff.lint.run": "onType",
}
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ COPY ./requirements.in .
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt

#########
# Test and CI #
#########

# pull official base image
FROM python:3.11.9-slim AS test
COPY ./requirements-test.txt .
RUN pip install -r requirements-test.txt

#########
# FINAL #
Expand Down
Loading

0 comments on commit 98b3383

Please sign in to comment.