From a08783fd1b2b1bee45789fb2e1131d249651c430 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Wed, 4 Sep 2024 12:39:34 -0700 Subject: [PATCH] Update CI/CD --- .github/deploy/staging.yaml | 6 ++++ .github/workflows/ci-cd.yaml | 4 +++ Makefile | 50 ++++++++++++++------------ backend/apps/github/models/__init__.py | 11 ++++-- docker-compose.yaml | 2 +- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/.github/deploy/staging.yaml b/.github/deploy/staging.yaml index a9cbbbba8..4d97dab55 100644 --- a/.github/deploy/staging.yaml +++ b/.github/deploy/staging.yaml @@ -13,6 +13,12 @@ dest: ~/docker-compose.yaml mode: '0644' + - name: Copy Makefile + ansible.builtin.copy: + src: '{{ playbook_dir }}/../../Makefile' + dest: ~/Makefile + mode: '0644' + - name: Stop Services shell: cmd: 'docker-compose rm --stop --force' diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 52ecd10ef..2cc38fee8 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -21,6 +21,8 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: + cache: poetry + cache-dependency-path: backend/poetry.lock python-version: '3.12' - name: Run pre-commit uses: pre-commit/action@v3.0.1 @@ -58,6 +60,8 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: + cache: poetry + cache-dependency-path: backend/poetry.lock python-version: '3.12' - name: Install dependencies diff --git a/Makefile b/Makefile index 18ad41c78..b054fd330 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,46 @@ build: @docker compose build - @CMD="poetry install" $(MAKE) run-backend-local-command - @CMD="poetry run python manage.py migrate" $(MAKE) run-backend-local-command + @CMD="poetry install" $(MAKE) run-backend-command + @CMD="poetry run python manage.py migrate" $(MAKE) run-backend-command collect-static: - @CMD="poetry run python manage.py collectstatic --noinput" $(MAKE) run-backend-local-command + @CMD="poetry run python manage.py collectstatic --noinput" $(MAKE) run-backend-command + +github-sync-owasp-organization: + @CMD="poetry run python manage.py github_sync_owasp_organization" $(MAKE) run-backend-command + +github-sync-related-repositories: + @CMD="poetry run python manage.py github_sync_related_repositories" $(MAKE) run-backend-command migrate: - @CMD="poetry run python manage.py migrate" $(MAKE) run-backend-local-command + @CMD="poetry run python manage.py migrate" $(MAKE) run-backend-command migrations: - @CMD="poetry run python manage.py makemigrations" $(MAKE) run-backend-local-command + @CMD="poetry run python manage.py makemigrations" $(MAKE) run-backend-command -run: - @docker compose up +owasp-scrape-site-data: + @CMD="poetry run python manage.py owasp_scrape_site_data" $(MAKE) run-backend-command + +owasp-update-projects: + @CMD="poetry run python manage.py owasp_update_projects" $(MAKE) run-backend-command pre-commit: @pre-commit run -a -run-backend-local-command: - @docker compose run --rm backend-local $(CMD) +run: + @docker compose up + +run-backend-command: + @docker compose run --rm backend $(CMD) shell: - @CMD="/bin/bash" $(MAKE) run-backend-local-command + @CMD="/bin/bash" $(MAKE) run-backend-command + +sync: + $(MAKE) github-sync-owasp-organization + $(MAKE) owasp-scrape-site-data + $(MAKE) github-sync-related-repositories + $(MAKE) owasp-update-projects test: @cd backend && poetry run pytest; cd .. - -github-sync-owasp-organization: - @CMD="poetry run python manage.py github_sync_owasp_organization" $(MAKE) run-backend-local-command - -github-sync-related-repositories: - @CMD="poetry run python manage.py github_sync_related_repositories" $(MAKE) run-backend-local-command - -owasp-scrape-site-data: - @CMD="poetry run python manage.py owasp_scrape_site_data" $(MAKE) run-backend-local-command - -owasp-update-projects: - @CMD="poetry run python manage.py owasp_update_projects" $(MAKE) run-backend-local-command diff --git a/backend/apps/github/models/__init__.py b/backend/apps/github/models/__init__.py index e1dd667a2..163c7b411 100644 --- a/backend/apps/github/models/__init__.py +++ b/backend/apps/github/models/__init__.py @@ -1,6 +1,8 @@ """Github app.""" -from django.conf import settings +import logging + +from github.GithubException import UnknownObjectException from apps.github.models.issue import Issue from apps.github.models.label import Label @@ -10,6 +12,8 @@ from apps.github.models.user import User from apps.github.utils import check_owasp_site_repository +logger = logging.getLogger(__name__) + def sync_repository(gh_repository, organization=None, user=None): """Sync GitHub repository data.""" @@ -76,7 +80,10 @@ def sync_repository(gh_repository, organization=None, user=None): # Labels. issue.labels.clear() for gh_issue_label in gh_issue.labels: - issue.labels.add(Label.update_data(gh_issue_label)) + try: + issue.labels.add(Label.update_data(gh_issue_label)) + except UnknownObjectException: + logger.info("Couldn't get GitHub issue label %s", issue.url) # GitHub repository releases. releases = [] diff --git a/docker-compose.yaml b/docker-compose.yaml index f4c187d6f..3e405aee0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,5 @@ services: - backend-local: + backend: container_name: nest-backend command: > bash -c