fix: bootstrap apps without version config
This commit is contained in:
1 parent
0848079db3
commit
59e040994b
5 files changed
+63
-9
No files matched your search
+6
-1
@@ -2,6 +2,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
: "${INPUT_CONFIG_FILE:?config-file is required}"
|
||||
: "${INPUT_VERSION_FILE:=}"
|
||||
: "${INPUT_BASE_BRANCH:?base-branch is required}"
|
||||
: "${INPUT_TARGET_BRANCH:?target-branch is required}"
|
||||
: "${INPUT_BUMP:?bump is required}"
|
||||
@@ -45,7 +46,11 @@ 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=$(python3 "${script_dir}/read_version.py" "${INPUT_CONFIG_FILE}" --ref "${base_ref}")
|
||||
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[@]}")
|
||||
|
||||
comparison=$(python3 - "${current_version}" "${base_version}" <<'PY'
|
||||
import re
|
||||
|
||||
+31
-1
@@ -4,7 +4,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
|
||||
|
||||
@@ -12,9 +14,35 @@ def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("config_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:
|
||||
@@ -30,7 +58,9 @@ def main() -> None:
|
||||
|
||||
try:
|
||||
version = tomllib.loads(content.decode())["tool"]["bumpversion"]["current_version"]
|
||||
except (KeyError, TypeError, UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
|
||||
except KeyError as error:
|
||||
version = read_bootstrap_version(args, error)
|
||||
except (TypeError, UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
|
||||
raise SystemExit(
|
||||
f"Could not read tool.bumpversion.current_version from {args.config_file}: {error}"
|
||||
) from error
|
||||
|
||||
Reference in new issue
Block a user