Compare commits
16
Commits
75adb282e7
...
0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c15ab4d0f | ||
|
|
58e3c2446a | ||
|
|
1a3217115f | ||
|
|
7daec2caa3 | ||
|
|
4f426637c8 | ||
|
|
c061296022 | ||
|
|
c4e2352cb5 | ||
|
|
cef665be88 | ||
|
|
e4328deaac | ||
|
|
3aef3b22bf | ||
|
|
79bc6ad519 | ||
|
|
db30814b54 | ||
|
|
a42e1cd1a7 | ||
|
|
549979ced6 | ||
|
|
b459eef34b | ||
|
|
244f995490 |
@@ -0,0 +1,20 @@
|
|||||||
|
name: release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["*"]
|
||||||
|
|
||||||
|
env:
|
||||||
|
POETRY_HTTP_BASIC_INFERNALGAMES_USERNAME: ${{ vars.PUBLISH_USERNAME }}
|
||||||
|
POETRY_HTTP_BASIC_INFERNALGAMES_PASSWORD: ${{ secrets.PUBLISH_TOKEN }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- uses: https://git.shmyga.ru/InfernalGames/project-manager@master
|
||||||
|
with:
|
||||||
|
setup-python: true
|
||||||
|
- run: pm build -vv
|
||||||
|
- run: pm publish -vv
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- uses: https://git.shmyga.ru/InfernalGames/project-manager@master
|
||||||
|
with:
|
||||||
|
setup-python: true
|
||||||
|
- run: pm lint -vv
|
||||||
|
- run: pm test -vv
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# Project Manager
|
# Project Manager
|
||||||
|
|
||||||
|
[](https://git.shmyga.ru/InfernalGames/project-manager/actions?workflow=test.yaml)
|
||||||
|
|
||||||
Automatically detects modules and executes commands
|
Automatically detects modules and executes commands
|
||||||
|
|
||||||
Supported types:
|
Supported types:
|
||||||
@@ -10,10 +12,18 @@ Supported types:
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
With pipx
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pipx install project-manager -i https://git.shmyga.ru/api/packages/InfernalGames/pypi/simple/ --pip-args="--extra-index-url https://pypi.org/simple"
|
pipx install project-manager -i https://git.shmyga.ru/api/packages/InfernalGames/pypi/simple/ --pip-args="--extra-index-url https://pypi.org/simple"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
With pip
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install project-manager --index-url https://git.shmyga.ru/api/packages/InfernalGames/pypi/simple/ --extra-index-url https://pypi.org/simple
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Show tasks list
|
### Show tasks list
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
name: "Project Manager"
|
||||||
|
inputs:
|
||||||
|
python-version:
|
||||||
|
default: "3.14"
|
||||||
|
setup-python:
|
||||||
|
default: false
|
||||||
|
venv-version:
|
||||||
|
default: "1"
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- id: setup-python
|
||||||
|
uses: actions/setup-python@v7
|
||||||
|
with:
|
||||||
|
python-version: ${{ inputs.python-version }}
|
||||||
|
cache: "pip"
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
pip install --upgrade project-manager \
|
||||||
|
--index-url https://git.shmyga.ru/api/packages/InfernalGames/pypi/simple/ \
|
||||||
|
--extra-index-url https://pypi.org/simple
|
||||||
|
|
||||||
|
- run: pm setup:config -vv
|
||||||
|
|
||||||
|
- if: inputs.setup-python
|
||||||
|
run: pip install poetry
|
||||||
|
|
||||||
|
- id: cache-venv
|
||||||
|
if: inputs.setup-python
|
||||||
|
uses: actions/cache@v6
|
||||||
|
with:
|
||||||
|
path: .venv
|
||||||
|
key: venv-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-v${{ inputs.venv-version }}
|
||||||
|
|
||||||
|
- if: ${{ inputs.setup-python && steps.cache-venv.outputs.cache-hit != 'true' }}
|
||||||
|
run: pm setup:python -vv
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -43,13 +44,14 @@ class CommandExecutor:
|
|||||||
def __init__(self, command: str):
|
def __init__(self, command: str):
|
||||||
self._command = command
|
self._command = command
|
||||||
|
|
||||||
def run(self, basepath: Path):
|
def run(self, basepath: Path) -> dict | None:
|
||||||
self._logger.debug(self._command)
|
self._logger.debug(self._command)
|
||||||
out_logger = CommandLogger(logging.TRACE)
|
out_logger = CommandLogger(logging.TRACE)
|
||||||
err_logger = CommandLogger(logging.TRACE)
|
err_logger = CommandLogger(logging.TRACE)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
self._command,
|
self._command,
|
||||||
|
executable="bash",
|
||||||
cwd=basepath,
|
cwd=basepath,
|
||||||
stdout=out_logger, # type: ignore
|
stdout=out_logger, # type: ignore
|
||||||
stderr=err_logger, # type: ignore
|
stderr=err_logger, # type: ignore
|
||||||
@@ -58,5 +60,13 @@ class CommandExecutor:
|
|||||||
finally:
|
finally:
|
||||||
out_logger.close()
|
out_logger.close()
|
||||||
err_logger.close()
|
err_logger.close()
|
||||||
|
out_logger.join()
|
||||||
|
err_logger.join()
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise CommandError("".join(err_logger.lines or out_logger.lines))
|
raise CommandError("".join(err_logger.lines or out_logger.lines))
|
||||||
|
if out_logger.lines:
|
||||||
|
try:
|
||||||
|
return json.loads(out_logger.lines[0])
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ addLoggingLevel("TRACE", logging.DEBUG - 5)
|
|||||||
|
|
||||||
|
|
||||||
class ColoredFormatter(logging.Formatter):
|
class ColoredFormatter(logging.Formatter):
|
||||||
|
sensetive = set() # TODO: chain formatters?
|
||||||
|
|
||||||
def __init__(self, fmt):
|
def __init__(self, fmt):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.fmt = fmt
|
self.fmt = fmt
|
||||||
@@ -72,7 +74,12 @@ class ColoredFormatter(logging.Formatter):
|
|||||||
logging.CRITICAL: colored(self.fmt, "red", attrs=["bold"]),
|
logging.CRITICAL: colored(self.fmt, "red", attrs=["bold"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _mask_sensetive_data(self, message: str) -> str:
|
||||||
|
for value in self.sensetive:
|
||||||
|
message = message.replace(value, "*****")
|
||||||
|
return message
|
||||||
|
|
||||||
def format(self, record: logging.LogRecord):
|
def format(self, record: logging.LogRecord):
|
||||||
log_fmt = self.FORMATS.get(record.levelno)
|
log_fmt = self.FORMATS.get(record.levelno)
|
||||||
formatter = logging.Formatter(log_fmt)
|
formatter = logging.Formatter(log_fmt)
|
||||||
return formatter.format(record)
|
return self._mask_sensetive_data(formatter.format(record))
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import tomllib
|
import tomllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -9,6 +8,7 @@ import dotenv
|
|||||||
from jinja2 import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
from ..preset.model import Variables
|
from ..preset.model import Variables
|
||||||
|
from .util import get_environ
|
||||||
|
|
||||||
|
|
||||||
def do_bool(data: str | None) -> bool:
|
def do_bool(data: str | None) -> bool:
|
||||||
@@ -19,10 +19,6 @@ def do_bool(data: str | None) -> bool:
|
|||||||
return data.lower() not in ["false", "null", "none", "0", ""]
|
return data.lower() not in ["false", "null", "none", "0", ""]
|
||||||
|
|
||||||
|
|
||||||
def do_env(key: str, default: str | None = None) -> str | None:
|
|
||||||
return os.environ.get(key=key.upper(), default=default)
|
|
||||||
|
|
||||||
|
|
||||||
def do_not(value: Any | None) -> bool:
|
def do_not(value: Any | None) -> bool:
|
||||||
return not do_bool(str(value))
|
return not do_bool(str(value))
|
||||||
|
|
||||||
@@ -31,6 +27,8 @@ def _build_env(basepath: Path) -> Environment:
|
|||||||
env = Environment()
|
env = Environment()
|
||||||
|
|
||||||
def do_file(filename: str) -> Path | None:
|
def do_file(filename: str) -> Path | None:
|
||||||
|
if not filename:
|
||||||
|
return None
|
||||||
result = Path(filename)
|
result = Path(filename)
|
||||||
if not result.is_absolute():
|
if not result.is_absolute():
|
||||||
result = basepath / result
|
result = basepath / result
|
||||||
@@ -73,6 +71,11 @@ def _build_env(basepath: Path) -> Environment:
|
|||||||
keys = list(data.keys())
|
keys = list(data.keys())
|
||||||
return keys[keyindex]
|
return keys[keyindex]
|
||||||
|
|
||||||
|
env_data = get_environ(basepath)
|
||||||
|
|
||||||
|
def do_env(key: str, default: str | None = None) -> str | None:
|
||||||
|
return env_data.get(key.upper(), default)
|
||||||
|
|
||||||
env.filters["file"] = do_file
|
env.filters["file"] = do_file
|
||||||
env.filters["read"] = do_read
|
env.filters["read"] = do_read
|
||||||
env.filters["get"] = do_get
|
env.filters["get"] = do_get
|
||||||
@@ -91,7 +94,17 @@ class PathTemplate:
|
|||||||
|
|
||||||
def update_variables(self, templates: Variables, variables: Variables):
|
def update_variables(self, templates: Variables, variables: Variables):
|
||||||
for k, v in templates.items():
|
for k, v in templates.items():
|
||||||
variables[k] = self._env.from_string(v).render(**variables)
|
if isinstance(v, dict):
|
||||||
|
variables[k] = {
|
||||||
|
kk: self._env.from_string(vv).render(**variables)
|
||||||
|
for kk, vv in v.items()
|
||||||
|
}
|
||||||
|
elif isinstance(v, list):
|
||||||
|
variables[k] = [
|
||||||
|
self._env.from_string(vv).render(**variables) for vv in v
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
variables[k] = self._env.from_string(v).render(**variables)
|
||||||
|
|
||||||
def fill_template(self, template: str, variables: Variables) -> str:
|
def fill_template(self, template: str, variables: Variables) -> str:
|
||||||
return self._env.from_string(template).render(**variables)
|
return self._env.from_string(template).render(**variables)
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import dotenv
|
||||||
|
|
||||||
|
|
||||||
def merge_dicts(target: dict, enhancer: dict) -> dict:
|
def merge_dicts(target: dict, enhancer: dict) -> dict:
|
||||||
for key, val in enhancer.items():
|
for key, val in enhancer.items():
|
||||||
if key not in target:
|
if key not in target:
|
||||||
@@ -9,3 +15,10 @@ def merge_dicts(target: dict, enhancer: dict) -> dict:
|
|||||||
else:
|
else:
|
||||||
target[key] = val
|
target[key] = val
|
||||||
return target
|
return target
|
||||||
|
|
||||||
|
|
||||||
|
def get_environ(path: Path) -> dict[str, str]:
|
||||||
|
result = os.environ.copy()
|
||||||
|
if (env_file := path / ".env").exists():
|
||||||
|
result.update(dotenv.dotenv_values(env_file))
|
||||||
|
return result
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from .entry import Entry
|
|||||||
|
|
||||||
class EmptyEntry(Entry):
|
class EmptyEntry(Entry):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__([], Path(), Path())
|
super().__init__([], {}, Path(), Path())
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from pathlib import Path
|
|||||||
from typing import NamedTuple, Self
|
from typing import NamedTuple, Self
|
||||||
|
|
||||||
from ..common.command import CommandExecutor
|
from ..common.command import CommandExecutor
|
||||||
|
from ..preset.model import Variables
|
||||||
|
|
||||||
logger = logging.getLogger("entry")
|
logger = logging.getLogger("entry")
|
||||||
|
|
||||||
@@ -57,13 +58,21 @@ class Entry:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
tasks: list[Task],
|
tasks: list[Task],
|
||||||
|
variables: Variables,
|
||||||
basepath: Path,
|
basepath: Path,
|
||||||
rootpath: Path,
|
rootpath: Path,
|
||||||
):
|
):
|
||||||
self._tasks = tasks
|
self._tasks = tasks
|
||||||
|
self._variables = variables
|
||||||
self._basepath = basepath
|
self._basepath = basepath
|
||||||
self._roopath = rootpath
|
self._roopath = rootpath
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sensentive_data(self):
|
||||||
|
for k, v in self._variables.items():
|
||||||
|
if "pass" in k.lower() and v:
|
||||||
|
yield v
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
self._logger.info("🔵 %s", self)
|
self._logger.info("🔵 %s", self)
|
||||||
level = logging.root.level
|
level = logging.root.level
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from typing import Iterable
|
|||||||
|
|
||||||
from .common.command import CommandError
|
from .common.command import CommandError
|
||||||
from .common.ignore import create_ignore
|
from .common.ignore import create_ignore
|
||||||
|
from .common.logging_colored import ColoredFormatter
|
||||||
from .entry.entry import Entry, PartialTaskKey
|
from .entry.entry import Entry, PartialTaskKey
|
||||||
from .entry.resolver import EntryResolver
|
from .entry.resolver import EntryResolver
|
||||||
from .preset.detector import PresetEntryDetector
|
from .preset.detector import PresetEntryDetector
|
||||||
@@ -38,7 +39,10 @@ class ProjectManager:
|
|||||||
|
|
||||||
def run_task(self, key: PartialTaskKey) -> dict[str, int]:
|
def run_task(self, key: PartialTaskKey) -> dict[str, int]:
|
||||||
counter = Counter()
|
counter = Counter()
|
||||||
|
sensetive = set()
|
||||||
|
ColoredFormatter.sensetive = sensetive
|
||||||
for entry in self._iter_entries():
|
for entry in self._iter_entries():
|
||||||
|
sensetive.update(set(entry.sensentive_data))
|
||||||
try:
|
try:
|
||||||
if count := entry.run_task(key):
|
if count := entry.run_task(key):
|
||||||
counter[ResultType.SUCCESS] += count
|
counter[ResultType.SUCCESS] += count
|
||||||
@@ -51,4 +55,5 @@ class ProjectManager:
|
|||||||
self._logger.info(
|
self._logger.info(
|
||||||
"%s", "\n".join(f"{RESULT_ICONS[k]} {v}" for k, v in counter.items())
|
"%s", "\n".join(f"{RESULT_ICONS[k]} {v}" for k, v in counter.items())
|
||||||
)
|
)
|
||||||
|
ColoredFormatter.sensetive = set()
|
||||||
return counter
|
return counter
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
[presets.config.tasks.setup.config]
|
[presets.config.tasks.setup.env]
|
||||||
priority = 1
|
priority = 1
|
||||||
conditions = ["{{ ('.env-base' | file) and ('.env' | file | not ) }}"]
|
conditions = ["{{ ('.env-base' | file) and ('.env' | file | not ) }}"]
|
||||||
commands = ["cp .env-base .env"]
|
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"]
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
[presets.docker]
|
[presets.docker]
|
||||||
conditions = ["{{ 'Dockerfile' | file }}"]
|
conditions = ["{{ 'Dockerfile' | file }}"]
|
||||||
variables.docker_name = "{{ 'pyproject.toml' | read | get('project.name') or 'package.json' | read | get('name') }}"
|
variables.docker_name = "{{ project_name }}"
|
||||||
variables.docker_version = "{{ 'pyproject.toml' | read | get('project.version') or 'package.json' | read | get('version') }}"
|
variables.docker_version = "{{ project_version }}"
|
||||||
variables.docker_repo = "{{ '.env' | read | get('DOCKER_REPO') }}"
|
variables.docker_repo = "{{ 'DOCKER_REPO' | env }}"
|
||||||
variables.docker_group = "{{ '.env' | read | get('DOCKER_GROUP') }}"
|
variables.docker_group = "{{ 'DOCKER_GROUP' | env }}"
|
||||||
variables.docker_image = "{% if docker_group | bool %}{{ docker_group }}/{% endif %}{{ docker_name }}"
|
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_str = "{{ ('--target ' + docker_target) if docker_target | bool else '' }}"
|
||||||
|
variables.docker_build_args = {}
|
||||||
|
variables.docker_build_args_str = "{% for item in docker_build_args.items() %}--build-arg \"{{ item[0] }}={{ item[1] }}\" {% endfor %}"
|
||||||
|
|
||||||
# build
|
# build
|
||||||
[presets.docker.tasks.build.default]
|
[presets.docker.tasks.build.default]
|
||||||
commands = ["docker build -t {{ docker_image }} . -f Dockerfile"]
|
commands = [
|
||||||
|
"docker build {{ docker_build_args_str }} {{ docker_target_str }} -t {{ docker_image }} . -f Dockerfile",
|
||||||
|
]
|
||||||
|
|
||||||
# publish version
|
# publish version
|
||||||
[presets.docker.tasks.publish.version]
|
[presets.docker.tasks.publish.version]
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
[presets.gitea]
|
||||||
|
variables.publish_repo = "{{ 'PUBLISH_REPO' | env }}"
|
||||||
|
variables.publish_group = "{{ 'PUBLISH_GROUP' | env }}"
|
||||||
|
variables.publish_password = "{{ 'PUBLISH_PASSWORD' | env }}"
|
||||||
|
variables.publish_artefacts = {}
|
||||||
|
|
||||||
|
variables.publish_auth_header = "-H 'Authorization: token {{ publish_password }}'"
|
||||||
|
variables.publish_api_url = "https://{{ publish_repo }}/api"
|
||||||
|
variables.publish_packages_url = "{{ publish_api_url }}/packages/{{ publish_group }}"
|
||||||
|
variables.publish_generic_url = "{{ publish_packages_url }}/generic/{{ project_name }}/{{ project_version }}"
|
||||||
|
variables.publish_releases_url = "{{ publish_api_url }}/v1/repos/{{ publish_group }}/{{ project_name }}/releases"
|
||||||
|
variables.publish_release_tag_url = "{{ publish_releases_url }}/tags/{{ project_version }}"
|
||||||
|
|
||||||
|
[presets.gitea.tasks.publish."{{ publish_artefacts | tojson }}"]
|
||||||
|
conditions = ["{{ item | file }}"]
|
||||||
|
variables.artefact_file = "{{ item }}"
|
||||||
|
variables.artefact_name = "{{ (artefact_file | file).name }}"
|
||||||
|
commands = [
|
||||||
|
"curl -s {{ publish_auth_header }} -X DELETE '{{ publish_generic_url }}/{{ artefact_name }}'",
|
||||||
|
"curl -s {{ publish_auth_header }} --fail-with-body --upload-file '{{ artefact_file }}' '{{ publish_generic_url }}/{{ artefact_name }}'",
|
||||||
|
]
|
||||||
|
|
||||||
|
[presets.gitea.tasks.publish.debian_repo]
|
||||||
|
conditions = ["{{ publish_artefacts.debian | file }}"]
|
||||||
|
variables.artefact_file = "{{ publish_artefacts.debian }}"
|
||||||
|
commands = [
|
||||||
|
"curl -s {{ publish_auth_header }} -X DELETE '{{ publish_packages_url }}/debian/pool/noble/main/{{ project_name }}/{{ project_version }}/all'",
|
||||||
|
"curl -s {{ publish_auth_header }} --fail-with-body --upload-file '{{ artefact_file }}' '{{ publish_packages_url }}/debian/pool/noble/main/upload'",
|
||||||
|
]
|
||||||
|
|
||||||
|
[presets.gitea.tasks.release.create]
|
||||||
|
conditions = ["{{ publish_repo }}"]
|
||||||
|
commands = [
|
||||||
|
"curl -s {{ publish_auth_header }} -X DELETE '{{ publish_release_tag_url }}'",
|
||||||
|
"curl -s {{ publish_auth_header }} --fail-with-body -X POST '{{ publish_releases_url }}' -H 'Content-Type: application/json' --data '{ \"name\": \"{{ project_version }}\", \"tag_name\": \"{{ project_version }}\" }'",
|
||||||
|
]
|
||||||
|
|
||||||
|
[presets.gitea.tasks.release."{{ publish_artefacts | tojson }}"]
|
||||||
|
conditions = ["{{ item | file }}"]
|
||||||
|
variables.artefact_file = "{{ item }}"
|
||||||
|
commands = [
|
||||||
|
"(export RELEASE_ID=$(curl -s {{ publish_auth_header }} --fail {{ publish_release_tag_url }} | jq '.id') && curl -s {{ publish_auth_header }} --fail-with-body -X POST \"{{ publish_releases_url }}/$RELEASE_ID/assets\" -H 'Content-Type: multipart/form-data' -F 'attachment=@{{ artefact_file }}')",
|
||||||
|
]
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
[presets.'*']
|
[presets.'*']
|
||||||
priority = 1000
|
priority = 1000
|
||||||
conditions = ["{{ true }}"]
|
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 }}"
|
variables.version = "{{ 'version' | env }}"
|
||||||
|
variables.home = "{{ 'home' | env }}"
|
||||||
tasks = {}
|
tasks = {}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
[presets.haxe]
|
||||||
|
variables.haxe_version_default = "{{ 'package.json' | read | get('haxe') }}"
|
||||||
|
variables.haxe_version = "{{ 'HAXE_VERSION' | env(haxe_version_default) }}"
|
||||||
|
variables.neko_version_default = "{{ 'package.json' | read | get('neko') or '2.2.0' }}"
|
||||||
|
variables.neko_version = "{{ 'NEKO_VERSION' | env(neko_version_default) }}"
|
||||||
|
variables.neko_sdk = "{{ 'NEKO_SDK' | env(home + '/sdk/neko/' + neko_version) }}"
|
||||||
|
variables.haxe_sdk = "{{ 'HAXE_SDK' | env(home + '/sdk/haxe/' + haxe_version) }}"
|
||||||
|
variables.haxe_activate = ". {{ neko_sdk }}/activate && . {{ haxe_sdk }}/activate &&"
|
||||||
|
variables.haxe_sources = []
|
||||||
|
variables.haxe_sources_str = "{% for item in haxe_sources %}-s \"{{ item }}\" {% endfor %}"
|
||||||
|
variables.haxe_formatter = "{{ ((haxe_sdk + '/lib/formatter') | file) and ('./hxformat.json' | file) }}"
|
||||||
|
conditions = ["{{ haxe_sdk | file }}"]
|
||||||
|
|
||||||
|
[presets.haxe.tasks.lint.formatter]
|
||||||
|
conditions = ["{{ haxe_formatter }}"]
|
||||||
|
commands = [
|
||||||
|
"{{ haxe_activate }} haxelib run formatter --check {{ haxe_sources_str or '.' }}",
|
||||||
|
]
|
||||||
|
|
||||||
|
[presets.haxe.tasks.format.formatter]
|
||||||
|
conditions = ["{{ haxe_formatter }}"]
|
||||||
|
commands = [
|
||||||
|
"{{ haxe_activate }} haxelib run formatter {{ haxe_sources_str or '.' }}",
|
||||||
|
]
|
||||||
@@ -36,4 +36,4 @@ commands = ["rm -rf node_modules"]
|
|||||||
# version
|
# version
|
||||||
[presets.nodejs.tasks.version.npm]
|
[presets.nodejs.tasks.version.npm]
|
||||||
conditions = ["{{ version }}"]
|
conditions = ["{{ version }}"]
|
||||||
commands = ["{{ nvm }}npm version {{ version }} --allow-same-version"]
|
commands = ["{{ nvm }}npm version {{ version }} --allow-same-version --commit-hooks false --git-tag-version false"]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import operator
|
import operator
|
||||||
from os import environ
|
from os import environ
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -14,7 +15,7 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
|
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
|
||||||
self._preset_loader_config = preset_loader_config
|
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:
|
def detect_entry(self, basepath: Path, rootpath: Path) -> Entry:
|
||||||
template = PathTemplate(basepath)
|
template = PathTemplate(basepath)
|
||||||
preset = PresetLoader(basepath, self._preset_loader_config).load()
|
preset = PresetLoader(basepath, self._preset_loader_config).load()
|
||||||
@@ -26,6 +27,7 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
return ENTRY_SKIP
|
return ENTRY_SKIP
|
||||||
tasks = []
|
tasks = []
|
||||||
global_variables = {f"env_{k.lower()}": v for k, v in environ.items()}
|
global_variables = {f"env_{k.lower()}": v for k, v in environ.items()}
|
||||||
|
entry_variables = {}
|
||||||
presets = sorted(
|
presets = sorted(
|
||||||
preset.presets.items(), key=lambda item: item[1].priority, reverse=True
|
preset.presets.items(), key=lambda item: item[1].priority, reverse=True
|
||||||
)
|
)
|
||||||
@@ -38,29 +40,40 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
if tag == "*":
|
if tag == "*":
|
||||||
template.update_variables(preset.variables, global_variables)
|
template.update_variables(preset.variables, global_variables)
|
||||||
template.update_variables(preset.variables, preset_variables)
|
template.update_variables(preset.variables, preset_variables)
|
||||||
|
entry_variables.update(preset_variables)
|
||||||
if preset.conditions and not template.check_conditions(
|
if preset.conditions and not template.check_conditions(
|
||||||
preset.conditions, preset_variables
|
preset.conditions, preset_variables
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
for task_name, task_pack in preset.tasks.items():
|
for task_name, task_pack in preset.tasks.items():
|
||||||
for sub_tag, task_preset in task_pack.items():
|
for sub_tag, task_preset in task_pack.items():
|
||||||
if not task_preset.conditions or template.check_conditions(
|
sub_tags = template.fill_template(sub_tag, preset_variables)
|
||||||
task_preset.conditions, preset_variables
|
try:
|
||||||
):
|
sub_tags = json.loads(sub_tags)
|
||||||
variables = preset_variables.copy()
|
except ValueError:
|
||||||
if task_preset.variables:
|
sub_tags = {sub_tags: None}
|
||||||
template.update_variables(task_preset.variables, variables)
|
for i_sub_tag, i_sub_tag_value in sub_tags.items():
|
||||||
task = Task(
|
if i_sub_tag_value:
|
||||||
key=TaskKey(task_name, tag, sub_tag),
|
preset_variables["item"] = i_sub_tag_value
|
||||||
commands=[
|
if not task_preset.conditions or template.check_conditions(
|
||||||
template.fill_template(command, variables)
|
task_preset.conditions, preset_variables
|
||||||
for command in task_preset.commands
|
):
|
||||||
],
|
variables = preset_variables.copy()
|
||||||
priority=task_preset.priority,
|
if task_preset.variables:
|
||||||
cwd=task_preset.cwd,
|
template.update_variables(
|
||||||
)
|
task_preset.variables, variables
|
||||||
tasks.append(task)
|
)
|
||||||
|
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:
|
if tasks:
|
||||||
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
|
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
|
||||||
return Entry(tasks, basepath, rootpath)
|
return Entry(tasks, entry_variables, basepath, rootpath)
|
||||||
return ENTRY_NONE
|
return ENTRY_NONE
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
Variables = dict[str, str]
|
Variables = dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
class TaskPreset(BaseModel):
|
class TaskPreset(BaseModel):
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from importlib.metadata import version
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
@@ -60,7 +61,11 @@ class ProjectManagerRunner:
|
|||||||
parser.add_argument("-p", "--path", type=Path, default=Path.cwd())
|
parser.add_argument("-p", "--path", type=Path, default=Path.cwd())
|
||||||
parser.add_argument("-v", "--verbose", action="count", default=1)
|
parser.add_argument("-v", "--verbose", action="count", default=1)
|
||||||
parser.add_argument("-q", "--quiet", action="store_true")
|
parser.add_argument("-q", "--quiet", action="store_true")
|
||||||
|
parser.add_argument("--version", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if args.version:
|
||||||
|
print(version("project-manager"))
|
||||||
|
sys.exit(0)
|
||||||
verbose = -1 if args.quiet else args.verbose
|
verbose = -1 if args.quiet else args.verbose
|
||||||
task_key = PartialTaskKey.from_str(args.task)
|
task_key = PartialTaskKey.from_str(args.task)
|
||||||
return cls(path=args.path, task_key=task_key, verbose=verbose)
|
return cls(path=args.path, task_key=task_key, verbose=verbose)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "project-manager"
|
name = "project-manager"
|
||||||
description = ""
|
description = ""
|
||||||
version = "0.3.1"
|
version = "0.5.1"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [{ name = "shmyga", email = "shmyga.z@gmail.com" }]
|
authors = [{ name = "shmyga", email = "shmyga.z@gmail.com" }]
|
||||||
requires-python = ">=3.14,<4.0"
|
requires-python = ">=3.14,<4.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user