feat: support config-free ERP app versioning
Update major version tag / update-major-tag (push) Successful in 5s
Test action / integration (push) Successful in 11s

This commit is contained in:
NikoKS committed 2026-08-26 23:45:11 +07:00
1 parent 59e040994b
commit 75fdf8a822
5 files changed
+32 -102

No files matched your search

+12 -13
View File
@@ -1,8 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
: "${INPUT_CONFIG_FILE:?config-file is required}"
: "${INPUT_VERSION_FILE:=}"
: "${INPUT_VERSION_FILE:?version-file is required}"
: "${INPUT_BASE_BRANCH:?base-branch is required}"
: "${INPUT_TARGET_BRANCH:?target-branch is required}"
: "${INPUT_BUMP:?bump is required}"
@@ -24,8 +23,8 @@ case "${INPUT_BUMP}" in
*) echo "bump must be major, minor, or patch" >&2; exit 1 ;;
esac
if [[ ! -f "${INPUT_CONFIG_FILE}" ]]; then
echo "Configuration file not found: ${INPUT_CONFIG_FILE}" >&2
if [[ ! -f "${INPUT_VERSION_FILE}" ]]; then
echo "Version file not found: ${INPUT_VERSION_FILE}" >&2
exit 1
fi
@@ -45,12 +44,8 @@ git fetch "${INPUT_REMOTE}" \
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
base_ref="refs/remotes/${INPUT_REMOTE}/${INPUT_BASE_BRANCH}"
current_version=$(python3 "${script_dir}/read_version.py" "${INPUT_CONFIG_FILE}")
base_version_args=("${INPUT_CONFIG_FILE}" --ref "${base_ref}")
if [[ -n "${INPUT_VERSION_FILE}" ]]; then
base_version_args+=(--fallback-version-file "${INPUT_VERSION_FILE}")
fi
base_version=$(python3 "${script_dir}/read_version.py" "${base_version_args[@]}")
current_version=$(python3 "${script_dir}/read_version.py" "${INPUT_VERSION_FILE}")
base_version=$(python3 "${script_dir}/read_version.py" "${INPUT_VERSION_FILE}" --ref "${base_ref}")
comparison=$(python3 - "${current_version}" "${base_version}" <<'PY'
import re
@@ -96,13 +91,17 @@ git config user.email "${INPUT_GIT_USER_EMAIL}"
message=${INPUT_COMMIT_MESSAGE//\{version\}/\{new_version\}}
"${venv_dir}/bin/bump-my-version" bump \
--config-file "${INPUT_CONFIG_FILE}" \
--current-version "${current_version}" \
--search '__version__ = "{current_version}"' \
--replace '__version__ = "{new_version}"' \
--no-configured-files \
--commit \
--no-tag \
--message "${message}" \
"${INPUT_BUMP}"
"${INPUT_BUMP}" \
"${INPUT_VERSION_FILE}"
new_version=$(python3 "${script_dir}/read_version.py" "${INPUT_CONFIG_FILE}")
new_version=$(python3 "${script_dir}/read_version.py" "${INPUT_VERSION_FILE}")
commit=$(git rev-parse HEAD)
if [[ "${INPUT_PUSH}" == "true" ]]; then
+12 -45
View File
@@ -1,73 +1,40 @@
#!/usr/bin/env python3
"""Read bump-my-version's current_version from a local file or Git ref."""
"""Read a Frappe app's stable __version__ from a local file or Git ref."""
from __future__ import annotations
import argparse
import re
import subprocess
import sys
import tomllib
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("config_file")
parser.add_argument("version_file")
parser.add_argument("--ref")
parser.add_argument("--fallback-version-file")
return parser.parse_args()
def read_bootstrap_version(args: argparse.Namespace, config_error: KeyError) -> str:
if not args.ref or not args.fallback_version_file:
raise SystemExit(
f"Could not read tool.bumpversion.current_version from {args.config_file}: {config_error}"
) from config_error
try:
version_content = subprocess.check_output(
["git", "show", f"{args.ref}:{args.fallback_version_file}"],
text=True,
)
except (OSError, subprocess.CalledProcessError) as error:
raise SystemExit(
f"Could not load bootstrap version file {args.fallback_version_file}: {error}"
) from error
match = re.search(r'^__version__ = "(\d+\.\d+\.\d+)"$', version_content, re.MULTILINE)
if not match:
raise SystemExit(f"Could not read __version__ from bootstrap file {args.fallback_version_file}")
version = match.group(1)
print(f"Using bootstrap version {version} from {args.fallback_version_file}", file=sys.stderr)
return version
def main() -> None:
args = parse_args()
try:
if args.ref:
content = subprocess.check_output(
["git", "show", f"{args.ref}:{args.config_file}"],
["git", "show", f"{args.ref}:{args.version_file}"],
text=True,
)
else:
with open(args.config_file, "rb") as config_file:
content = config_file.read()
with open(args.version_file, encoding="utf-8") as version_file:
content = version_file.read()
except (OSError, subprocess.CalledProcessError) as error:
raise SystemExit(f"Could not load {args.config_file}: {error}") from error
raise SystemExit(f"Could not load {args.version_file}: {error}") from error
try:
version = tomllib.loads(content.decode())["tool"]["bumpversion"]["current_version"]
except KeyError as error:
version = read_bootstrap_version(args, error)
except (TypeError, UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
match = re.search(r'^__version__ = "(\d+\.\d+\.\d+)"$', content, re.MULTILINE)
if not match:
raise SystemExit(
f"Could not read tool.bumpversion.current_version from {args.config_file}: {error}"
) from error
if not isinstance(version, str):
raise SystemExit("tool.bumpversion.current_version must be a string")
print(version)
f"Could not read a stable MAJOR.MINOR.PATCH __version__ from {args.version_file}"
)
print(match.group(1))
if __name__ == "__main__":