Skip to content

Commit

Permalink
template update
Browse files Browse the repository at this point in the history
  • Loading branch information
sbilge committed Aug 21, 2024
1 parent aba0a65 commit d363114
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/vscode/devcontainers/python:3.9-bullseye
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm

ENV PYTHONUNBUFFERED 1

Expand All @@ -8,7 +8,7 @@ ARG USER_GID=$USER_UID
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then groupmod --gid $USER_GID vscode && usermod --uid $USER_UID --gid $USER_GID vscode; fi

# [Option] Install Node.js
ARG INSTALL_NODE="true"
ARG INSTALL_NODE="false"
ARG NODE_VERSION="lts/*"
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/license_header.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
for the German Human Genome-Phenome Archive (GHGA)

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/check_template_files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ on: push

jobs:
check-template-files:
name: Check template files

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
- name: Checkout repository
id: checkout
uses: actions/checkout@v4

- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.12'

- name: Check template files
id: check-template-files
run: |
if [ "${{ github.event.repository.name }}" == "microservice-repository-template" ]
then
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache/
prof/

# Translations
Expand Down Expand Up @@ -132,6 +133,12 @@ dmypy.json
# ignore VS Code settings:
.vscode/

# key stores
*.key
*.rnd
.keystore
.ssl/

# desktop settings and thumbnails
.DS_Store
desktop.ini
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
for the German Human Genome-Phenome Archive (GHGA)

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion scripts/script_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
9 changes: 8 additions & 1 deletion scripts/script_utils/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -26,6 +26,13 @@ def echo_success(message: str):
typer.echo(styled_message)


def echo_warning(message: str):
"""Print a warning message."""

styled_message = typer.style(text=message, fg=typer.colors.YELLOW)
typer.echo(styled_message)


def echo_failure(message: str):
"""Print a failure message."""

Expand Down
42 changes: 33 additions & 9 deletions scripts/update_all.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,33 +19,57 @@
"""Run all update scripts that are present in the repository in the correct order"""

try:
from scripts.update_template_files import main as update_template
from update_template_files import main as update_template
except ImportError:
pass
print("update_template_files script not found")
else:
print("Pulling in updates from template repository")
update_template()

try:
from scripts.update_config_docs import main as update_config
from update_pyproject import main as update_pyproject
except ImportError:
pass
print("update_pyproject script not found")
else:
print("Updating pyproject.toml file")
update_pyproject()

try:
from update_lock import main as update_lock
except ImportError:
print("update_lock script not found")
else:
print("Upgrading the lock file")
update_lock(upgrade=True)

try:
from update_hook_revs import main as update_hook_revs
except ImportError:
print("update_hook_revs script not found")
else:
print("Updating config docs")
update_hook_revs()

try:
from update_config_docs import main as update_config
except ImportError:
print("update_config_docs script not found")
else:
print("Updating config docs")
update_config()

try:
from scripts.update_openapi_docs import main as update_openapi
from update_openapi_docs import main as update_openapi
except ImportError:
pass
print("update_openapi_docs script not found")
else:
print("Updating OpenAPI docs")
update_openapi()

try:
from scripts.update_readme import main as update_readme
from update_readme import main as update_readme
except ImportError:
pass
print("update_readme script not found")
else:
print("Updating README")
update_readme()
40 changes: 26 additions & 14 deletions scripts/update_template_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -40,12 +40,20 @@ def run(main_fn):
main_fn(check="--check" in sys.argv[1:])


REPO_ROOT_DIR = Path(__file__).parent.parent.resolve()
REPO_ROOT_DIR = Path(__file__).parent.parent.absolute()

FILE_LIST_DIR_NAME = ".template"
DEPRECATED_FILES = "deprecated_files"
MANDATORY_FILES = "mandatory_files"
STATIC_FILES = "static_files"

DEPRECATED_FILES = ".deprecated_files"
MANDATORY_FILES = ".mandatory_files"
STATIC_FILES = ".static_files"
IGNORE_SUFFIX = "_ignore"

TEMPLATE_LIST_REL_PATHS = [
f"{FILE_LIST_DIR_NAME}/{list_name}.txt"
for list_name in [STATIC_FILES, MANDATORY_FILES, DEPRECATED_FILES]
]

RAW_TEMPLATE_URL = (
"https://raw.githubusercontent.com/ghga-de/microservice-repository-template/main/"
)
Expand All @@ -55,10 +63,15 @@ class ValidationError(RuntimeError):
"""Raised when files need to be updated."""


def get_file_list_path(list_name: str, relative: bool = False) -> Path:
"""Get the path to the file list of the given name."""
return Path(REPO_ROOT_DIR / FILE_LIST_DIR_NAME / f"{list_name}.txt")


def get_file_list(list_name: str) -> list[str]:
"""Return a list of all file names specified in a given list file."""
list_path = REPO_ROOT_DIR / list_name
with open(list_path, "r", encoding="utf8") as list_file:
list_path = get_file_list_path(list_name)
with open(list_path, encoding="utf8") as list_file:
file_list = [
clean_line
for clean_line in (
Expand Down Expand Up @@ -127,7 +140,7 @@ def check_file(relative_file_path: str, diff: bool = False) -> bool:
print(f" - {local_file_path}: cannot check, remote is missing")
return True

with open(local_file_path, "r", encoding="utf8") as file:
with open(local_file_path, encoding="utf8") as file:
return diff_content(local_file_path, file.read(), template_file_content)

return False
Expand All @@ -153,7 +166,7 @@ def update_file(relative_file_path: str, diff: bool = False) -> bool:
return True

if diff and local_file_path.exists():
with open(local_file_path, "r", encoding="utf8") as file:
with open(local_file_path, encoding="utf8") as file:
if file.read() == template_file_content:
return False

Expand Down Expand Up @@ -212,14 +225,13 @@ def remove_files(files: list[str], check: bool = False) -> bool:
def main(check: bool = False):
"""Update the static files in the service template."""
updated = False
if not check:
update_files([STATIC_FILES], diff=True, check=False)

print("Template lists...")
if update_files(TEMPLATE_LIST_REL_PATHS, diff=True, check=False):
updated = True

print("Static files...")
files_to_update = get_file_list(STATIC_FILES)
if check:
files_to_update.append(STATIC_FILES)
files_to_update.extend((MANDATORY_FILES, DEPRECATED_FILES))
if update_files(files_to_update, diff=True, check=check):
updated = True

Expand Down

0 comments on commit d363114

Please sign in to comment.