diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 0aecf02..71a51c8 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -21,8 +21,46 @@ on: - '**/*.yml' jobs: - build: + build-normal: + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [ 3.6, 3.7, 3.8, 3.9 ] + + steps: + - name: Start MySQL + uses: samin/mysql-action@v1.3 + with: + host port: 3306 + container port: 3306 + character set server: utf8mb4 + collation server: utf8mb4_general_ci + mysql version: latest + mysql root password: root + mysql database: djangoblog + mysql user: root + mysql password: root + + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + env: + DJANGO_MYSQL_PASSWORD: root + DJANGO_MYSQL_HOST: 127.0.0.1 + run: | + python manage.py makemigrations + python manage.py migrate + python manage.py test + build-with-es: runs-on: ubuntu-latest strategy: max-parallel: 4 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 20d2423..b1f34e3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -28,10 +28,4 @@ jobs: with: context: . push: true - platforms: | - linux/amd64 - linux/arm64 - linux/arm/v7 - linux/arm/v6 - linux/386 tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoblog:latest diff --git a/blog/documents.py b/blog/documents.py index cca422b..16e9eb4 100644 --- a/blog/documents.py +++ b/blog/documents.py @@ -93,7 +93,15 @@ class ElapsedTimeDocument(Document): doc_type = 'ElapsedTime' -class ElaspedTimeDocumentManager(): +class ElaspedTimeDocumentManager: + @staticmethod + def build_index(): + from elasticsearch import Elasticsearch + client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts']) + res = client.indices.exists(index="performance") + if not res: + ElapsedTimeDocument.init() + @staticmethod def delete_index(): from elasticsearch import Elasticsearch @@ -102,12 +110,7 @@ class ElaspedTimeDocumentManager(): @staticmethod def create(url, time_taken, log_datetime, useragent, ip): - from elasticsearch import Elasticsearch - client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts']) - - res = client.indices.exists(index="performance") - if not res: - ElapsedTimeDocument.init() + ElaspedTimeDocumentManager.build_index() ua = UserAgent() ua.browser = UserAgentBrowser() ua.browser.Family = useragent.browser.family diff --git a/blog/management/commands/build_index.py b/blog/management/commands/build_index.py index 1c5a5b1..0391cc3 100644 --- a/blog/management/commands/build_index.py +++ b/blog/management/commands/build_index.py @@ -23,8 +23,8 @@ class Command(BaseCommand): def handle(self, *args, **options): if ELASTICSEARCH_ENABLED: + ElaspedTimeDocumentManager.build_index() manager = ElapsedTimeDocument() - ElaspedTimeDocumentManager.delete_index() manager.init() manager = ArticleDocumentManager() manager.delete_index()