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

add cicd workflow for testing, pushing to docker #52

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Django Tests
on:
pull_request:
branches:
- 'main'
- 'production'
- 'staging'

jobs:
unit-tests:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Docker Compose
run: |
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

- name: Build image
run: |
docker-compose build

- name: Run Tests
run: |
docker-compose up postgres -d
docker-compose run --rm app sh -c "python manage.py wait_for_db && python manage.py migrate && python manage.py test"

- name: Stop containers
run: |
docker-compose down

code-lint-format:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Docker Compose
run: |
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

- name: Build image
run: |
docker-compose build

- name: Linting
run: |
make lint

- name: Formatting
run: |
make format



28 changes: 28 additions & 0 deletions .github/workflows/push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Push Docker Images
on:
pull_request:
types: [closed]
branches:
- 'main'

jobs:
publish-images:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_PASS }}

- name: Push Clubs Image
run: |
make docker-push-clubs

- name: Push Clubs Image
run: |
make docker-push-proxy
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apt-get update && \
apt install -f && \
apt-get install -y --no-install-recommends libpq-dev gcc g++
apt-get install -y --no-install-recommends libpq-dev gcc g++ postgresql

COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
Expand Down
4 changes: 3 additions & 1 deletion app/analytics/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class LinkAdmin(admin.ModelAdmin):
inlines = (LinkVisitInlineAdmin,)

def url_link(self, obj):
return mark_safe(f'<a href="{obj.tracking_url}" target="_blank">{obj.tracking_url}</a>')
return mark_safe(
f'<a href="{obj.tracking_url}" target="_blank">{obj.tracking_url}</a>'
)


admin.site.register(QRCode, QRCodeAdmin)
Expand Down
1 change: 0 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import sys
from pathlib import Path


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down
1 change: 1 addition & 0 deletions app/clubs/tests/test_club_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from django.urls import reverse

from analytics.models import Link
from clubs.models import Club, Event
from clubs.tests.utils import CLUB_CREATE_PARAMS, CLUB_UPDATE_PARAMS, create_test_club
Expand Down
2 changes: 0 additions & 2 deletions app/core/abstracts/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ class ViewSetBase(GenericViewSet):

class ModelViewSetBase(ModelViewSet, ViewSetBase):
"""Base viewset for model CRUD operations."""

pass
11 changes: 7 additions & 4 deletions app/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def main():
execute_from_command_line(sys.argv)

if running_tests:
cov.stop()
cov.save()
cov.report(skip_covered=True, skip_empty=True)
cov.html_report()
try:
cov.stop()
cov.save()
cov.report(skip_covered=True, skip_empty=True)
cov.html_report()
except Exception:
pass


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion app/users/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AuthLoginView(LoginView):

redirect_authenticated_user = True
template_name = "users/login-user.html"

def get_context_data(self, **kwargs):
kwargs["next"] = self.request.GET.get("next", None)
return super().get_context_data(**kwargs)
Expand Down
3 changes: 1 addition & 2 deletions app/utils/files.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import uuid
from pathlib import Path
from typing import Optional
import uuid

from app.settings import MEDIA_ROOT


# def get_media_dir(nested_path=""):
# return Path(MEDIA_ROOT, nested_path)

Expand Down
1 change: 1 addition & 0 deletions app/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from urllib.parse import urljoin

from django.http import HttpRequest
from django.urls import reverse

Expand Down
Loading