From 8499074979a1ad632298ca3fb03eec94fcaf9d3e Mon Sep 17 00:00:00 2001 From: Andrew4Coding Date: Tue, 1 Oct 2024 00:08:00 +0700 Subject: [PATCH] feat: initialize main module and deploy yml --- .github/workflows/deploy.yml | 42 ++++++++++++++++++++++++++++++++++++ eventyog/settings.py | 12 ++++++++--- eventyog/urls.py | 3 ++- main/__init__.py | 0 main/admin.py | 3 +++ main/apps.py | 6 ++++++ main/migrations/__init__.py | 0 main/models.py | 3 +++ main/tests.py | 3 +++ main/urls.py | 8 +++++++ main/views.py | 5 +++++ 11 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 main/__init__.py create mode 100644 main/admin.py create mode 100644 main/apps.py create mode 100644 main/migrations/__init__.py create mode 100644 main/models.py create mode 100644 main/tests.py create mode 100644 main/urls.py create mode 100644 main/views.py diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..38fe332 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,42 @@ +name: Push to PWS + +on: + push: + branches: [ main, master ] + paths-ignore: + - '**.md' + pull_request: + branches: [ main, master ] + paths-ignore: + - '**.md' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Check PWS remote, pull, merge, and push + env: + PWS_URL: ${{ secrets.PWS_URL }} + run: | + echo "Creating temporary branch" + git checkout -b tmp + + # Push to master branch and capture the output + push_output=$(git push $PWS_URL tmp:master 2>&1) + if [[ $? -ne 0 ]]; then + echo "Push failed with output: $push_output" + echo "Error: Unable to push changes. Please check the error message above and resolve any conflicts manually." + exit 1 + fi + echo "Push successful with output: $push_output" \ No newline at end of file diff --git a/eventyog/settings.py b/eventyog/settings.py index 68a0082..77dd0cf 100644 --- a/eventyog/settings.py +++ b/eventyog/settings.py @@ -37,16 +37,17 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'main' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'eventyog.urls' @@ -115,9 +116,14 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.1/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = '/static/' +STATICFILES_DIRS = [BASE_DIR / 'static'] # Default primary key field type -# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +STATIC_ROOT = BASE_DIR / 'staticfiles' + +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" \ No newline at end of file diff --git a/eventyog/urls.py b/eventyog/urls.py index 021d3fd..43593d7 100644 --- a/eventyog/urls.py +++ b/eventyog/urls.py @@ -15,8 +15,9 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('', include('main.urls')) ] diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/admin.py b/main/admin.py new file mode 100644 index 0000000..34ef61e --- /dev/null +++ b/main/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. \ No newline at end of file diff --git a/main/apps.py b/main/apps.py new file mode 100644 index 0000000..167f044 --- /dev/null +++ b/main/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MainConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'main' diff --git a/main/migrations/__init__.py b/main/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/models.py b/main/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/main/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/main/tests.py b/main/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/main/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/main/urls.py b/main/urls.py new file mode 100644 index 0000000..4953de5 --- /dev/null +++ b/main/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from main.views import * + +app_name = 'main' + +urlpatterns = [ + path('', main, name='main'), +] \ No newline at end of file diff --git a/main/views.py b/main/views.py new file mode 100644 index 0000000..a7d4e19 --- /dev/null +++ b/main/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render, HttpResponse + +# Create your views here. +def main(request): + return HttpResponse("Hello, World!") \ No newline at end of file