-
Notifications
You must be signed in to change notification settings - Fork 9
Add CI check that the previous release works against the new schema #3506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jonathangreen
wants to merge
8
commits into
main
Choose a base branch
from
chore/migration-backcompat-ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c810676
Add CI check that the previous release works against the new schema
jonathangreen 4512a47
Remove the external-schema test seam check from the backwards-compati…
jonathangreen 2a2ed4a
Update .github/workflows/build.yml
jonathangreen f881c28
Run the backwards-compatibility check in parallel
jonathangreen b0c0e6d
Skip migration and backwards-compatibility tests on tag builds
jonathangreen 4277fb3
Warn instead of silently skipping when the previous release can't be …
jonathangreen c110371
Tighten the previous-release resolution comment
jonathangreen 2970454
Fix README description of the backwards-compatibility check's DB mode
jonathangreen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script checks that the PREVIOUS released version of the application still works | ||
| # against the database schema produced by the CURRENT code. It exercises our online | ||
| # migration requirement: a release's database must keep working with version N-1 of the | ||
| # code, because during a deploy the new migrations run while the previous version's | ||
| # webservers are still serving traffic. | ||
| # | ||
| # It works by: | ||
| # (1) Finding the previous release (the latest GitHub release) and its published | ||
| # circ-webapp image. | ||
| # (2) Initializing a fresh database with the CURRENT image, which builds the new schema. | ||
| # (3) Running the previous release's database tests (pytest -m db) against that schema in | ||
| # external-schema mode (PALACE_TEST_DATABASE_EXTERNAL_SCHEMA), so the older code | ||
| # exercises the new schema. If those tests fail, the migration is not backwards | ||
| # compatible. | ||
| # | ||
| # The current image is provided via the WEBAPP_IMAGE environment variable (as in the other | ||
| # docker CI jobs). The previous release image can be overridden via PREV_RELEASE_IMAGE | ||
| # (useful for running this script locally). | ||
|
|
||
| set -uo pipefail | ||
|
|
||
| COMPOSE_FILES=(-f docker-compose.yml -f docker/ci/test_backwards_compatibility.yml) | ||
|
|
||
| # Run a docker compose command for this check. | ||
| compose_cmd() { | ||
| docker compose "${COMPOSE_FILES[@]}" --progress quiet "$@" | ||
| } | ||
|
|
||
| # Run a command in a container with the palace virtualenv activated. | ||
| run_in_container() { | ||
| local container="$1" | ||
| shift | ||
| compose_cmd run --rm --no-deps "${container}" /bin/bash -c "source env/bin/activate && $*" | ||
| } | ||
|
|
||
| cleanup() { | ||
| compose_cmd down --remove-orphans >/dev/null 2>&1 | ||
| } | ||
|
|
||
| fail() { | ||
| echo "::error::$1" | ||
| exit "${2:-1}" | ||
| } | ||
|
|
||
| # (1) Resolve the previous release image. | ||
| if [[ -z "${PREV_RELEASE_IMAGE:-}" ]]; then | ||
| # In CI gh infers the repo from $GITHUB_REPOSITORY; locally it infers it from the git | ||
| # remote of the current directory. | ||
| gh_release_args=(release view --json tagName --jq '.tagName') | ||
| if [[ -n "${GITHUB_REPOSITORY:-}" ]]; then | ||
| gh_release_args+=(--repo "${GITHUB_REPOSITORY}") | ||
| fi | ||
|
|
||
| # Resolve the previous release's tag. We deliberately do NOT fail the job when this lookup | ||
| # fails: `gh release view` exits non-zero both when there is genuinely no prior release (a | ||
| # legitimate skip) and on transient errors (auth hiccup, rate limit, network blip). But we | ||
| # don't fail *open silently*, we let gh's error flow to the job log and check its exit status, and on | ||
| # any failure we emit a GitHub Actions ::warning:: before skipping. That makes the gate no-op | ||
| # visible at the PR/checks level instead of quietly passing. | ||
| prev_tag="$(gh "${gh_release_args[@]}")" | ||
| gh_status=$? | ||
| if [[ ${gh_status} -ne 0 || -z "${prev_tag}" ]]; then | ||
| echo "::warning::Backwards-compatibility check skipped: could not resolve the previous release (gh exit ${gh_status}). The gate did NOT run for this build -- see gh's error above. A transient gh/auth/network failure or a genuine absence of releases both land here." | ||
| exit 0 | ||
| fi | ||
|
|
||
| PREV_RELEASE_IMAGE="ghcr.io/thepalaceproject/circ-webapp:${prev_tag#v}" | ||
| fi | ||
| export PREV_RELEASE_IMAGE | ||
| echo "Previous release image: ${PREV_RELEASE_IMAGE}" | ||
|
|
||
| if [[ -z "${WEBAPP_IMAGE:-}" ]]; then | ||
| fail "WEBAPP_IMAGE is not set; it must point at the current build's webapp image." | ||
| fi | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| # (2) Build the current schema by initializing a fresh database with the current image. | ||
| compose_cmd up -d pg os minio redis || fail "Could not start service containers." | ||
| run_in_container webapp "./bin/util/initialize_instance" \ | ||
| || fail "Failed to initialize the database with the current image." | ||
|
|
||
| # (3) Run the previous release's database tests against the new schema. In external-schema | ||
| # mode each xdist worker clones the freshly-built schema into its own database, so the suite | ||
| # runs in parallel (-n auto). | ||
| compose_cmd pull --quiet webapp-prev || fail "Could not pull ${PREV_RELEASE_IMAGE}." | ||
| echo "Running the previous release's database tests against the current schema ..." | ||
| if ! run_in_container webapp-prev \ | ||
| "uv sync --frozen --active && pytest --no-cov -n auto -m db --ignore=tests/migration tests"; then | ||
| fail "Previous release tests failed against the current schema: the migration is not backwards compatible." | ||
|
jonathangreen marked this conversation as resolved.
|
||
| fi | ||
|
|
||
| echo "The previous release works against the current schema 🎉" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Compose overlay for the backwards-compatibility check; see test_backwards_compatibility.sh. | ||
| # | ||
| # The `webapp` service (from docker-compose.yml, the image built by the current commit) is | ||
| # used to build the new schema. `webapp-prev` runs a previously released image and re-runs | ||
| # its database tests against that schema in external-schema mode. | ||
| services: | ||
| webapp-prev: | ||
| # Inherit the full test environment (database/search/storage/redis URLs, etc.) from the | ||
| # webapp service so the previous release's test suite can run, then point it at the | ||
| # previous release's published image and turn on external-schema mode. | ||
| extends: | ||
| file: docker-compose.yml | ||
| service: webapp | ||
| image: "${PREV_RELEASE_IMAGE}" | ||
| environment: | ||
| PALACE_TEST_DATABASE_EXTERNAL_SCHEMA: "true" | ||
| # External-schema mode with database creation enabled clones the externally-built | ||
| # schema into a per-worker database, so the previous release's suite can run in | ||
| # parallel (-n auto); see DatabaseCreationFixture. | ||
| PALACE_TEST_DATABASE_CREATE_DATABASE: "true" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This skip isn't strictly necessary, but I added it for consistency with the
backwards-compatibility-testskip below. Since we shouldn't need these tests for a tagged release build.