Skip to content

Commit 89e832c

Browse files
check for pre_update.sh
1 parent 036fca4 commit 89e832c

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -xeu
4+
5+
6+
export LC_ALL=C
7+
8+
# Lower bound version
9+
min_version="25.1.30"
10+
11+
# Get the current version of pio
12+
current_version=$(sudo -u pioreactor -i pio version)
13+
14+
# Use sorting to determine if the current version is less than the minimum version
15+
is_valid=$(printf "%s\n%s" "$current_version" "$min_version" | sort -V | head -n1)
16+
17+
# If the smallest version isn't the minimum version, then current version is too low
18+
if [ "$is_valid" != "$min_version" ]; then
19+
sudo -u pioreactor -i pio log -l ERROR -m "Version error: installed version $current_version is lower than the minimum required version $min_version."
20+
exit 1
21+
fi
22+
23+
echo "Version check passed: $current_version"

scripts/create_release.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,41 @@ def ensure_update_scripts_folder(calver: str, dry_run: bool) -> bool:
146146
if target.exists():
147147
return False
148148
if upcoming.exists():
149+
pre_update_path = upcoming / "pre_update.sh"
150+
if not pre_update_path.exists():
151+
raise RuntimeError(f"Missing pre_update.sh in {upcoming}")
149152
print(f"Renaming update scripts: upcoming -> {calver}")
150153
run_git_command(["mv", upcoming.as_posix(), target.as_posix()], dry_run)
151154
return True
152155
print("No upcoming update scripts folder found; skipping rename.")
153156
return False
154157

155158

159+
def ensure_pre_update_script_exists(calver: str, update_scripts_changed: bool, dry_run: bool) -> bool:
160+
target = UPDATE_SCRIPTS_DIR / calver
161+
upcoming = UPDATE_SCRIPTS_DIR / "upcoming"
162+
163+
if target.exists() or update_scripts_changed:
164+
target_dir = target
165+
elif upcoming.exists():
166+
target_dir = upcoming
167+
else:
168+
print("No update scripts directory found to ensure pre_update.sh; skipping.")
169+
return False
170+
171+
pre_update_path = target_dir / "pre_update.sh"
172+
if pre_update_path.exists():
173+
return False
174+
175+
print(f"Creating missing pre_update.sh in {target_dir}")
176+
if dry_run:
177+
print(f"DRY-RUN: would write {pre_update_path}")
178+
return True
179+
180+
pre_update_path.write_text("#!/bin/bash\n\n" "set -euo pipefail\n\n" "# Intentionally left blank.\n")
181+
return True
182+
183+
156184
def stage_if_exists(path: Path, dry_run: bool) -> None:
157185
if dry_run:
158186
print(f"DRY-RUN: $ git add {path.as_posix()}")
@@ -203,18 +231,25 @@ def main(argv: list[str]) -> int:
203231
release_version_changed = ensure_release_version(calver, dry_run=args.dry_run)
204232
changelog_changed = ensure_changelog_top_matches(calver, dry_run=args.dry_run)
205233
update_scripts_changed = ensure_update_scripts_folder(calver, dry_run=args.dry_run)
234+
pre_update_created = ensure_pre_update_script_exists(
235+
calver, update_scripts_changed=update_scripts_changed, dry_run=args.dry_run
236+
)
206237

207238
if release_version_changed:
208239
stage_if_exists(VERSION_FILE, dry_run=args.dry_run)
209240
if changelog_changed:
210241
stage_if_exists(CHANGELOG_FILE, dry_run=args.dry_run)
211-
if update_scripts_changed:
242+
if update_scripts_changed or pre_update_created:
212243
stage_if_exists(UPDATE_SCRIPTS_DIR, dry_run=args.dry_run)
213244
if fe_build_changed:
214245
stage_if_exists(FE_BUILD_DIR, dry_run=args.dry_run)
215246

216247
need_release_commit = args.dry_run and (
217-
release_version_changed or changelog_changed or update_scripts_changed or fe_build_changed
248+
release_version_changed
249+
or changelog_changed
250+
or update_scripts_changed
251+
or pre_update_created
252+
or fe_build_changed
218253
)
219254
if not args.dry_run:
220255
need_release_commit = git_diff_cached_has_changes()

0 commit comments

Comments
 (0)