From 7cb73dec5754f01af81de54e6349c6b165e4e151 Mon Sep 17 00:00:00 2001 From: Zurdi Date: Tue, 12 Dec 2023 13:33:41 +0100 Subject: [PATCH 01/34] default theme in first setup fixed --- frontend/src/plugins/vuetify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/plugins/vuetify.js b/frontend/src/plugins/vuetify.js index 46ef4b2ca..d8ecdf8b4 100644 --- a/frontend/src/plugins/vuetify.js +++ b/frontend/src/plugins/vuetify.js @@ -9,7 +9,7 @@ const mediaMatch = window.matchMedia("(prefers-color-scheme: dark)"); function getTheme() { const storedTheme = parseInt(localStorage.getItem("settings.theme")); - if (storedTheme !== null && storedTheme !== autoThemeKey) { + if (!isNaN(storedTheme) && storedTheme !== autoThemeKey) { return themes[storedTheme]; } From 43816783a7966193c2320e8390382326beb8b026 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Tue, 12 Dec 2023 08:26:18 -0800 Subject: [PATCH 02/34] Hotfix subtag parsing --- backend/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/utils/__init__.py b/backend/utils/__init__.py index 5d4224562..57824a406 100644 --- a/backend/utils/__init__.py +++ b/backend/utils/__init__.py @@ -68,7 +68,7 @@ def parse_tags(file_name: str) -> tuple: langs = [] other_tags = [] tags = [tag[0] or tag[1] for tag in re.findall(TAG_REGEX, file_name)] - tags = np.array([tag.split(",") for tag in tags]).flatten() + tags = [tag for subtags in tags for tag in subtags.split(",")] tags = [tag.strip() for tag in tags] for tag in tags: From 808279b2cd2d52f5d4dbfa7046c741092d73527e Mon Sep 17 00:00:00 2001 From: Zurdi Date: Wed, 13 Dec 2023 10:43:00 +0100 Subject: [PATCH 03/34] get branch_name and version from backend --- .github/workflows/build.yml | 11 +++++++- .github/workflows/pytest.yml | 7 +++++ .vscode/tasks.json | 2 +- DEVELOPER-SETUP.md | 8 +++--- backend/__version__.py | 1 + backend/endpoints/tests/test_heartbeat.py | 2 ++ backend/main.py | 2 ++ backend/utils/__init__.py | 16 +++++++++++- backend/utils/fs.py | 26 +++++++++++-------- backend/utils/tests/test_fs.py | 4 +-- frontend/src/App.vue | 5 +++- .../General/TaskStatus/TaskStatusCard.vue | 16 ++++-------- frontend/src/stores/heartbeat.js | 11 ++++++++ .../src/views/Settings/ControlPanel/Base.vue | 5 ++-- 14 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 backend/__version__.py create mode 100644 frontend/src/stores/heartbeat.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b579bdb3..6202df9d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: version: - description: 'romm version' + description: "romm version" required: true type: string @@ -18,23 +18,32 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + - name: Set environment variables run: echo "GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + + - name: Set version + run: sed -i 's//'"${{ inputs.version }}"'/' backend/__version__.py + - name: Set up QEMU uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Generate Docker metadata id: meta uses: docker/metadata-action@v4 diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 564c6fcb7..5de39529c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -37,23 +37,29 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + - name: Install mariadb connectors run: | sudo apt-get update sudo apt-get install -y libmariadb3 libmariadb-dev + - name: Install poetry run: pipx install poetry + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: python-version: '3.10' cache: 'poetry' + - name: Install dependencies run: | poetry install --sync + - name: Initiate database run: | mysql --host 127.0.0.1 --port ${{ job.services.mariadb.ports['3306'] }} -uroot -ppasswd -e "GRANT ALL PRIVILEGES ON romm_test.* TO 'romm_test'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" + - name: Run python tests env: DB_HOST: 127.0.0.1 @@ -61,6 +67,7 @@ jobs: run: | cd backend poetry run pytest -vv --maxfail=10 --junitxml=pytest-report.xml . + - name: Publish test results uses: EnricoMi/publish-unit-test-result-action/composite@v2 if: always() diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c34e897ce..12f077917 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -38,7 +38,7 @@ }, { "type": "shell", - "command": "export $(cat .env | xargs); docker exec -i mariadb mariadb -u root -p$DB_ROOT_PASSWD < backend/romm_test/setup.sql", + "command": "export $(cat .env | xargs); docker exec -i mariadb mysql -u root -p$DB_ROOT_PASSWD < backend/romm_test/setup.sql", "label": "Setup development environment migrations [docker] (2)", "problemMatcher": [] }, diff --git a/DEVELOPER-SETUP.md b/DEVELOPER-SETUP.md index 63998a543..25ef3e5a9 100644 --- a/DEVELOPER-SETUP.md +++ b/DEVELOPER-SETUP.md @@ -31,9 +31,8 @@ Then initialize the virtual environment and install the dependencies poetry shell # Fix disable parallel installation stuck: $> poetry config experimental.new-installer false # Fix Loading macOS/linux stuck: $> export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring -# Fix mariadb install on linux: $> sudo apt install libmariadb3 libmariadb-dev -# Fix mariadb connector/c >= 3.3.1: https://mariadb.com/docs/skysql-previous-release/connect/programming-languages/c/install/#Installation_via_Package_Repository_(Linux) -poetry install +# Fix mariadb install on linux https://mariadb.com/docs/skysql-previous-release/connect/programming-languages/c/install/#Installation_via_Package_Repository_(Linux): $> sudo apt install libmariadb3 libmariadb-dev +poetry install --no-root ``` ### - Spin up mariadb in docker @@ -87,8 +86,7 @@ npm run dev ### - Create the test user and database with root user ```sh -docker exec -i mariadb mysql -u root -p < backend/romm_test/setup.sql # for amd images -docker exec -i mariadb mariadb -u root -p < backend/romm_test/setup.sql # for arm images +docker exec -i mariadb mysql -u root -p < backend/romm_test/setup.sql ``` ### - Run tests diff --git a/backend/__version__.py b/backend/__version__.py new file mode 100644 index 000000000..cc4a13849 --- /dev/null +++ b/backend/__version__.py @@ -0,0 +1 @@ +__version__ = '' diff --git a/backend/endpoints/tests/test_heartbeat.py b/backend/endpoints/tests/test_heartbeat.py index 500bcc517..77944604c 100644 --- a/backend/endpoints/tests/test_heartbeat.py +++ b/backend/endpoints/tests/test_heartbeat.py @@ -1,6 +1,7 @@ from fastapi.testclient import TestClient from main import app +from utils import get_version client = TestClient(app) @@ -9,6 +10,7 @@ def test_heartbeat(): response = client.get("/heartbeat") assert response.status_code == 200 assert response.json() == { + "VERSION" : get_version(), "ROMM_AUTH_ENABLED": True, "WATCHER": { "ENABLED": True, diff --git a/backend/main.py b/backend/main.py index e535d6da1..0de4b7d4b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -30,6 +30,7 @@ from utils.auth import ( CustomCSRFMiddleware, create_default_admin_user, ) +from utils import get_version app = FastAPI(title="RomM API", version="0.1.0") @@ -78,6 +79,7 @@ app.mount("/ws", socket_app) @app.get("/heartbeat") def heartbeat(): return { + "VERSION": get_version(), "ROMM_AUTH_ENABLED": ROMM_AUTH_ENABLED, "WATCHER": { "ENABLED": ENABLE_RESCAN_ON_FILESYSTEM_CHANGE, diff --git a/backend/utils/__init__.py b/backend/utils/__init__.py index 57824a406..ad4f0c3bc 100644 --- a/backend/utils/__init__.py +++ b/backend/utils/__init__.py @@ -1,5 +1,6 @@ import re -import numpy as np +import subprocess as sp +from __version__ import __version__ LANGUAGES = [ ("Ar", "Arabic"), @@ -119,3 +120,16 @@ def get_file_extension(rom: dict) -> str: if not rom["multi"] else "" ) + + +def get_version() -> str | None: + """Returns current version or branch name.""" + if not __version__ == "": + return __version__ + else: + try: + output = str(sp.check_output(["git", "branch"], universal_newlines=True)) + except sp.CalledProcessError: + return None + branch = [a for a in output.split("\n") if a.find("*") >= 0][0] + return branch[branch.find("*") + 2 :] diff --git a/backend/utils/fs.py b/backend/utils/fs.py index 4abf37636..c3c81ad9e 100644 --- a/backend/utils/fs.py +++ b/backend/utils/fs.py @@ -19,7 +19,7 @@ from config import ( DEFAULT_URL_COVER_S, DEFAULT_PATH_COVER_S, DEFAULT_WIDTH_COVER_S, - DEFAULT_HEIGHT_COVER_S + DEFAULT_HEIGHT_COVER_S, ) from config.config_loader import config from exceptions.fs_exceptions import ( @@ -30,12 +30,10 @@ from exceptions.fs_exceptions import ( ) - - # ========= Resources utils ========= class CoverSize(Enum): - SMALL = 'small' - BIG = 'big' + SMALL = "small" + BIG = "big" def _cover_exists(fs_slug: str, rom_name: str, size: CoverSize): @@ -49,13 +47,15 @@ def _cover_exists(fs_slug: str, rom_name: str, size: CoverSize): True if cover exists in filesystem else False """ return bool( - os.path.exists(f"{RESOURCES_BASE_PATH}/{fs_slug}/{rom_name}/cover/{size.value}.png") + os.path.exists( + f"{RESOURCES_BASE_PATH}/{fs_slug}/{rom_name}/cover/{size.value}.png" + ) ) def _resize_cover(cover_path: str, size: CoverSize) -> None: """Resizes the cover image to the standard size - + Args: cover_path: path where the original cover were stored size: size of the cover @@ -64,12 +64,12 @@ def _resize_cover(cover_path: str, size: CoverSize) -> None: if cover.size[1] > DEFAULT_HEIGHT_COVER_L: if size == CoverSize.BIG: big_dimensions = (DEFAULT_WIDTH_COVER_L, DEFAULT_HEIGHT_COVER_L) - background = Image.new('RGBA', big_dimensions, (0, 0, 0, 0)) + background = Image.new("RGBA", big_dimensions, (0, 0, 0, 0)) cover.thumbnail(big_dimensions) offset = (int(round(((DEFAULT_WIDTH_COVER_L - cover.size[0]) / 2), 0)), 0) elif size == CoverSize.SMALL: small_dimensions = (DEFAULT_WIDTH_COVER_S, DEFAULT_HEIGHT_COVER_S) - background = Image.new('RGBA', small_dimensions, (0, 0, 0, 0)) + background = Image.new("RGBA", small_dimensions, (0, 0, 0, 0)) cover.thumbnail(small_dimensions) offset = (int(round(((DEFAULT_WIDTH_COVER_S - cover.size[0]) / 2), 0)), 0) else: @@ -116,7 +116,9 @@ def get_cover( ) -> dict: q_rom_name = quote(rom_name) # Cover small - if (overwrite or not _cover_exists(fs_slug, rom_name, CoverSize.SMALL)) and url_cover: + if ( + overwrite or not _cover_exists(fs_slug, rom_name, CoverSize.SMALL) + ) and url_cover: _store_cover(fs_slug, rom_name, url_cover, CoverSize.SMALL) path_cover_s = ( _get_cover_path(fs_slug, q_rom_name, CoverSize.SMALL) @@ -293,7 +295,9 @@ def get_roms(fs_slug: str): ] -def get_rom_file_size(roms_path: str, file_name: str, multi: bool, multi_files: list = []): +def get_rom_file_size( + roms_path: str, file_name: str, multi: bool, multi_files: list = [] +): files = ( [f"{LIBRARY_BASE_PATH}/{roms_path}/{file_name}"] if not multi diff --git a/backend/utils/tests/test_fs.py b/backend/utils/tests/test_fs.py index c3122abb4..59402dd8a 100644 --- a/backend/utils/tests/test_fs.py +++ b/backend/utils/tests/test_fs.py @@ -31,8 +31,8 @@ def test_get_cover(): rom_name="Paper Mario", ) - assert DEFAULT_PATH_COVER_S in cover["path_cover_s"] - assert DEFAULT_PATH_COVER_L in cover["path_cover_l"] + assert "n64/Paper%20Mario/cover/small.png" in cover["path_cover_s"] + assert "n64/Paper%20Mario/cover/big.png" in cover["path_cover_l"] # Game: Paper Mario (USA).z64 cover = get_cover( diff --git a/frontend/src/App.vue b/frontend/src/App.vue index fc05eeca0..bb3e7a871 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -4,14 +4,17 @@ import cookie from "js-cookie"; import storeAuth from "@/stores/auth"; import Notification from "@/components/Notification.vue"; import { api } from "@/services/api"; +import storeHeartbeat from "@/stores/heartbeat"; // Props const auth = storeAuth(); +const heartbeat = storeHeartbeat(); onBeforeMount(async () => { - // Set CSRF token for all requests const { data } = await api.get("/heartbeat"); + heartbeat.set(data) auth.setEnabled(data.ROMM_AUTH_ENABLED ?? false); + // Set CSRF token for all requests api.defaults.headers.common["x-csrftoken"] = cookie.get("csrftoken"); }); diff --git a/frontend/src/components/Settings/General/TaskStatus/TaskStatusCard.vue b/frontend/src/components/Settings/General/TaskStatus/TaskStatusCard.vue index 48b477a90..567b3f5c8 100644 --- a/frontend/src/components/Settings/General/TaskStatus/TaskStatusCard.vue +++ b/frontend/src/components/Settings/General/TaskStatus/TaskStatusCard.vue @@ -3,11 +3,11 @@ import { ref, onBeforeMount, inject } from "vue"; import { api } from "@/services/api"; import TaskWatcher from "@/components/Settings/General/TaskStatus/TaskWatcher.vue"; import TaskScheduler from "@/components/Settings/General/TaskStatus/TaskScheduler.vue"; +import storeHeartbeat from "@/stores/heartbeat"; // Props -const watcher = ref({}); -const scheduler = ref({}); const emitter = inject("emitter"); +const heartbeat = storeHeartbeat(); // Methods const runAllTasks = async () => { @@ -26,12 +26,6 @@ const runAllTasks = async () => { color: "green", }); }; - -onBeforeMount(async () => { - const { data } = await api.get("/heartbeat"); - watcher.value = data.WATCHER; - scheduler.value = data.SCHEDULER; -}); + +