Skip to content

Commit d0a7464

Browse files
committed
Move enforcement to ghe-host-check
This ensures all the individual scripts also detect the version step down if run individually.
1 parent 6a1c352 commit d0a7464

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

bin/ghe-host-check

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ if [ -z "$version" ]; then
9191
exit 2
9292
fi
9393

94+
# Block restoring snapshots to older releases of GitHub Enterprise
95+
if [ -n "$GHE_RESTORE_SNAPSHOT_PATH" ]; then
96+
snapshot_version=$(cat $GHE_RESTORE_SNAPSHOT_PATH/version)
97+
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
98+
read -r snapshot_version_major snapshot_version_minor _ <<<$(ghe_parse_version $snapshot_version)
99+
if [ "$(version $GHE_REMOTE_VERSION)" -lt "$(version $snapshot_version_major.$snapshot_version_minor.0)" ]; then
100+
echo "Error: Snapshot can not be restored to an older release of GitHub Enterprise." >&2
101+
exit 1
102+
fi
103+
fi
104+
94105
if [ -z "$GHE_ALLOW_REPLICA_BACKUP" ]; then
95106
if [ "$(ghe-ssh $host -- cat $GHE_REMOTE_ROOT_DIR/etc/github/repl-state 2>/dev/null || true)" = "replica" ]; then
96107
echo "Error: high availability replica detected." 1>&2

bin/ghe-restore

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ GHE_BACKUP_STRATEGY=$(cat "$GHE_RESTORE_SNAPSHOT_PATH/strategy")
106106
# Perform a host-check and establish the remote version in GHE_REMOTE_VERSION.
107107
ghe_remote_version_required "$GHE_HOSTNAME"
108108

109-
# Block restoring snapshots to older releases of GitHub Enterprise
110-
snapshot_version=$(cat $GHE_RESTORE_SNAPSHOT_PATH/version)
111-
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
112-
read -r snapshot_version_major snapshot_version_minor _ <<<$(ghe_parse_version $snapshot_version)
113-
if [ "$(version $GHE_REMOTE_VERSION)" -lt "$(version $snapshot_version_major.$snapshot_version_minor.0)" ]; then
114-
echo "Error: Snapshot can not be restored to an older release of GitHub Enterprise." >&2
115-
exit 1
116-
fi
117-
118109
# Figure out if this instance has been configured or is entirely new.
119110
instance_configured=false
120111
if ghe-ssh "$GHE_HOSTNAME" -- "[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/configured' ]"; then

test/test-ghe-host-check.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,16 @@ begin_test "ghe-host-check detects high availability replica"
7878
GHE_ALLOW_REPLICA_BACKUP=yes ghe-host-check
7979
)
8080
end_test
81+
82+
begin_test "ghe-host-check blocks restore to old release"
83+
(
84+
set -e
85+
86+
mkdir -p "$GHE_DATA_DIR/current/"
87+
echo "$GHE_TEST_REMOTE_VERSION" > "$GHE_DATA_DIR/current/version"
88+
89+
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
90+
read -r bu_version_major bu_version_minor bu_version_patch <<<$(ghe_parse_version $GHE_TEST_REMOTE_VERSION)
91+
! GHE_TEST_REMOTE_VERSION=$bu_version_major.$((bu_version_minor-1)).$bu_version_patch ghe-restore -v
92+
)
93+
end_test

test/test-ghe-restore.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,6 @@ begin_test "ghe-restore exits early on unsupported version"
398398
)
399399
end_test
400400

401-
begin_test "ghe-restore exits early when restoring to older release"
402-
(
403-
set -e
404-
GHE_RESTORE_HOST=127.0.0.1
405-
export GHE_RESTORE_HOST
406-
407-
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
408-
read -r bu_version_major bu_version_minor bu_version_patch <<<$(ghe_parse_version $GHE_TEST_REMOTE_VERSION)
409-
! GHE_TEST_REMOTE_VERSION=$bu_version_major.$((bu_version_minor-1)).$bu_version_patch ghe-restore -v
410-
)
411-
end_test
412-
413401
# Reset data for sub-subsequent tests
414402
rm -rf "$GHE_DATA_DIR/1"
415403
setup_test_data "$GHE_DATA_DIR/1"

0 commit comments

Comments
 (0)