Skip to content

Commit 16a4f35

Browse files
committed
Add --update-template-files flag to auto-update scaffolding without a TTY
Without -it, docker run never attaches stdin, so the existing ask-and-deny fallback for outdated build.sh/view.sh can never actually apply an update - it'll always just warn. Add an explicit 'always' mode that applies content and executable-bit fixes without prompting, alongside 'ask' (default) and 'never'. Not wired into the GitHub Action layers: CI never needs anything but the 'ask' default, which already degrades safely (warns, leaves the file untouched) when stdin is closed.
1 parent dc6dbd9 commit 16a4f35

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

ogc/bblocks/entrypoint.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
help='Skip interactive permission prompts for transforms and plugins (set to true in CI)',
6868
)
6969

70+
parser.add_argument(
71+
'--update-template-files',
72+
default='ask',
73+
choices=('ask', 'always', 'never'),
74+
help="Whether to update outdated scaffolding files (build.sh, view.sh, ...) inherited "
75+
"from bblocks-template: 'ask' to prompt (falls back to leaving them untouched if "
76+
"stdin isn't interactive), 'always' to update without asking, or 'never' to skip "
77+
"the check entirely (set to 'never' in CI)",
78+
)
79+
7080
parser.add_argument(
7181
'--annotated-path',
7282
default='build-local/annotated',
@@ -311,7 +321,7 @@
311321
logger.warning("Could not autodetect base_url / github_base_url: %s", e)
312322

313323
if git_repo_path:
314-
check_template_files(git_repo_path)
324+
check_template_files(git_repo_path, mode=args.update_template_files)
315325

316326
steps = args.steps.split(',') if args.steps else None
317327

ogc/bblocks/template_sync.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@ def _make_executable(path: Path) -> None:
2121
path.chmod(path.stat().st_mode | 0o755)
2222

2323

24-
def check_template_files(git_repo_path: Path) -> None:
25-
"""Offer to update scaffolding files (build.sh, view.sh, ...) that are
26-
outdated copies of their bblock-template counterparts.
24+
def check_template_files(git_repo_path: Path, mode: str = 'ask') -> None:
25+
"""Update scaffolding files (build.sh, view.sh, ...) that are outdated
26+
copies of their bblocks-template counterparts.
2727
2828
A file is only treated as a candidate for updating if it has never been
2929
modified since it was added to the repo's git history - if it has, we
3030
assume it was intentionally customized and leave it alone.
31+
32+
mode:
33+
'ask' - prompt before updating (default); if stdin isn't
34+
interactive, warn and leave the file as-is
35+
'always' - update without prompting
36+
'never' - skip the check entirely
3137
"""
38+
if mode == 'never':
39+
return
40+
3241
template_dir = os.environ.get(_TEMPLATE_DIR_ENV)
3342
if not template_dir:
3443
return
@@ -71,6 +80,12 @@ def check_template_files(git_repo_path: Path) -> None:
7180
continue
7281

7382
if target.read_bytes() != template.read_bytes():
83+
if mode == 'always':
84+
target.write_bytes(template.read_bytes())
85+
_make_executable(target)
86+
logger.info("Updated %s to the latest bblocks-template version.", filename)
87+
continue
88+
7489
print()
7590
print("╔══ Outdated template file detected")
7691
print(f"║ {filename} differs from the latest version in bblocks-template,")
@@ -91,6 +106,11 @@ def check_template_files(git_repo_path: Path) -> None:
91106
continue
92107

93108
if not _is_executable(target):
109+
if mode == 'always':
110+
_make_executable(target)
111+
logger.info("Made %s executable.", filename)
112+
continue
113+
94114
print()
95115
print("╔══ Template file is not executable")
96116
print(f"║ {filename} is missing the executable bit.")

0 commit comments

Comments
 (0)