From 46aced56a244618485952f0e572e3fef2cb5c0d2 Mon Sep 17 00:00:00 2001 From: Her Email Date: Sun, 19 Nov 2023 10:59:51 -0500 Subject: [PATCH] properly add version to package --- .github/workflows/publish.yml | 1 - Dockerfile | 2 +- boofilsic/__init__.py | 1 + boofilsic/settings.py | 12 ++++++++++-- common/management/commands/cron.py | 3 --- common/models.py | 10 ++++++++++ common/setup.py | 2 ++ misc/bin/neodb-hello | 4 ++-- misc/bin/neodb-init | 9 +++------ misc/bin/neodb-version | 2 ++ 10 files changed, 31 insertions(+), 15 deletions(-) create mode 100755 misc/bin/neodb-version diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3b3b4d14..a8c14149 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,7 +5,6 @@ on: workflows: ["unit test"] branches: - main - - activitypub types: - completed diff --git a/Dockerfile b/Dockerfile index c970bb38..cf1c6341 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN --mount=type=cache,sharing=locked,target=/var/cache/apt apt-get update \ COPY . /neodb -RUN echo neodb-`cd /neodb && git rev-parse --short HEAD`-`cd /neodb/neodb-takahe && git rev-parse --short HEAD`-`date -u +%Y%m%d%H%M%S` > /neodb/version +RUN echo `cd /neodb && git rev-parse --short HEAD`-`cd /neodb/neodb-takahe && git rev-parse --short HEAD`-`date -u +%Y%m%d%H%M%S` > /neodb/build_version RUN rm -rf /neodb/.git /neodb/neodb-takahe/.git RUN mv /neodb/neodb-takahe /takahe diff --git a/boofilsic/__init__.py b/boofilsic/__init__.py index e69de29b..3e2f46a3 100644 --- a/boofilsic/__init__.py +++ b/boofilsic/__init__.py @@ -0,0 +1 @@ +__version__ = "0.9.0" diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 301a03c9..d22e2285 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -2,13 +2,21 @@ import environ -NEODB_VERSION = "0.8" +from boofilsic import __version__ + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +try: + with open(os.path.join(BASE_DIR, "build_version")) as f: + NEODB_VERSION = __version__ + "-" + f.read().strip() +except: + NEODB_VERSION = __version__ + "-dev" + # Parse configuration from: # - environment variables # - .env file in project root directory # - /etc/neodb.conf -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) environ.Env.read_env("/etc/neodb.conf") environ.Env.read_env(os.path.join(BASE_DIR, ".env")) diff --git a/common/management/commands/cron.py b/common/management/commands/cron.py index 3efb3230..d84f9828 100644 --- a/common/management/commands/cron.py +++ b/common/management/commands/cron.py @@ -4,10 +4,7 @@ from django.core.management.base import BaseCommand from loguru import logger -from catalog.jobs import * # noqa from common.models import BaseJob, JobManager -from mastodon.jobs import * # noqa -from users.jobs import * # noqa # @JobManager.register # class DummyJob(BaseJob): diff --git a/common/models.py b/common/models.py index 61370359..7ee65b4f 100644 --- a/common/models.py +++ b/common/models.py @@ -75,3 +75,13 @@ def run(cls, job_id): def get_scheduled_job_ids(cls): registry = ScheduledJobRegistry(queue=django_rq.get_queue("cron")) return registry.get_job_ids() + + @classmethod + def schedule_all(cls): + # TODO rewrite lazy import in a better way + from catalog.jobs import DiscoverGenerator, PodcastUpdater + from mastodon.jobs import MastodonSiteCheck + from users.jobs import MastodonUserSync + + cls.cancel() + cls.schedule() diff --git a/common/setup.py b/common/setup.py index 7fae31f6..be1d9e07 100644 --- a/common/setup.py +++ b/common/setup.py @@ -2,6 +2,7 @@ from loguru import logger from catalog.search.models import Indexer +from common.models import JobManager from takahe.models import Config as TakaheConfig from takahe.models import Domain as TakaheDomain from takahe.models import Follow as TakaheFollow @@ -151,5 +152,6 @@ def run(self): Indexer.init() # Register cron jobs if not yet + JobManager.schedule_all() logger.info("Finished post-migration setup.") diff --git a/misc/bin/neodb-hello b/misc/bin/neodb-hello index 17931bba..e38acb68 100755 --- a/misc/bin/neodb-hello +++ b/misc/bin/neodb-hello @@ -1,6 +1,6 @@ #!/bin/sh -echo '\033[0;35m====== Welcome to NeoDB ======\033[0m' -cat /neodb/version +echo '\033[0;35m====== NeoDB ======\033[0m' +echo Version: `neodb-version` echo Your configuration is for ${NEODB_SITE_NAME} on ${NEODB_SITE_DOMAIN} [[ -z "${NEODB_DEBUG}" ]] || echo DEBUG is ON, showing environment variables: [[ -z "${NEODB_DEBUG}" ]] || env diff --git a/misc/bin/neodb-init b/misc/bin/neodb-init index 278d6a5e..9873ff7f 100755 --- a/misc/bin/neodb-init +++ b/misc/bin/neodb-init @@ -1,14 +1,11 @@ #!/bin/sh -echo '\033[0;35m====== Welcome to NeoDB ======\033[0m' -cat /neodb/version +echo '\033[0;35m====== NeoDB ======\033[0m' +echo Version: `neodb-version` echo Your configuration is for ${NEODB_SITE_NAME} on ${NEODB_SITE_DOMAIN} -[[ -z "${NEODB_DEBUG}" ]] || echo DEBUG is ON, show environment: -[[ -z "${NEODB_DEBUG}" ]] || env -echo + echo NeoDB initializing... takahe-manage migrate || exit $? neodb-manage migrate || exit $? -neodb-manage cron --schedule || exit $? echo NeoDB initialization complete. diff --git a/misc/bin/neodb-version b/misc/bin/neodb-version new file mode 100755 index 00000000..321d072b --- /dev/null +++ b/misc/bin/neodb-version @@ -0,0 +1,2 @@ +#!/bin/sh +echo "from django.conf import settings; print(settings.NEODB_VERSION+(' debug:on' if settings.DEBUG else ''))" | neodb-manage shell