feat(preset): add gitea preset
test / test (push) Successful in 2m20s

This commit is contained in:
2026-10-03 16:34:32 +03:00
parent 244f995490
commit b459eef34b
8 changed files with 106 additions and 31 deletions
+13 -1
View File
@@ -1,4 +1,16 @@
[presets.config.tasks.setup.config]
[presets.config.tasks.setup.env]
priority = 1
conditions = ["{{ ('.env-base' | file) and ('.env' | file | not ) }}"]
commands = ["cp .env-base .env"]
[presets.config.tasks.setup.env2]
priority = 1
conditions = ["{{ ('.env.default' | file) and ('.env' | file | not ) }}"]
commands = ["cp .env.default .env"]
[presets.config.tasks.setup.json]
priority = 1
conditions = [
"{{ ('config.example.json' | file) and ('config.json' | file | not ) }}",
]
commands = ["cp config.example.json config.json"]
+8 -6
View File
@@ -1,15 +1,17 @@
[presets.docker]
conditions = ["{{ 'Dockerfile' | file }}"]
variables.docker_name = "{{ 'pyproject.toml' | read | get('project.name') or 'package.json' | read | get('name') }}"
variables.docker_version = "{{ 'pyproject.toml' | read | get('project.version') or 'package.json' | read | get('version') }}"
variables.docker_repo = "{{ '.env' | read | get('DOCKER_REPO') }}"
variables.docker_group = "{{ '.env' | read | get('DOCKER_GROUP') }}"
variables.docker_name = "{{ project_name }}"
variables.docker_version = "{{ project_version }}"
variables.docker_repo = "{{ 'DOCKER_REPO' | env }}"
variables.docker_group = "{{ 'DOCKER_GROUP' | env }}"
variables.docker_image = "{% if docker_group | bool %}{{ docker_group }}/{% endif %}{{ docker_name }}"
variables.docker_tag = "{{ '.env' | read | get('DOCKER_TAG') or 'latest' }}"
variables.docker_tag = "{{ 'DOCKER_TAG' | env('latest') }}"
variables.docker_target = "{{ 'DOCKER_TARGET' | env }}"
variables.docker_target_arg = "{{ ('--target ' + docker_target) if docker_target else '' }}"
# build
[presets.docker.tasks.build.default]
commands = ["docker build -t {{ docker_image }} . -f Dockerfile"]
commands = ["docker build {{ docker_target_arg }} -t {{ docker_image }} . -f Dockerfile"]
# publish version
[presets.docker.tasks.publish.version]
+24
View File
@@ -0,0 +1,24 @@
[presets.gitea]
variables.publish_repo = "{{ 'PUBLISH_REPO' | env }}"
variables.publish_repo_path = "{{ publish_repo }}/generic/{{ project_name }}/{{ project_version }}"
variables.publish_user = "{{ 'PUBLISH_USER' | env }}"
variables.publish_password = "{{ 'PUBLISH_PASSWORD' | env }}"
variables.publish_auth = "{{ publish_user }}:{{ publish_password }}"
variables.publish_artefacts = {}
[presets.gitea.tasks.publish."{{ publish_artefacts | tojson }}"]
conditions = ["{{ item | file }}"]
variables.artefact_file = "{{ item }}"
variables.artefact_name = "{{ (artefact_file | file).name }}"
commands = [
"curl --user \"{{ publish_auth }}\" -X DELETE \"{{ publish_repo_path }}/{{ artefact_name }}\"",
"curl --user \"{{ publish_auth }}\" --fail --upload-file \"{{ artefact_file }}\" \"{{ publish_repo_path }}/{{ artefact_name }}\"",
]
[presets.gitea.tasks.publish.debian_repo]
conditions = ["{{ publish_artefacts.debian | file }}"]
variables.artefact_file = "{{ publish_artefacts.debian }}"
commands = [
"curl --user \"{{ publish_auth }}\" -X DELETE \"{{ publish_repo }}/debian/pool/noble/main/{{ project_name }}/{{ project_version }}/all\"",
"curl --user \"{{ publish_auth }}\" --fail --upload-file \"{{ artefact_file }}\" \"{{ publish_repo }}/debian/pool/noble/main/upload\"",
]
@@ -1,5 +1,7 @@
[presets.'*']
priority = 1000
conditions = ["{{ true }}"]
variables.project_name = "{{ 'pyproject.toml' | read | get('project.name') or 'package.json' | read | get('name') }}"
variables.project_version = "{{ 'pyproject.toml' | read | get('project.version') or 'package.json' | read | get('version') }}"
variables.version = "{{ 'version' | env }}"
tasks = {}
+28 -17
View File
@@ -1,3 +1,4 @@
import json
import operator
from os import environ
from pathlib import Path
@@ -14,7 +15,7 @@ class PresetEntryDetector(EntryDetector):
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
self._preset_loader_config = preset_loader_config
# pylint:disable=too-many-locals
# pylint:disable=too-many-locals,too-many-nested-blocks,too-many-branches
def detect_entry(self, basepath: Path, rootpath: Path) -> Entry:
template = PathTemplate(basepath)
preset = PresetLoader(basepath, self._preset_loader_config).load()
@@ -44,22 +45,32 @@ class PresetEntryDetector(EntryDetector):
continue
for task_name, task_pack in preset.tasks.items():
for sub_tag, task_preset in task_pack.items():
if not task_preset.conditions or template.check_conditions(
task_preset.conditions, preset_variables
):
variables = preset_variables.copy()
if task_preset.variables:
template.update_variables(task_preset.variables, variables)
task = Task(
key=TaskKey(task_name, tag, sub_tag),
commands=[
template.fill_template(command, variables)
for command in task_preset.commands
],
priority=task_preset.priority,
cwd=task_preset.cwd,
)
tasks.append(task)
sub_tags = template.fill_template(sub_tag, preset_variables)
try:
sub_tags = json.loads(sub_tags)
except ValueError:
sub_tags = {sub_tags: None}
for i_sub_tag, i_sub_tag_value in sub_tags.items():
if i_sub_tag_value:
preset_variables["item"] = i_sub_tag_value
if not task_preset.conditions or template.check_conditions(
task_preset.conditions, preset_variables
):
variables = preset_variables.copy()
if task_preset.variables:
template.update_variables(
task_preset.variables, variables
)
task = Task(
key=TaskKey(task_name, tag, i_sub_tag),
commands=[
template.fill_template(command, variables)
for command in task_preset.commands
],
priority=task_preset.priority,
cwd=task_preset.cwd,
)
tasks.append(task)
if tasks:
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
return Entry(tasks, basepath, rootpath)
+3 -1
View File
@@ -1,6 +1,8 @@
from typing import Any
from pydantic import BaseModel
Variables = dict[str, str]
Variables = dict[str, Any]
class TaskPreset(BaseModel):