diff --git a/.github/workflows/stage-compatibility-release.yml b/.github/workflows/stage-compatibility-release.yml index 6701d5bb..06e59d27 100644 --- a/.github/workflows/stage-compatibility-release.yml +++ b/.github/workflows/stage-compatibility-release.yml @@ -63,13 +63,22 @@ jobs: fi test "$(gh api "repos/$GITHUB_REPOSITORY/commits/${{ github.event.repository.default_branch }}" --jq .sha)" = "$SOURCE_SHA" git -c 'credential.helper=!gh auth git-credential' push origin "$branch" - # Only the newest staged leaf can be certified; close older ones. - gh pr list --repo "$GITHUB_REPOSITORY" --state open --json number,headRefName \ - --jq '.[] | select(.headRefName | startswith("automation/release-stage-")) | .number' | - while read -r number; do - gh pr close "$number" --repo "$GITHUB_REPOSITORY" --delete-branch \ - --comment "Superseded by staging run $GITHUB_RUN_ID." - done + # Only the newest staged leaf can be certified; close older ones, + # but never while a certification runs or waits: it may be + # certifying one of them (1.3.26 lost a finished certification + # that way). A later staging run closes them. + active_certifications=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow release-certification.yml \ + --limit 20 --json status --jq '[.[] | select(.status != "completed")] | length') + if [[ "$active_certifications" == 0 ]]; then + gh pr list --repo "$GITHUB_REPOSITORY" --state open --json number,headRefName \ + --jq '.[] | select(.headRefName | startswith("automation/release-stage-")) | .number' | + while read -r number; do + gh pr close "$number" --repo "$GITHUB_REPOSITORY" --delete-branch \ + --comment "Superseded by staging run $GITHUB_RUN_ID." + done + else + echo "A certification is running; older staging PRs stay open." >> "$GITHUB_STEP_SUMMARY" + fi gh pr create --repo "$GITHUB_REPOSITORY" --base '${{ github.event.repository.default_branch }}' --head "$branch" --title "Stage compatibility release $(cat VERSION)" --body 'Version and factual changelog frozen before full native certification. Preserve this leaf with a merge; squash/rebase or concurrent main changes require fresh staging and certification.' echo "Frozen candidate: $(git rev-parse HEAD)" >> "$GITHUB_STEP_SUMMARY" gh workflow run release-certification.yml --ref '${{ github.event.repository.default_branch }}' -f "source_sha=$(git rev-parse HEAD)" -f "upstream_profile_json=$PROFILE_JSON" -f "profile_id=$PROFILE_ID" -f mode=full diff --git a/CHANGELOG.md b/CHANGELOG.md index d36ef0d8..2920a4f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The result-description cache tracks uncommitted DDL per session: it resumes after DDL that ran outside a transaction, and another session's commit or autocommit write (or an inner `RELEASE SAVEPOINT`) no longer ends the window early. - A statement whose stream was read ahead is no longer re-run from the first row when it is stepped from another connection. - Manual image publication only moves `:latest` when it publishes the repository's latest release, checked right before promotion. +- A shadow database without its sidecar file (an interrupted installation) is still refused, since it may have been used as a real library since, but the error now explains that and how to recover. +- Release staging no longer closes older staging pull requests (and deletes their branches) while a certification is running or queued, which had discarded a finished 1.3.26 certification. ## [1.3.26] - 2026-11-06 diff --git a/scripts/migrate_lib.sh b/scripts/migrate_lib.sh index 988085aa..6a671e01 100644 --- a/scripts/migrate_lib.sh +++ b/scripts/migrate_lib.sh @@ -439,12 +439,36 @@ sys.exit(0 if identity == [(expected,)] and expected else 1) PY } +# A database with a shadow marker but no sidecar is most likely left by an +# interrupted shadow installation (the database is moved before its sidecar). +# It is still refused: it may since have been used as a real library. +shadow_recovery_hint() { + [[ -f "$1" && ! -e "${1}.plex-pg-shadow" ]] || return 0 + python3 - "$1" <<'PY' || return 0 +import pathlib +import sqlite3 +import sys + +path = pathlib.Path(sys.argv[1]) +try: + connection = sqlite3.connect(path.resolve().as_uri() + '?mode=ro', uri=True) + rows = connection.execute('SELECT identity FROM plex_pg_shadow_marker').fetchall() + connection.close() +except (OSError, sqlite3.Error): + sys.exit(1) +sys.exit(0 if len(rows) == 1 else 1) +PY + echo " It carries a plex-postgresql shadow marker but no ${1}.plex-pg-shadow file, which usually means a" >&2 + echo " shadow installation was interrupted. If it was not used with plain Plex since, move it aside and start again." >&2 +} + protect_shadow_destinations() { local shadow_dir="$1" db_file protect_sqlite_sources "$shadow_dir" || return 1 for db_file in "$shadow_dir/com.plexapp.plugins.library.db" "$shadow_dir/com.plexapp.plugins.library.blobs.db"; do if [[ -e "$db_file" ]] && ! is_shadow_database "$db_file"; then echo "ERROR: Unmarked SQLite destination $db_file; preserve it as a separate source/backup before startup." >&2 + shadow_recovery_hint "$db_file" return 1 fi done @@ -720,6 +744,7 @@ build_shadow_database() ( protect_sqlite_sources "$(dirname "$db_file")" || return 1 if [[ -e "$db_file" ]] && ! is_shadow_database "$db_file"; then echo "ERROR: Unmarked SQLite destination $db_file; preserve it as a separate backup before rebuilding." >&2 + shadow_recovery_hint "$db_file" return 1 fi temporary=$(mktemp "${db_file}.new.XXXXXX") || return 1 diff --git a/scripts/tests/test_shadow_marker.py b/scripts/tests/test_shadow_marker.py new file mode 100644 index 00000000..f0362b76 --- /dev/null +++ b/scripts/tests/test_shadow_marker.py @@ -0,0 +1,61 @@ +"""Shadow databases need their sidecar; a marker alone only earns a recovery hint.""" +from contextlib import closing +import pathlib +import sqlite3 +import subprocess +import tempfile +import unittest + + +ROOT = pathlib.Path(__file__).resolve().parents[2] + + +def run(function, path): + return subprocess.run( + ['bash', '-c', 'source "$1"; ' + function + ' "$2"', 'shadow-test', + str(ROOT / 'scripts/migrate_lib.sh'), str(path)], + capture_output=True, text=True, timeout=30) + + +class ShadowMarkerTests(unittest.TestCase): + def database(self, root, name, marker=None): + path = root / name + with closing(sqlite3.connect(path)) as connection, connection: + connection.execute('CREATE TABLE metadata_items(id INTEGER PRIMARY KEY)') + if marker is not None: + connection.execute('CREATE TABLE plex_pg_shadow_marker(identity TEXT NOT NULL)') + connection.execute('INSERT INTO plex_pg_shadow_marker VALUES (?)', (marker,)) + return path + + def test_shadow_requires_matching_sidecar(self): + with tempfile.TemporaryDirectory() as directory: + root = pathlib.Path(directory) + matching = self.database(root, 'matching.db', 'identity-1') + pathlib.Path(str(matching) + '.plex-pg-shadow').write_text('identity-1\n') + self.assertEqual(run('is_shadow_database', matching).returncode, 0) + + mismatched = self.database(root, 'mismatched.db', 'identity-1') + pathlib.Path(str(mismatched) + '.plex-pg-shadow').write_text('identity-2\n') + self.assertNotEqual(run('is_shadow_database', mismatched).returncode, 0) + + # A marker without sidecar may since be a real library: refused. + unmarked = self.database(root, 'unmarked.db', 'identity-1') + self.assertNotEqual(run('is_shadow_database', unmarked).returncode, 0) + + def test_recovery_hint_only_for_marker_without_sidecar(self): + with tempfile.TemporaryDirectory() as directory: + root = pathlib.Path(directory) + interrupted = self.database(root, 'interrupted.db', 'identity-1') + self.assertIn('shadow installation was interrupted', + run('shadow_recovery_hint', interrupted).stderr) + + library = self.database(root, 'library.db') + self.assertEqual(run('shadow_recovery_hint', library).stderr, '') + + marked = self.database(root, 'marked.db', 'identity-1') + pathlib.Path(str(marked) + '.plex-pg-shadow').write_text('identity-1\n') + self.assertEqual(run('shadow_recovery_hint', marked).stderr, '') + + +if __name__ == '__main__': + unittest.main()