-
Notifications
You must be signed in to change notification settings - Fork 1
fix(ci): make stacked PR validation a develop prerequisite #1691
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
Draft
seonghobae
wants to merge
3
commits into
develop
Choose a base branch
from
fix/stacked-pr-trigger-foundation
base: develop
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.
Draft
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,51 @@ | ||
| """Guard repo-local PR validation on dependent stacked pull requests.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import yaml | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| PR_VALIDATION_WORKFLOWS = ( | ||
| ".github/workflows/app-ci.yml", | ||
| ".github/workflows/bandit.yml", | ||
| ".github/workflows/dependency-review.yml", | ||
| ".github/workflows/docker-publish.yml", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("workflow_path", PR_VALIDATION_WORKFLOWS) | ||
| def test_repo_local_pr_validation_accepts_every_base_branch(workflow_path: str) -> None: | ||
| """Require an unfiltered pull_request trigger for every stacked PR base.""" | ||
| workflow_text = (REPO_ROOT / workflow_path).read_text(encoding="utf-8") | ||
| # BaseLoader preserves the Actions `on` key instead of YAML 1.1 boolean coercion. | ||
| workflow_events = yaml.load(workflow_text, Loader=yaml.BaseLoader)["on"] | ||
| assert "pull_request" in workflow_events | ||
| pull_request_config = workflow_events["pull_request"] or {} | ||
| assert "branches" not in pull_request_config | ||
| assert "branches-ignore" not in pull_request_config | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "branch_filter", | ||
| [ | ||
| "branches: ['**']", | ||
| "branches: ['**', '!feature/**']", | ||
| "branches: [develop] # '**' is only a comment", | ||
| "branches-ignore: [archive/**]", | ||
| ], | ||
| ) | ||
| def test_stacked_trigger_guard_rejects_any_base_filter( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch, branch_filter: str | ||
| ) -> None: | ||
| """Do not encode all-base verification through mutable branch patterns.""" | ||
| workflow_path = tmp_path / "workflow.yml" | ||
| workflow_path.write_text( | ||
| f"on:\n pull_request:\n {branch_filter}\n", encoding="utf-8" | ||
| ) | ||
| monkeypatch.setitem(globals(), "REPO_ROOT", tmp_path) | ||
| with pytest.raises(AssertionError): | ||
| test_repo_local_pr_validation_accepts_every_base_branch("workflow.yml") |
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,83 @@ | ||
| """Repository contract for PostgreSQL-backed backend acceptance.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[1] | ||
| APP_CI = REPO_ROOT / ".github" / "workflows" / "app-ci.yml" | ||
| PGVECTOR_CI_IMAGE = ( | ||
| "pgvector/pgvector:pg16@" | ||
| "sha256:ccc6e83d6e35e931dc7c5def2022729d5a6c370318d099181995567ff1fb4d6b" | ||
| ) | ||
|
|
||
|
|
||
| def _workflow() -> dict[str, object]: | ||
| """Load the workflow without YAML 1.1 coercing the `on` key to a boolean.""" | ||
| return yaml.load(APP_CI.read_text(encoding="utf-8"), Loader=yaml.BaseLoader) | ||
|
|
||
|
|
||
| def test_backend_ci_provisions_migrated_pgvector_database() -> None: | ||
| """Real PostgreSQL tests must run against a ready, migrated CI database.""" | ||
| workflow = _workflow() | ||
| jobs = workflow["jobs"] | ||
| assert isinstance(jobs, dict) | ||
| backend = jobs["backend"] | ||
| assert isinstance(backend, dict) | ||
|
|
||
| services = backend.get("services") | ||
| assert isinstance(services, dict), "backend CI must provision PostgreSQL" | ||
| postgres = services.get("postgres") | ||
| assert isinstance(postgres, dict), "backend CI must declare a postgres service" | ||
| assert postgres.get("image") == PGVECTOR_CI_IMAGE | ||
| assert postgres.get("env") == { | ||
| "POSTGRES_USER": "test", | ||
| "POSTGRES_PASSWORD": "test", | ||
| "POSTGRES_DB": "test_db", | ||
| } | ||
| options = postgres.get("options") | ||
| assert isinstance(options, str) | ||
| assert "pg_isready -U test -d test_db" in options | ||
|
|
||
| environment = backend.get("env") | ||
| assert isinstance(environment, dict) | ||
| assert environment.get("DATABASE_URL") == ( | ||
| "postgresql+asyncpg://test:test@localhost:5432/test_db" | ||
| ) | ||
| assert "AUTH_SESSION_HMAC_SECRET" not in environment, ( | ||
| "CI runtime auth material must be generated per job, not committed as a fixture" | ||
| ) | ||
|
|
||
| steps = backend.get("steps") | ||
| assert isinstance(steps, list) | ||
| named_steps = { | ||
| step.get("name"): step | ||
| for step in steps | ||
| if isinstance(step, dict) and isinstance(step.get("name"), str) | ||
| } | ||
| runtime_secret = named_steps.get("Generate ephemeral CI runtime secret") | ||
| assert isinstance(runtime_secret, dict), ( | ||
| "backend CI must generate auth material before importing runtime settings" | ||
| ) | ||
| runtime_secret_script = str(runtime_secret.get("run", "")) | ||
| assert "secrets.token_urlsafe(48)" in runtime_secret_script | ||
| assert "AUTH_SESSION_HMAC_SECRET" in runtime_secret_script | ||
| assert "GITHUB_ENV" in runtime_secret_script | ||
| assert 'print(f"::add-mask::{value}")' in runtime_secret_script, ( | ||
| "generated runtime auth material must be masked before later steps expose env" | ||
| ) | ||
| assert runtime_secret_script.index("::add-mask::") < runtime_secret_script.index( | ||
| "GITHUB_ENV" | ||
| ) | ||
|
|
||
| migration = named_steps.get("Run database migrations") | ||
| assert isinstance(migration, dict), "backend CI must migrate before pytest" | ||
| assert "python scripts/migrate_db.py" in str(migration.get("run", "")) | ||
|
|
||
| step_names = [ | ||
| step.get("name") for step in steps if isinstance(step, dict) and step.get("name") | ||
| ] | ||
| assert step_names.index("Generate ephemeral CI runtime secret") < step_names.index( | ||
| "Run database migrations" | ||
| ) < step_names.index("Run backend tests") | ||
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.
Uh oh!
There was an error while loading. Please reload this page.