-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add CI for volunteers page #42
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[run] | ||
branch = True | ||
source = volunteers/ | ||
|
||
[report] | ||
exclude_lines = | ||
if self.debug: | ||
pragma: no cover | ||
raise NotImplementedError | ||
if __name__ == .__main__.: | ||
ignore_errors = True | ||
omit = | ||
volunteers/tests.py | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: [push] | ||
|
||
jobs: | ||
test_job: | ||
runs-on: ubuntu-latest | ||
env: | ||
OS: ubuntu-latest | ||
PYTHON: '3.7' | ||
name: Linting and Testing | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Test action step | ||
uses: ./ | ||
id: test | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
files: ./coverage.xml | ||
flags: unittests | ||
env_vars: OS,PYTHON | ||
name: codecov-umbrella | ||
fail_ci_if_error: true | ||
path_to_write_report: ./coverage/codecov_report.txt | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,9 @@ secret.txt | |
|
||
logs | ||
static/* | ||
|
||
public/ | ||
penta.db | ||
volunteers.db | ||
.coverage | ||
coverage.xml |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: 'Test' | ||
description: 'Linting and Testing' | ||
runs: | ||
using: 'docker' | ||
image: 'ci/Dockerfile' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.7-bullseye | ||
|
||
RUN apt-get update -y && \ | ||
DEBIAN_FRONTEND="noninteractive" apt-get install -y sqlite3 | ||
|
||
COPY ./entrypoint.sh ./ | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
utils/create-venv.sh | ||
utils/install-dependencies.sh | ||
utils/setup-file-system.sh | ||
utils/setup-server.sh | ||
utils/run-linter.sh | ||
utils/run-tests.sh | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
arabic-reshaper==2.1.1 | ||
astroid==2.5.6 | ||
coverage==5.5 | ||
dj-static==0.0.6 | ||
Django==2.2.18 | ||
django-guardian==2.3.0 | ||
django-userena-ce==6.0.1 | ||
easy-thumbnails==2.5 | ||
future==0.18.2 | ||
gunicorn==20.0.4 | ||
html2text==2014.12.29 | ||
html5lib==1.1 | ||
isort==5.8.0 | ||
lazy-object-proxy==1.6.0 | ||
mccabe==0.6.1 | ||
Pillow==8.1.0 | ||
psycopg2-binary==2.8.6 | ||
pylint==2.8.2 | ||
pylint-django==2.4.4 | ||
pylint-plugin-utils==0.6 | ||
PyPDF2==1.26.0 | ||
python-bidi==0.4.2 | ||
python-dateutil==2.8.1 | ||
pytz==2021.1 | ||
reportlab==3.5.59 | ||
six==1.15.0 | ||
sqlparse==0.4.1 | ||
static3==0.7.0 | ||
toml==0.10.2 | ||
typed-ast==1.4.3 | ||
vobject==0.9.6.1 | ||
webencodings==0.5.1 | ||
wrapt==1.12.1 | ||
xhtml2pdf==0.2.5 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
python3 -m venv venv | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
. venv/bin/activate | ||
pip install -r requirements-dev.txt | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
show_help() { | ||
cat <<EOM | ||
Invocation: | ||
|
||
$0 [-h|-?] [-s] [-u USER] [-e EXECUTABLE] [--] [ARGS...] | ||
|
||
Options: | ||
|
||
-h|-? : Display this help text | ||
-s : Elevate this script to run Docker as root | ||
(default: false) | ||
-u USER : User parameter to pass on to docker run | ||
(default: current UID / GID) | ||
-e EXECUTABLE : Entrypoint to pass on to docker run | ||
(default: none) | ||
ARGS : Arguments for the dockerized process | ||
EOM | ||
} | ||
|
||
##### Option parsing ##### | ||
AS_ROOT=false | ||
USER=$(id -u):$(id -g) | ||
ENTRYPOINT= | ||
|
||
while getopts "h?su:e:" opt; do | ||
case "$opt" in | ||
h|\?) | ||
show_help | ||
exit 0 | ||
;; | ||
s) AS_ROOT=true | ||
;; | ||
u) USER=$OPTARG | ||
;; | ||
e) ENTRYPOINT=$OPTARG | ||
;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)) | ||
|
||
if [[ "${1:-}" = "--" ]]; then | ||
shift | ||
fi | ||
|
||
##### Elevate script ##### | ||
if [[ $AS_ROOT = true && $UID -ne 0 ]]; then | ||
sudo "$0" -u "$USER" -e "$ENTRYPOINT" "$@" | ||
exit | ||
fi | ||
|
||
##### Build container ##### | ||
CONTAINER_NAME=volunteers-test | ||
docker build --pull -t "$CONTAINER_NAME" ci | ||
|
||
##### Run container ##### | ||
ADDITIONAL_ARGS= | ||
EXEC_ARGS= | ||
if [[ -n "$ENTRYPOINT" ]]; then | ||
ADDITIONAL_ARGS="--entrypoint $ENTRYPOINT" | ||
fi | ||
if [[ $# -gt 0 ]]; then | ||
EXEC_ARGS="$*" | ||
fi | ||
docker run \ | ||
-v "$PWD:$PWD" \ | ||
--rm \ | ||
--name "$CONTAINER_NAME" \ | ||
--workdir "$PWD" \ | ||
--user "$USER" \ | ||
$ADDITIONAL_ARGS \ | ||
"$CONTAINER_NAME" \ | ||
$EXEC_ARGS | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
. venv/bin/activate | ||
echo " ##### Run linter #####" | ||
DJANGO_SETTINGS_MODULE=volunteer_mgmt.settings pylint --load-plugins pylint_django --fail-under=7 volunteers/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
. venv/bin/activate | ||
echo " ##### Run test #####" | ||
coverage run manage.py test | ||
coverage xml | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
mkdir -p logs tool/media/mugshots | ||
sqlite3 volunteers.db | ||
sqlite3 penta.db | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
sed "\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than using sed, I would provide a specific settings_sqlite.py and a settings_postgres.py . I'm okay doing this now, but in any case, I think we can improve how this is done: |
||
s/backends.postgresql_psycopg2/backends.sqlite3/; \ | ||
s/'NAME': '\([a-z]\+\)'/'NAME': '\1.db'/; \ | ||
" \ | ||
volunteer_mgmt/localsettings_example.py \ | ||
> volunteer_mgmt/localsettings.py | ||
|
||
. venv/bin/activate | ||
./manage.py migrate | ||
./manage.py collectstatic | ||
./manage.py createsuperuser --noinput --username test --email [email protected] | ||
|
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
|
||
Replace this with more appropriate tests for your application. | ||
Tests to be run via "manage.py test" | ||
""" | ||
|
||
from unittest.mock import patch | ||
from django.test import TestCase | ||
from volunteers.views import promo | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) | ||
class PromoTestCase(TestCase): | ||
@patch('volunteers.views.render') | ||
def test_promo_view_renders_static_page(self, render_mock): | ||
static_promo_page_content = 'Some promo page' | ||
render_mock.return_value = static_promo_page_content | ||
ret = promo(None) | ||
self.assertEqual(ret, static_promo_page_content) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not make a big difference, but we tend to use debian rather than ubuntu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get "Can't find any online and idle self-hosted runner in the current repository, account/organization that matches the required labels: 'debian-latest'" when I try that.
It seems like GitHub has decided to stick with Ubuntu for all of their Linux CI hosts: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
So, unfortunately, we will be limited to the Docker container for Debian.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SourceHut offers Debian VM images and I'd be glad to integrate it with this repo if it is desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The os doesn't really matter as we are using a virtualenv anyway. But thanks for the suggestion anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed @johanvdw , but @McSinyx if you have a plan how to do that integration, I would be fine with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it would require either trusting me for owner privilege or creating a paying account for FOSDEM ($20/year; builds.sr.ht got hit by cryptocurrency miners and decided to require payment earlier than initially planned). Personally I'm OK with either but it's up for the maintainers to decide if it's worth it.