Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f14f697428 | ||
|
|
4f518e78a5 | ||
|
|
5bb659f76c | ||
|
|
0fe81a0d42 | ||
|
|
c70d561c53 | ||
|
|
cc2d62c22b | ||
|
|
e54d8dd23f | ||
|
|
dc566087fb | ||
|
|
6c15ab4d0f | ||
|
|
58e3c2446a | ||
|
|
1a3217115f | ||
|
|
7daec2caa3 | ||
|
|
4f426637c8 | ||
|
|
c061296022 | ||
|
|
c4e2352cb5 | ||
|
|
cef665be88 |
+58
-2
@@ -1,11 +1,33 @@
|
|||||||
name: "Project Manager"
|
name: "Project Manager"
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
|
# python
|
||||||
python-version:
|
python-version:
|
||||||
default: "3.14"
|
default: "3.14"
|
||||||
setup-python:
|
setup-python:
|
||||||
default: false
|
type: boolean
|
||||||
|
required: false
|
||||||
venv-version:
|
venv-version:
|
||||||
default: "1"
|
default: "1"
|
||||||
|
# nodejs
|
||||||
|
nodejs-version:
|
||||||
|
default: "24.x"
|
||||||
|
setup-nodejs:
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
node_modules-version:
|
||||||
|
default: "1"
|
||||||
|
# haxetool
|
||||||
|
setup-haxetool:
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
haxetool_sdk-version:
|
||||||
|
default: "1"
|
||||||
|
|
||||||
|
env:
|
||||||
|
NPM_CONFIG_AUDIT: false
|
||||||
|
NPM_CONFIG_FUND: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
@@ -20,8 +42,9 @@ runs:
|
|||||||
--index-url https://git.shmyga.ru/api/packages/InfernalGames/pypi/simple/ \
|
--index-url https://git.shmyga.ru/api/packages/InfernalGames/pypi/simple/ \
|
||||||
--extra-index-url https://pypi.org/simple
|
--extra-index-url https://pypi.org/simple
|
||||||
|
|
||||||
- run: pm setup:config -vv
|
- run: pm setup:config -i -vv
|
||||||
|
|
||||||
|
# setup python
|
||||||
- if: inputs.setup-python
|
- if: inputs.setup-python
|
||||||
run: pip install poetry
|
run: pip install poetry
|
||||||
|
|
||||||
@@ -34,3 +57,36 @@ runs:
|
|||||||
|
|
||||||
- if: ${{ inputs.setup-python && steps.cache-venv.outputs.cache-hit != 'true' }}
|
- if: ${{ inputs.setup-python && steps.cache-venv.outputs.cache-hit != 'true' }}
|
||||||
run: pm setup:python -vv
|
run: pm setup:python -vv
|
||||||
|
|
||||||
|
# setup nodejs
|
||||||
|
- if: ${{ inputs.setup-haxetool || inputs.setup-nodejs }}
|
||||||
|
uses: actions/setup-node@v7
|
||||||
|
with:
|
||||||
|
node-version: ${{ inputs.nodejs-version }}
|
||||||
|
cache: "npm"
|
||||||
|
|
||||||
|
- id: cache-node_modules
|
||||||
|
if: ${{ inputs.setup-haxetool || inputs.setup-nodejs }}
|
||||||
|
uses: actions/cache@v6
|
||||||
|
with:
|
||||||
|
path: node_modules
|
||||||
|
key: node_modules-${{ runner.os }}-nodejs-${{ inputs.nodejs-version }}-${{ hashFiles('**/package-lock.json') }}-v${{ inputs.node_modules-version }}
|
||||||
|
|
||||||
|
- if: ${{ (inputs.setup-haxetool || inputs.setup-nodejs) && steps.cache-node_modules.outputs.cache-hit != 'true' }}
|
||||||
|
run: pm setup:nodejs -vv
|
||||||
|
|
||||||
|
# setup haxetool
|
||||||
|
- if: inputs.setup-haxetool
|
||||||
|
uses: actions/cache/restore@v6
|
||||||
|
id: cache-haxetool
|
||||||
|
with:
|
||||||
|
key: ${{ runner.os }}-haxetool-${{ hashFiles('**/haxetool.json') }}-v${{ inputs.haxetool_sdk-version }}
|
||||||
|
path: /root/sdk
|
||||||
|
- if: steps.cache-haxetool.outputs.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
|
npx hxt app:flash:setup
|
||||||
|
- if: steps.cache-haxetool.outputs.cache-hit != 'true'
|
||||||
|
uses: actions/cache/save@v6
|
||||||
|
with:
|
||||||
|
key: ${{ steps.cache-haxetool.outputs.cache-primary-key }}
|
||||||
|
path: /root/sdk
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ class PathTemplate:
|
|||||||
kk: self._env.from_string(vv).render(**variables)
|
kk: self._env.from_string(vv).render(**variables)
|
||||||
for kk, vv in v.items()
|
for kk, vv in v.items()
|
||||||
}
|
}
|
||||||
|
elif isinstance(v, list):
|
||||||
|
variables[k] = [
|
||||||
|
self._env.from_string(vv).render(**variables) for vv in v
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
variables[k] = self._env.from_string(v).render(**variables)
|
variables[k] = self._env.from_string(v).render(**variables)
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class Task(NamedTuple):
|
|||||||
|
|
||||||
|
|
||||||
class Entry:
|
class Entry:
|
||||||
|
DEFAULT_EXECUTOR: type[CommandExecutor] = CommandExecutor
|
||||||
_logger = logger
|
_logger = logger
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -61,16 +62,18 @@ class Entry:
|
|||||||
variables: Variables,
|
variables: Variables,
|
||||||
basepath: Path,
|
basepath: Path,
|
||||||
rootpath: Path,
|
rootpath: Path,
|
||||||
|
executor: type[CommandExecutor] | None = None,
|
||||||
):
|
):
|
||||||
self._tasks = tasks
|
self._tasks = tasks
|
||||||
self._variables = variables
|
self._variables = variables
|
||||||
self._basepath = basepath
|
self._basepath = basepath
|
||||||
self._roopath = rootpath
|
self._roopath = rootpath
|
||||||
|
self._executor = executor or self.DEFAULT_EXECUTOR
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sensentive_data(self):
|
def sensentive_data(self):
|
||||||
for k, v in self._variables.items():
|
for k, v in self._variables.items():
|
||||||
if "pass" in k.lower():
|
if "pass" in k.lower() and v:
|
||||||
yield v
|
yield v
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
@@ -103,7 +106,7 @@ class Entry:
|
|||||||
if key == task.key:
|
if key == task.key:
|
||||||
self._logger.info("🔵 %s %s", task.key, self)
|
self._logger.info("🔵 %s %s", task.key, self)
|
||||||
for command in task.commands:
|
for command in task.commands:
|
||||||
CommandExecutor(command).run(
|
self._executor(command).run(
|
||||||
(task.cwd and Path(task.cwd)) or self._basepath
|
(task.cwd and Path(task.cwd)) or self._basepath
|
||||||
)
|
)
|
||||||
c += 1
|
c += 1
|
||||||
|
|||||||
@@ -7,11 +7,15 @@ 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 = "{{ 'DOCKER_TAG' | env('latest') }}"
|
variables.docker_tag = "{{ 'DOCKER_TAG' | env('latest') }}"
|
||||||
variables.docker_target = "{{ 'DOCKER_TARGET' | env }}"
|
variables.docker_target = "{{ 'DOCKER_TARGET' | env }}"
|
||||||
variables.docker_target_arg = "{{ ('--target ' + docker_target) if docker_target else '' }}"
|
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 {{ docker_target_arg }} -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]
|
||||||
|
|||||||
@@ -1,24 +1,43 @@
|
|||||||
[presets.gitea]
|
[presets.gitea]
|
||||||
variables.publish_repo = "{{ 'PUBLISH_REPO' | env }}"
|
variables.publish_repo = "{{ 'PUBLISH_REPO' | env }}"
|
||||||
variables.publish_repo_path = "{{ publish_repo }}/generic/{{ project_name }}/{{ project_version }}"
|
variables.publish_group = "{{ 'PUBLISH_GROUP' | env }}"
|
||||||
variables.publish_user = "{{ 'PUBLISH_USER' | env }}"
|
|
||||||
variables.publish_password = "{{ 'PUBLISH_PASSWORD' | env }}"
|
variables.publish_password = "{{ 'PUBLISH_PASSWORD' | env }}"
|
||||||
variables.publish_auth = "{{ publish_user }}:{{ publish_password }}"
|
|
||||||
variables.publish_artefacts = {}
|
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 }}"]
|
[presets.gitea.tasks.publish."{{ publish_artefacts | tojson }}"]
|
||||||
conditions = ["{{ item | file }}"]
|
conditions = ["{{ item | file }}"]
|
||||||
variables.artefact_file = "{{ item }}"
|
variables.artefact_file = "{{ item }}"
|
||||||
variables.artefact_name = "{{ (artefact_file | file).name }}"
|
variables.artefact_name = "{{ (artefact_file | file).name }}"
|
||||||
commands = [
|
commands = [
|
||||||
"curl --user \"{{ publish_auth }}\" -X DELETE \"{{ publish_repo_path }}/{{ artefact_name }}\"",
|
"curl -s {{ publish_auth_header }} -X DELETE '{{ publish_generic_url }}/{{ artefact_name }}'",
|
||||||
"curl --user \"{{ publish_auth }}\" --fail --upload-file \"{{ artefact_file }}\" \"{{ publish_repo_path }}/{{ 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]
|
[presets.gitea.tasks.publish.debian_repo]
|
||||||
conditions = ["{{ publish_artefacts.debian | file }}"]
|
conditions = ["{{ publish_artefacts.debian | file }}"]
|
||||||
variables.artefact_file = "{{ publish_artefacts.debian }}"
|
variables.artefact_file = "{{ publish_artefacts.debian }}"
|
||||||
commands = [
|
commands = [
|
||||||
"curl --user \"{{ publish_auth }}\" -X DELETE \"{{ publish_repo }}/debian/pool/noble/main/{{ project_name }}/{{ project_version }}/all\"",
|
"curl -s {{ publish_auth_header }} -X DELETE '{{ publish_packages_url }}/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\"",
|
"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 }}')",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ conditions = ["{{ true }}"]
|
|||||||
variables.project_name = "{{ 'pyproject.toml' | read | get('project.name') or 'package.json' | read | get('name') }}"
|
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.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 '.' }}",
|
||||||
|
]
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
conditions = ["{{ 'package.json' | file }}"]
|
conditions = ["{{ 'package.json' | file }}"]
|
||||||
variables.use_nvm = "{{ (((('home' | env) + '/.nvm/nvm.sh') | file) and ('.nvmrc' | file)) | bool }}"
|
variables.use_nvm = "{{ (((('home' | env) + '/.nvm/nvm.sh') | file) and ('.nvmrc' | file)) | bool }}"
|
||||||
variables.nvm = "{{ '. ~/.nvm/nvm.sh && nvm use && ' if use_nvm | bool else '' }}"
|
variables.nvm = "{{ '. ~/.nvm/nvm.sh && nvm use && ' if use_nvm | bool else '' }}"
|
||||||
|
variables.npm_scripts = "{{ 'package.json' | read | get('scripts') | tojson }}"
|
||||||
|
|
||||||
# install
|
# install
|
||||||
[presets.nodejs.tasks.setup.npm]
|
[presets.nodejs.tasks.setup.npm]
|
||||||
@@ -13,20 +14,9 @@ commands = ["{{ nvm }}npm install-clean"]
|
|||||||
conditions = ["{{ not ('package-lock.json' | file) }}"]
|
conditions = ["{{ not ('package-lock.json' | file) }}"]
|
||||||
commands = ["{{ nvm }}npm install"]
|
commands = ["{{ nvm }}npm install"]
|
||||||
|
|
||||||
# test
|
# scripts
|
||||||
[presets.nodejs.tasks.test.jest]
|
[presets.nodejs.tasks."{{ npm_scripts | tojson }}".npm]
|
||||||
conditions = ["{{ 'node_modules/jest' | file }}"]
|
commands = ["{{ nvm }}npm run {{ task }}"]
|
||||||
commands = ["{{ nvm }}npx jest"]
|
|
||||||
|
|
||||||
# build
|
|
||||||
[presets.nodejs.tasks.build.npm]
|
|
||||||
conditions = ["{{ 'package.json' | read | get('scripts.build') }}"]
|
|
||||||
commands = ["{{ nvm }}npm run build"]
|
|
||||||
|
|
||||||
# publish
|
|
||||||
[presets.nodejs.tasks.publish.npm]
|
|
||||||
conditions = ["{{ 'package.json' | read | get('scripts.publish') }}"]
|
|
||||||
commands = ["{{ nvm }}npm run publish"]
|
|
||||||
|
|
||||||
# clean
|
# clean
|
||||||
[presets.nodejs.tasks.clean.node_modules]
|
[presets.nodejs.tasks.clean.node_modules]
|
||||||
@@ -36,4 +26,6 @@ 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",
|
||||||
|
]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ variables.python_poetry = "{{ 'pyproject.toml' | read | get('build-system.build-
|
|||||||
# setup
|
# setup
|
||||||
[presets.python.tasks.setup.poetry]
|
[presets.python.tasks.setup.poetry]
|
||||||
conditions = ["{{ python_poetry }}"]
|
conditions = ["{{ python_poetry }}"]
|
||||||
variables.python_version = "{{ 'pyproject.toml' | read | get('project.requires-python') | search('(\\d+.\\d+)') }}"
|
variables.python_version = "{{ 'pyproject.toml' | read | get('project.requires-python') | search('(\\\\d+.\\\\d+)') }}"
|
||||||
commands = ["poetry env use {{ python_version }}", "poetry install --all-extras"]
|
commands = ["poetry env use {{ python_version }}", "poetry install --all-extras"]
|
||||||
|
|
||||||
# playwright
|
# playwright
|
||||||
|
|||||||
@@ -15,6 +15,21 @@ 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
|
||||||
|
|
||||||
|
def _expand_section(
|
||||||
|
self,
|
||||||
|
section: str,
|
||||||
|
template: PathTemplate,
|
||||||
|
variables: Variables,
|
||||||
|
) -> dict[str, str | None]:
|
||||||
|
data = template.fill_template(section, variables)
|
||||||
|
try:
|
||||||
|
sections: dict[str, str | None] = json.loads(data)
|
||||||
|
if isinstance(sections, str):
|
||||||
|
sections = json.loads(sections)
|
||||||
|
except ValueError:
|
||||||
|
sections = {data: None}
|
||||||
|
return sections
|
||||||
|
|
||||||
# pylint:disable=too-many-locals,too-many-nested-blocks,too-many-branches
|
# 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)
|
||||||
@@ -46,14 +61,18 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
for task_name, task_pack in preset.tasks.items():
|
for task_name, task_pack in preset.tasks.items():
|
||||||
|
task_names = self._expand_section(task_name, template, preset_variables)
|
||||||
|
for i_task_name, i_task_value in task_names.items():
|
||||||
|
if i_task_value:
|
||||||
|
preset_variables["task"] = i_task_name
|
||||||
|
preset_variables["item"] = i_task_value
|
||||||
for sub_tag, task_preset in task_pack.items():
|
for sub_tag, task_preset in task_pack.items():
|
||||||
sub_tags = template.fill_template(sub_tag, preset_variables)
|
sub_tags = self._expand_section(
|
||||||
try:
|
sub_tag, template, preset_variables
|
||||||
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():
|
for i_sub_tag, i_sub_tag_value in sub_tags.items():
|
||||||
if i_sub_tag_value:
|
if i_sub_tag_value:
|
||||||
|
preset_variables["sub_tag"] = i_sub_tag
|
||||||
preset_variables["item"] = i_sub_tag_value
|
preset_variables["item"] = i_sub_tag_value
|
||||||
if not task_preset.conditions or template.check_conditions(
|
if not task_preset.conditions or template.check_conditions(
|
||||||
task_preset.conditions, preset_variables
|
task_preset.conditions, preset_variables
|
||||||
@@ -64,7 +83,7 @@ class PresetEntryDetector(EntryDetector):
|
|||||||
task_preset.variables, variables
|
task_preset.variables, variables
|
||||||
)
|
)
|
||||||
task = Task(
|
task = Task(
|
||||||
key=TaskKey(task_name, tag, i_sub_tag),
|
key=TaskKey(i_task_name, tag, i_sub_tag),
|
||||||
commands=[
|
commands=[
|
||||||
template.fill_template(command, variables)
|
template.fill_template(command, variables)
|
||||||
for command in task_preset.commands
|
for command in task_preset.commands
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
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
|
||||||
|
|
||||||
from .common.logging_colored import ColoredFormatter
|
from .common.logging_colored import ColoredFormatter
|
||||||
from .entry.entry import PartialTaskKey
|
from .entry.entry import PartialTaskKey
|
||||||
from .manager import ProjectManager
|
from .manager import ProjectManager
|
||||||
from .version import __version__
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectManagerRunner:
|
class ProjectManagerRunner:
|
||||||
@@ -16,10 +16,12 @@ class ProjectManagerRunner:
|
|||||||
*,
|
*,
|
||||||
path: Path,
|
path: Path,
|
||||||
task_key: PartialTaskKey,
|
task_key: PartialTaskKey,
|
||||||
|
ignore: bool = False,
|
||||||
verbose: int = 0,
|
verbose: int = 0,
|
||||||
):
|
):
|
||||||
self._path = path
|
self._path = path
|
||||||
self._task_key = task_key
|
self._task_key = task_key
|
||||||
|
self._ignore = ignore
|
||||||
self._verbose = verbose
|
self._verbose = verbose
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -47,6 +49,8 @@ class ProjectManagerRunner:
|
|||||||
self._setup_logging(self._verbose)
|
self._setup_logging(self._verbose)
|
||||||
manager = ProjectManager(self._path)
|
manager = ProjectManager(self._path)
|
||||||
result = manager.run_task(self._task_key)
|
result = manager.run_task(self._task_key)
|
||||||
|
if not self._ignore and not result:
|
||||||
|
raise RuntimeError(f'Task not found "{self._task_key}"')
|
||||||
if result["failed"] > 0:
|
if result["failed"] > 0:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@@ -59,13 +63,16 @@ class ProjectManagerRunner:
|
|||||||
default="show",
|
default="show",
|
||||||
)
|
)
|
||||||
parser.add_argument("-p", "--path", type=Path, default=Path.cwd())
|
parser.add_argument("-p", "--path", type=Path, default=Path.cwd())
|
||||||
|
parser.add_argument("-i", "--ignore", action="store_true")
|
||||||
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")
|
parser.add_argument("--version", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.version:
|
if args.version:
|
||||||
print(__version__)
|
print(version("project-manager"))
|
||||||
sys.exit(0)
|
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, ignore=args.ignore, verbose=verbose
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import tomllib
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
__version__ = tomllib.loads(
|
|
||||||
(Path(__file__).parent.parent / "pyproject.toml").read_text()
|
|
||||||
)["project"]["version"]
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "project-manager"
|
name = "project-manager"
|
||||||
description = ""
|
description = ""
|
||||||
version = "0.4.1"
|
version = "0.6.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"
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "echo build"
|
"build": "echo build",
|
||||||
|
"test": "echo test",
|
||||||
|
"format": "echo format",
|
||||||
|
"lint": "echo lint"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^29.2.2"
|
"jest": "^29.2.2"
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
[tool.poetry]
|
|
||||||
name = "example"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = ""
|
|
||||||
authors = []
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
|
||||||
python = "^3.8"
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
|
||||||
black = "^23.1.0"
|
|
||||||
pytest = "^7.2.2"
|
|
||||||
isort = "^5.12.0"
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["poetry-core"]
|
|
||||||
build-backend = "poetry.core.masonry.api"
|
|
||||||
+23
-2
@@ -4,6 +4,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from project_manager.common.command import CommandExecutor
|
||||||
from project_manager.entry.detector import EntryDetector
|
from project_manager.entry.detector import EntryDetector
|
||||||
from project_manager.entry.entry import Entry, PartialTaskKey
|
from project_manager.entry.entry import Entry, PartialTaskKey
|
||||||
from project_manager.preset.detector import PresetEntryDetector
|
from project_manager.preset.detector import PresetEntryDetector
|
||||||
@@ -29,6 +30,24 @@ def entry(entry_detector: EntryDetector, entry_path: Path, tmp_path: Path):
|
|||||||
return entry_detector.detect_entry(destination, destination)
|
return entry_detector.detect_entry(destination, destination)
|
||||||
|
|
||||||
|
|
||||||
|
class FakeCommandExecutor(CommandExecutor):
|
||||||
|
def run(self, basepath: Path) -> dict | None:
|
||||||
|
if self._command == "npm install":
|
||||||
|
(basepath / "node_modules").mkdir(exist_ok=True)
|
||||||
|
elif self._command == "poetry install --all-extras":
|
||||||
|
bin_dir = basepath / ".venv/bin"
|
||||||
|
bin_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
(bin_dir / "pytest").write_text("")
|
||||||
|
(bin_dir / "pylint").write_text("")
|
||||||
|
(bin_dir / "isort").write_text("")
|
||||||
|
(bin_dir / "black").write_text("")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module", autouse=True)
|
||||||
|
def entry_command_executor():
|
||||||
|
Entry.DEFAULT_EXECUTOR = FakeCommandExecutor
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("entry_path", [Path(__file__).parent / "python"])
|
@pytest.mark.parametrize("entry_path", [Path(__file__).parent / "python"])
|
||||||
def test_python_entry(entry: Entry | None, entry_detector: EntryDetector):
|
def test_python_entry(entry: Entry | None, entry_detector: EntryDetector):
|
||||||
assert entry is not None
|
assert entry is not None
|
||||||
@@ -44,10 +63,12 @@ def test_python_entry(entry: Entry | None, entry_detector: EntryDetector):
|
|||||||
@pytest.mark.parametrize("entry_path", [Path(__file__).parent / "nodejs"])
|
@pytest.mark.parametrize("entry_path", [Path(__file__).parent / "nodejs"])
|
||||||
def test_nodejs_entry(entry: Entry | None, entry_detector: EntryDetector):
|
def test_nodejs_entry(entry: Entry | None, entry_detector: EntryDetector):
|
||||||
assert entry is not None
|
assert entry is not None
|
||||||
assert {"setup", "build"} == {task.key.name for task in entry._tasks}
|
assert {"setup", "build", "lint", "format", "test"} == {
|
||||||
|
task.key.name for task in entry._tasks
|
||||||
|
}
|
||||||
entry.run_task(PartialTaskKey.from_str("setup"))
|
entry.run_task(PartialTaskKey.from_str("setup"))
|
||||||
entry = entry_detector.detect_entry(entry._basepath, entry._basepath)
|
entry = entry_detector.detect_entry(entry._basepath, entry._basepath)
|
||||||
assert entry is not None
|
assert entry is not None
|
||||||
assert {"setup", "build", "test", "clean"} == {
|
assert {"setup", "build", "lint", "format", "test", "clean"} == {
|
||||||
task.key.name for task in entry._tasks
|
task.key.name for task in entry._tasks
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user