Compare commits
34
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0131a1f415 | ||
|
|
5bdda2f8c9 | ||
|
|
7b1756818f | ||
|
|
68f17d3b09 | ||
|
|
130bc35ab0 | ||
|
|
9b7161c3c8 | ||
|
|
482d72ce21 | ||
|
|
45a439796f | ||
|
|
02f0b93e41 | ||
|
|
5e433ec629 | ||
|
|
cec7a76f12 | ||
|
|
8717d3536e | ||
|
|
8229a66bc5 | ||
|
|
9687feb36c | ||
|
|
0fefe6a064 | ||
|
|
2956e3ffce | ||
|
|
0afe2a231f | ||
|
|
65265e48a4 | ||
|
|
49399deb3d | ||
|
|
9fe4257490 | ||
|
|
0965a45653 | ||
|
|
bfd41c8e0d | ||
|
|
9c30a30754 | ||
|
|
ee8953bd93 | ||
|
|
5bc3167286 | ||
|
|
1a3368e119 | ||
|
|
1ddba883c9 | ||
|
|
da8044d6f2 | ||
|
|
67ba48da1f | ||
|
|
5196609974 | ||
|
|
49e09a6776 | ||
|
|
748016f105 | ||
|
|
6514aaa688 | ||
|
|
3ac47adc21 |
No files matched your search
+1
-34
@@ -4,9 +4,6 @@ parameters:
|
||||
run_rc_finalize_sweep:
|
||||
type: boolean
|
||||
default: false
|
||||
run_enrollment_reconcile:
|
||||
type: boolean
|
||||
default: false
|
||||
orbs:
|
||||
orb-tools: circleci/orb-tools@12.3
|
||||
shellcheck: circleci/shellcheck@3.2
|
||||
@@ -16,23 +13,6 @@ filters: &filters
|
||||
only: /.*/
|
||||
|
||||
jobs:
|
||||
enrollment-reconcile:
|
||||
docker:
|
||||
- image: cimg/python:3.12
|
||||
resource_class: small
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Install reconciliation tools
|
||||
command: |
|
||||
bash tools/install_reconcile_gh.sh
|
||||
python3 -m pip install --disable-pip-version-check PyYAML==6.0.3
|
||||
- run:
|
||||
name: Reconcile current QQQ branches
|
||||
no_output_timeout: 21m
|
||||
command: python3 tools/run_enrollment.py
|
||||
- store_artifacts:
|
||||
path: artifacts/enrollment
|
||||
rc-finalize-sweep:
|
||||
docker:
|
||||
- image: cimg/python:3.12
|
||||
@@ -48,10 +28,7 @@ jobs:
|
||||
workflows:
|
||||
lint-pack:
|
||||
when:
|
||||
not:
|
||||
or:
|
||||
- << pipeline.parameters.run_rc_finalize_sweep >>
|
||||
- << pipeline.parameters.run_enrollment_reconcile >>
|
||||
not: << pipeline.parameters.run_rc_finalize_sweep >>
|
||||
jobs:
|
||||
- orb-tools/lint:
|
||||
filters: *filters
|
||||
@@ -79,13 +56,3 @@ workflows:
|
||||
only: main
|
||||
tags:
|
||||
ignore: /.*/
|
||||
reconcile-enrollment:
|
||||
when: << pipeline.parameters.run_enrollment_reconcile >>
|
||||
jobs:
|
||||
- enrollment-reconcile:
|
||||
context: qqq-maven-registry-credentials
|
||||
filters:
|
||||
branches:
|
||||
only: main
|
||||
tags:
|
||||
ignore: /.*/
|
||||
@@ -57,12 +57,10 @@ jobs:
|
||||
python3 tests/test_ci_maintenance.py
|
||||
python3 tests/test_rollout_version.py
|
||||
python3 tests/test_enforce_orb_checks.py
|
||||
python3 tests/test_native_next_gates.py
|
||||
python3 tests/test_enroll_consumers.py
|
||||
python3 tests/test_reconcile_enrollment.py
|
||||
python3 tests/test_discover_enrollment.py
|
||||
python3 tests/test_finish_enrollment.py
|
||||
python3 tests/test_run_enrollment.py
|
||||
python3 tests/test_static_analysis_exit.py
|
||||
python3 tests/test_validate_standard.py
|
||||
python3 tests/test_voyage_profile.py
|
||||
|
||||
@@ -50,31 +50,22 @@ python tools/reconcile_enrollment.py --targets remote-targets.json --orb-version
|
||||
python tools/reconcile_enrollment.py --targets remote-targets.json --orb-version 0.8 --output result.json --apply
|
||||
```
|
||||
|
||||
Use existing `gh` authentication with repository write access. The coordinator
|
||||
never installs credentials or changes authentication. Every target is inspected
|
||||
at an immutable head and validated before any remote mutation. No repository
|
||||
clone, SSH key or local signing key is required. A moved target stops submission;
|
||||
refresh the plan instead of overwriting it.
|
||||
Use existing `gh` authentication, GitHub SSH access, Git author identity and a
|
||||
working Git signing configuration. The coordinator never installs credentials
|
||||
or changes authentication. Every target is inspected at an immutable head and
|
||||
validated before any remote mutation. Only changed targets are cloned. A moved
|
||||
target stops submission; refresh the plan instead of overwriting it.
|
||||
|
||||
An automation branch derives from the source commit and proposed declarations.
|
||||
The coordinator creates the branch at the observed base and uses GitHub's
|
||||
`createCommitOnBranch` API with `expectedHeadOid` for an atomic append. GitHub
|
||||
signs the commit when supported by the authenticated identity; the coordinator
|
||||
requires remote signature verification, exact parent, changed paths and
|
||||
declaration bytes before opening a PR. It never force-updates a branch.
|
||||
An interrupted branch creation, commit or PR creation can be resumed:
|
||||
an existing branch still at the planned base receives the missing commit;
|
||||
The coordinator signs its commit, pushes without force, verifies the remote
|
||||
signature, parent, exact changed paths and declaration bytes, then opens a PR.
|
||||
An interrupted push or PR creation can be resumed with the same invocation:
|
||||
matching signed branches and PRs are reused. A mismatched branch is rejected.
|
||||
Closed existing PRs are reported as existing; they are not silently reopened.
|
||||
Reports include repository, branch, immutable head and submission URL, without
|
||||
embedding declaration contents or credentials. Keep the report if a later target
|
||||
fails; earlier valid submissions remain intact.
|
||||
|
||||
API permission, signature or commit-conflict failures stop the run. A timeout
|
||||
can occur after GitHub accepted a mutation, so inspect remote state or repeat
|
||||
the same invocation; do not create a different automation branch to retry.
|
||||
See [GitHub commit API documentation](https://docs.github.com/en/graphql/reference/commits#createcommitonbranch).
|
||||
|
||||
This handles remote target lists and signed submissions. Organization discovery is described below. Qualification-aware merging and classic branch enforcement are described below; scheduling and ruleset reconciliation remain separate work. A submitted PR is not a completed migration. Unknown profiles and
|
||||
native workflows require their own central conversion, not deletion by this tool.
|
||||
|
||||
@@ -126,27 +117,3 @@ Existing active repository rulesets with app-bound gates and no bypass actors ar
|
||||
A merged source update and an enforced branch are separate reported outcomes.
|
||||
Neither proves artifact publication or deployment. Scheduling and ruleset
|
||||
reconciliation remain outstanding.
|
||||
|
||||
## Central hosted pass
|
||||
|
||||
The orb owner's CircleCI config accepts `run_enrollment_reconcile: true` on
|
||||
`main`. This selects one small Python container instead of the normal orb
|
||||
build/publication workflow. It uses the existing
|
||||
`qqq-maven-registry-credentials` context's GitHub token through `gh`.
|
||||
No consumer-specific runner configuration or local signing key is needed.
|
||||
|
||||
`tools/run_enrollment.py` verifies the owner repository and main branch, runs
|
||||
organization discovery, signed enrollment, qualified merging and enforcement,
|
||||
then exits. The pass has a 20-minute execution limit. Pending checks are reported
|
||||
for the next pass rather than polled while a paid executor waits. Incremental
|
||||
results and execution status are retained under `artifacts/enrollment`, including
|
||||
when execution fails or times out. A completed pass does not mean every repository
|
||||
conforms: unresolved and waiting entries remain explicit follow-up work.
|
||||
|
||||
Create a single daily CircleCI schedule for the owner project only after a manual
|
||||
main-branch pass verifies its hosted credentials and results. Set `branch: main`
|
||||
and `run_enrollment_reconcile: true` in the schedule parameters. Scheduling is
|
||||
an external project setting; merging this config does not itself enable a schedule.
|
||||
Keep the existing RC-finalization parameter false for these runs. A timed-out
|
||||
GitHub request may already have succeeded remotely; the next pass resumes from
|
||||
the deterministic branch and verified source rather than forcing updates.
|
||||
@@ -70,12 +70,10 @@ def load_manifest(path, setup_version):
|
||||
if not isinstance(data, dict):
|
||||
raise ManifestError("Manifest must be a mapping")
|
||||
profile = data.get("profile")
|
||||
if profile not in ("qbit", "core", "frontend-material", "frontend-core", "cli", "voyage", "frontend-next", "all", "app-starter", "android", "mcp-policy", "repository-policy", "marketing", "node-artifact"):
|
||||
if profile not in ("qbit", "core", "frontend-material", "frontend-core", "cli", "voyage", "frontend-next", "all", "app-starter", "android", "mcp-policy", "repository-policy", "marketing"):
|
||||
raise ManifestError("Unsupported profile")
|
||||
allowed = ("profile", "orb_version", "default_branch", "docs_only", "publish")
|
||||
if profile == "node-artifact":
|
||||
allowed = ("profile", "orb_version", "default_branch", "node_version", "context", "npm_scopes", "artifact_path", "build_branches")
|
||||
elif profile in ("qbit", "core"):
|
||||
if profile in ("qbit", "core"):
|
||||
allowed += ("java_version", "browsers", "api_checks")
|
||||
if profile == "qbit":
|
||||
allowed += ("release_completion", "release_on_main", "release_tag_policy", "test_branch_policy")
|
||||
@@ -106,22 +104,6 @@ def load_manifest(path, setup_version):
|
||||
node = data.get("node_version", "24.21" if profile == "frontend-core" else "20")
|
||||
if not isinstance(node, str) or not re.fullmatch(r"\d+(?:\.\d+){0,2}", node):
|
||||
raise ManifestError("node_version must be an explicit numeric version string")
|
||||
if profile == "node-artifact":
|
||||
context = data.get("context", "")
|
||||
scopes = data.get("npm_scopes", [])
|
||||
artifact = data.get("artifact_path")
|
||||
branches = data.get("build_branches")
|
||||
if not isinstance(context, str) or not re.fullmatch(r"[A-Za-z0-9_-]+", context):
|
||||
raise ManifestError("Node artifact requires an explicit context")
|
||||
if not isinstance(scopes, list) or any(not isinstance(x, str) or not re.fullmatch(r"@[a-z0-9][a-z0-9-]*", x) for x in scopes) or len(scopes) != len(set(scopes)):
|
||||
raise ManifestError("Invalid npm registry scopes")
|
||||
if not isinstance(artifact, str) or not re.fullmatch(r"[A-Za-z0-9_-]+(?:/[A-Za-z0-9_.-]+)+", artifact) or any(x in (".", "..") for x in artifact.split("/")):
|
||||
raise ManifestError("Artifact must be a relative file path")
|
||||
if not isinstance(branches, list) or not branches or any(not isinstance(x, str) or not re.fullmatch(r"[A-Za-z0-9_-]+(?:/[A-Za-z0-9_.-]+)*", x) for x in branches) or len(branches) != len(set(branches)):
|
||||
raise ManifestError("Build branches must be distinct literal branch names")
|
||||
return {"profile": profile, "orb_version": version, "default_branch": default_branch,
|
||||
"node_version": node, "context": context, "npm_scopes": scopes,
|
||||
"artifact_path": artifact, "build_branches": branches}
|
||||
publish_keys = ("snapshot", "release_candidate", "release")
|
||||
if profile == "all":
|
||||
publish_keys = ("snapshot",)
|
||||
@@ -148,7 +130,7 @@ def load_manifest(path, setup_version):
|
||||
raise ManifestError("Unsupported QBit release tag policy")
|
||||
test_policy = data.get("test_branch_policy", "all")
|
||||
if test_policy not in ("all", "non-release", "non-release-no-integration", "feature", "non-release-no-main",
|
||||
"non-release-no-hotfix", "non-release-no-hotfix-integration", "non-release-no-main-hotfix", "feature-no-hotfix"):
|
||||
"non-release-no-hotfix", "non-release-no-main-hotfix", "feature-no-hotfix"):
|
||||
raise ManifestError("Unsupported QBit test branch policy")
|
||||
return {"profile": profile, "orb_version": version, "default_branch": default_branch,
|
||||
"java_version": java, "node_version": node, "browsers": boolean(data, "browsers", True),
|
||||
@@ -256,7 +238,6 @@ def qbit_template(config, branch, tag):
|
||||
"feature": "/(develop|main|release/.*|integration.*)/",
|
||||
"non-release-no-main": "/(develop|main|release/.*)/",
|
||||
"non-release-no-hotfix": "/(develop|release/.*|hotfix/.*)/",
|
||||
"non-release-no-hotfix-integration": "/(develop|release/.*|hotfix/.*|integration.*)/",
|
||||
"non-release-no-main-hotfix": "/(develop|main|release/.*|hotfix/.*)/",
|
||||
"feature-no-hotfix": "/(develop|main|release/.*|hotfix/.*|integration.*)/"}
|
||||
ignored = ignores[config.get("test_branch_policy", "all")]
|
||||
@@ -478,30 +459,6 @@ PROFILE_TEMPLATES = {"qbit": qbit_template, "core": core_template,
|
||||
"cli": cli_template, "voyage": voyage_template, "frontend-next": next_template, "all": all_template, "app-starter": starter_template, "android": android_template, "mcp-policy": policy_template, "marketing": marketing_template}
|
||||
|
||||
|
||||
def node_artifact_template(config, branch, tag):
|
||||
# One checkout/install is shared by tests and an optional artifact build.
|
||||
lines = ["registry=https://registry.npmjs.org/"]
|
||||
lines += [scope + ":registry=https://npm.pkg.github.com/" for scope in config["npm_scopes"]]
|
||||
if config["npm_scopes"]:
|
||||
lines.append("//npm.pkg.github.com/:_authToken=${NPM_TOKEN}")
|
||||
npmrc = "printf '%s\\n' " + " ".join("'" + line + "'" for line in lines) + " >> .npmrc"
|
||||
steps = ["checkout", {"run": {"name": "Configure npm registries", "command": npmrc}},
|
||||
{"restore_cache": {"keys": ['node-artifact-npm-v1-{{ checksum "package-lock.json" }}', 'node-artifact-npm-v1-']}},
|
||||
{"run": {"name": "Install locked dependencies", "command": "npm ci --prefer-offline --cache ~/.npm"}},
|
||||
{"save_cache": {"key": 'node-artifact-npm-v1-{{ checksum "package-lock.json" }}', "paths": ["~/.npm"]}},
|
||||
{"run": {"name": "Test project", "command": "npm test"}}]
|
||||
if not tag and branch in config["build_branches"]:
|
||||
steps += [{"run": {"name": "Build artifact", "command": "npm run build"}},
|
||||
{"store_artifacts": {"path": config["artifact_path"], "destination": config["artifact_path"].split("/")[-1]}}]
|
||||
return {"version": 2.1,
|
||||
"jobs": {"node_artifact": {"docker": [{"image": "cimg/node:" + config["node_version"]}], "steps": steps}},
|
||||
"workflows": {"verify": {"jobs": [{"node_artifact": {"context": [config["context"]],
|
||||
"filters": {"branches": {"ignore": "automation/qbit-rc-pending"}, "tags": {"ignore": "/.*/"}}}}]}}}
|
||||
|
||||
|
||||
PROFILE_TEMPLATES["node-artifact"] = node_artifact_template
|
||||
|
||||
|
||||
def runtime_boolean(name):
|
||||
value = os.environ.get(name, "false").lower()
|
||||
if value in ("true", "1"):
|
||||
|
||||
@@ -70,12 +70,10 @@ def load_manifest(path, setup_version):
|
||||
if not isinstance(data, dict):
|
||||
raise ManifestError("Manifest must be a mapping")
|
||||
profile = data.get("profile")
|
||||
if profile not in ("qbit", "core", "frontend-material", "frontend-core", "cli", "voyage", "frontend-next", "all", "app-starter", "android", "mcp-policy", "repository-policy", "marketing", "node-artifact"):
|
||||
if profile not in ("qbit", "core", "frontend-material", "frontend-core", "cli", "voyage", "frontend-next", "all", "app-starter", "android", "mcp-policy", "repository-policy", "marketing"):
|
||||
raise ManifestError("Unsupported profile")
|
||||
allowed = ("profile", "orb_version", "default_branch", "docs_only", "publish")
|
||||
if profile == "node-artifact":
|
||||
allowed = ("profile", "orb_version", "default_branch", "node_version", "context", "npm_scopes", "artifact_path", "build_branches")
|
||||
elif profile in ("qbit", "core"):
|
||||
if profile in ("qbit", "core"):
|
||||
allowed += ("java_version", "browsers", "api_checks")
|
||||
if profile == "qbit":
|
||||
allowed += ("release_completion", "release_on_main", "release_tag_policy", "test_branch_policy")
|
||||
@@ -106,22 +104,6 @@ def load_manifest(path, setup_version):
|
||||
node = data.get("node_version", "24.21" if profile == "frontend-core" else "20")
|
||||
if not isinstance(node, str) or not re.fullmatch(r"\d+(?:\.\d+){0,2}", node):
|
||||
raise ManifestError("node_version must be an explicit numeric version string")
|
||||
if profile == "node-artifact":
|
||||
context = data.get("context", "")
|
||||
scopes = data.get("npm_scopes", [])
|
||||
artifact = data.get("artifact_path")
|
||||
branches = data.get("build_branches")
|
||||
if not isinstance(context, str) or not re.fullmatch(r"[A-Za-z0-9_-]+", context):
|
||||
raise ManifestError("Node artifact requires an explicit context")
|
||||
if not isinstance(scopes, list) or any(not isinstance(x, str) or not re.fullmatch(r"@[a-z0-9][a-z0-9-]*", x) for x in scopes) or len(scopes) != len(set(scopes)):
|
||||
raise ManifestError("Invalid npm registry scopes")
|
||||
if not isinstance(artifact, str) or not re.fullmatch(r"[A-Za-z0-9_-]+(?:/[A-Za-z0-9_.-]+)+", artifact) or any(x in (".", "..") for x in artifact.split("/")):
|
||||
raise ManifestError("Artifact must be a relative file path")
|
||||
if not isinstance(branches, list) or not branches or any(not isinstance(x, str) or not re.fullmatch(r"[A-Za-z0-9_-]+(?:/[A-Za-z0-9_.-]+)*", x) for x in branches) or len(branches) != len(set(branches)):
|
||||
raise ManifestError("Build branches must be distinct literal branch names")
|
||||
return {"profile": profile, "orb_version": version, "default_branch": default_branch,
|
||||
"node_version": node, "context": context, "npm_scopes": scopes,
|
||||
"artifact_path": artifact, "build_branches": branches}
|
||||
publish_keys = ("snapshot", "release_candidate", "release")
|
||||
if profile == "all":
|
||||
publish_keys = ("snapshot",)
|
||||
@@ -148,7 +130,7 @@ def load_manifest(path, setup_version):
|
||||
raise ManifestError("Unsupported QBit release tag policy")
|
||||
test_policy = data.get("test_branch_policy", "all")
|
||||
if test_policy not in ("all", "non-release", "non-release-no-integration", "feature", "non-release-no-main",
|
||||
"non-release-no-hotfix", "non-release-no-hotfix-integration", "non-release-no-main-hotfix", "feature-no-hotfix"):
|
||||
"non-release-no-hotfix", "non-release-no-main-hotfix", "feature-no-hotfix"):
|
||||
raise ManifestError("Unsupported QBit test branch policy")
|
||||
return {"profile": profile, "orb_version": version, "default_branch": default_branch,
|
||||
"java_version": java, "node_version": node, "browsers": boolean(data, "browsers", True),
|
||||
@@ -256,7 +238,6 @@ def qbit_template(config, branch, tag):
|
||||
"feature": "/(develop|main|release/.*|integration.*)/",
|
||||
"non-release-no-main": "/(develop|main|release/.*)/",
|
||||
"non-release-no-hotfix": "/(develop|release/.*|hotfix/.*)/",
|
||||
"non-release-no-hotfix-integration": "/(develop|release/.*|hotfix/.*|integration.*)/",
|
||||
"non-release-no-main-hotfix": "/(develop|main|release/.*|hotfix/.*)/",
|
||||
"feature-no-hotfix": "/(develop|main|release/.*|hotfix/.*|integration.*)/"}
|
||||
ignored = ignores[config.get("test_branch_policy", "all")]
|
||||
@@ -478,30 +459,6 @@ PROFILE_TEMPLATES = {"qbit": qbit_template, "core": core_template,
|
||||
"cli": cli_template, "voyage": voyage_template, "frontend-next": next_template, "all": all_template, "app-starter": starter_template, "android": android_template, "mcp-policy": policy_template, "marketing": marketing_template}
|
||||
|
||||
|
||||
def node_artifact_template(config, branch, tag):
|
||||
# One checkout/install is shared by tests and an optional artifact build.
|
||||
lines = ["registry=https://registry.npmjs.org/"]
|
||||
lines += [scope + ":registry=https://npm.pkg.github.com/" for scope in config["npm_scopes"]]
|
||||
if config["npm_scopes"]:
|
||||
lines.append("//npm.pkg.github.com/:_authToken=${NPM_TOKEN}")
|
||||
npmrc = "printf '%s\\n' " + " ".join("'" + line + "'" for line in lines) + " >> .npmrc"
|
||||
steps = ["checkout", {"run": {"name": "Configure npm registries", "command": npmrc}},
|
||||
{"restore_cache": {"keys": ['node-artifact-npm-v1-{{ checksum "package-lock.json" }}', 'node-artifact-npm-v1-']}},
|
||||
{"run": {"name": "Install locked dependencies", "command": "npm ci --prefer-offline --cache ~/.npm"}},
|
||||
{"save_cache": {"key": 'node-artifact-npm-v1-{{ checksum "package-lock.json" }}', "paths": ["~/.npm"]}},
|
||||
{"run": {"name": "Test project", "command": "npm test"}}]
|
||||
if not tag and branch in config["build_branches"]:
|
||||
steps += [{"run": {"name": "Build artifact", "command": "npm run build"}},
|
||||
{"store_artifacts": {"path": config["artifact_path"], "destination": config["artifact_path"].split("/")[-1]}}]
|
||||
return {"version": 2.1,
|
||||
"jobs": {"node_artifact": {"docker": [{"image": "cimg/node:" + config["node_version"]}], "steps": steps}},
|
||||
"workflows": {"verify": {"jobs": [{"node_artifact": {"context": [config["context"]],
|
||||
"filters": {"branches": {"ignore": "automation/qbit-rc-pending"}, "tags": {"ignore": "/.*/"}}}}]}}}
|
||||
|
||||
|
||||
PROFILE_TEMPLATES["node-artifact"] = node_artifact_template
|
||||
|
||||
|
||||
def runtime_boolean(name):
|
||||
value = os.environ.get(name, "false").lower()
|
||||
if value in ("true", "1"):
|
||||
|
||||
@@ -47,7 +47,6 @@ PROFILE_PARAMETERS = {
|
||||
"mcp-policy": {},
|
||||
"repository-policy": {},
|
||||
"marketing": {},
|
||||
"node-artifact": {},
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +66,6 @@ def canonical_caller(profile, version, explicit_manifest=False, release_tag_poli
|
||||
"orb_version": version,
|
||||
"filters": {"branches": {"ignore": "automation/qbit-rc-pending"}, "tags": {"only": "/.*/"}},
|
||||
}
|
||||
if profile == "node-artifact":
|
||||
options["filters"]["tags"] = {"ignore": "/.*/"}
|
||||
if profile == "frontend-next":
|
||||
options["filters"]["branches"] = {"ignore": "/.*/"}
|
||||
if profile == "qbit" and release_tag_policy is not None:
|
||||
|
||||
@@ -18,42 +18,6 @@ def runs():
|
||||
|
||||
|
||||
class EnforcementTests(unittest.TestCase):
|
||||
def test_profile_gates_match_shared_branch_workflows(self):
|
||||
spec = importlib.util.spec_from_file_location('pipeline',
|
||||
Path(__file__).resolve().parents[1] / 'src/scripts/generate_pipeline.py')
|
||||
pipeline = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(pipeline)
|
||||
for profile in ('all', 'cli', 'android', 'app-starter', 'mcp-policy'):
|
||||
desired = enforcement.gates(profile)
|
||||
for branch in ('main', 'develop', 'feature/change'):
|
||||
config = {'orb_version': '0.8', 'publish': {'snapshot': False, 'release': False}}
|
||||
output = pipeline.PROFILE_TEMPLATES[profile](config, branch, '')
|
||||
self.assertEqual([desired[1]['context']], list(output['workflows']))
|
||||
successful = [{'id': i, 'name': gate['context'], 'app': {'id': 18001},
|
||||
'conclusion': 'success'} for i, gate in enumerate(desired)]
|
||||
before = {'required_status_checks': {'checks': [
|
||||
*desired, {'context': 'scanner', 'app_id': 15368}]}}
|
||||
checks = enforcement.required_checks(before, successful, desired)['checks']
|
||||
self.assertTrue(enforcement.same_checks(before['required_status_checks']['checks'], checks))
|
||||
self.assertNotIn({'context': 'verify', 'app_id': 18001}, checks)
|
||||
for bad in (successful[:1], [*successful, dict(successful[1], id=99, conclusion='failure')],
|
||||
[dict(run, app={'id': 999}) for run in successful]):
|
||||
with self.subTest(profile=profile), self.assertRaises(ValueError):
|
||||
enforcement.required_checks(before, bad, desired)
|
||||
record, effective = self.ruleset_fixture()
|
||||
record['rules'][0]['parameters']['required_status_checks'] = [
|
||||
{'context': gate['context'], 'integration_id': gate['app_id']} for gate in desired]
|
||||
enforcement.verified_rulesets('QRun-IO/example', effective, lambda path: record, desired)
|
||||
with self.assertRaises(ValueError):
|
||||
enforcement.verified_rulesets('QRun-IO/example', effective, lambda path: record)
|
||||
|
||||
def test_check_comparison_ignores_only_order(self):
|
||||
checks = [*enforcement.DESIRED, {'context': 'scanner', 'app_id': 15368}]
|
||||
self.assertTrue(enforcement.same_checks(checks, list(reversed(checks))))
|
||||
self.assertFalse(enforcement.same_checks(checks, checks[:-1]))
|
||||
self.assertFalse(enforcement.same_checks(checks, checks + checks[:1]))
|
||||
self.assertFalse(enforcement.same_checks(checks, [*enforcement.DESIRED, {'context': 'scanner', 'app_id': 999}]))
|
||||
|
||||
def test_preserves_security_gate_and_binds_orb_checks(self):
|
||||
before = {'required_status_checks': {'strict': False, 'contexts': ['security', 'setup'],
|
||||
'checks': [{'context': 'security', 'app_id': 15368}, {'context': 'setup', 'app_id': -1}]}}
|
||||
@@ -118,22 +82,6 @@ class EnforcementTests(unittest.TestCase):
|
||||
enforcement.enforce(plan, request)
|
||||
self.assertEqual([], state['writes'])
|
||||
|
||||
def test_github_may_reorder_required_checks_on_readback(self):
|
||||
before = {'required_status_checks': {'strict': True, 'checks': [
|
||||
*enforcement.DESIRED, {'context': 'scanner', 'app_id': 15368}]},
|
||||
'enforce_admins': {'enabled': False}, 'required_signatures': {'enabled': True}}
|
||||
plan, request, state = self.fixture(before)
|
||||
|
||||
def reordered(path, method='GET', payload=None):
|
||||
value = request(path, method, payload)
|
||||
if method == 'PATCH':
|
||||
state['before']['required_status_checks']['checks'].reverse()
|
||||
return value
|
||||
|
||||
enforcement.enforce(plan, reordered)
|
||||
self.assertTrue(state['before']['enforce_admins']['enabled'])
|
||||
self.assertEqual(before['required_signatures'], state['before']['required_signatures'])
|
||||
|
||||
def test_head_or_protection_drift_never_mutates(self):
|
||||
for field, value in [('head', 'b' * 40), ('before', {'unexpected': True})]:
|
||||
plan, request, state = self.fixture(None)
|
||||
|
||||
@@ -29,9 +29,6 @@ class EnrollmentTests(unittest.TestCase):
|
||||
target = self.legacy(profile)
|
||||
root = Path(target['checkout'])
|
||||
data = {'profile': profile, 'orb_version': '0.7.4', 'default_branch': 'main'}
|
||||
if profile == 'node-artifact':
|
||||
data.update(context='registry', npm_scopes=['@example'],
|
||||
artifact_path='dist/bundle.js', build_branches=['main'])
|
||||
(root / '.qqq-ci.yml').write_text(yaml.safe_dump(data), encoding='utf-8')
|
||||
(root / '.circleci/config.yml').write_text(yaml.safe_dump(
|
||||
enrollment.rollout.standard.canonical_caller(profile, '0.7.4')), encoding='utf-8')
|
||||
|
||||
@@ -29,17 +29,6 @@ class FinishTests(unittest.TestCase):
|
||||
{'statuses': [{'context': 'legacy-test', 'state': 'pending'}]}]):
|
||||
self.assertEqual(['legacy-test', 'scanner', 'verify'], finish.qualification('QRun-IO/example', 'b' * 40))
|
||||
|
||||
def test_profile_qualification_requires_its_actual_workflow(self):
|
||||
for profile in ('all', 'cli', 'android', 'app-starter', 'mcp-policy'):
|
||||
checks = self.checks()
|
||||
checks[1]['name'] = finish.enforcement.PROFILE_GATES[profile]
|
||||
with mock.patch.object(finish.remote, 'api', side_effect=[
|
||||
{'check_runs': checks}, {'statuses': []}]):
|
||||
self.assertEqual([], finish.qualification('QRun-IO/example', 'b' * 40, profile))
|
||||
with mock.patch.object(finish.remote, 'api', side_effect=[
|
||||
{'check_runs': self.checks()}, {'statuses': []}]):
|
||||
self.assertEqual([checks[1]['name']], finish.qualification('QRun-IO/example', 'b' * 40, profile))
|
||||
|
||||
def test_failed_or_missing_checks_never_merge(self):
|
||||
with mock.patch.object(finish.remote, 'verify_submission'), mock.patch.object(finish.remote, 'command', return_value=json.dumps(self.pr)) as command, mock.patch.object(finish.remote, 'api', return_value={'commit': {'sha': self.plan['head']}}), mock.patch.object(finish, 'qualification', return_value=['verify']):
|
||||
self.assertEqual('waiting-checks', finish.merge_ready(self.plan, self.result)['state'])
|
||||
@@ -83,7 +72,7 @@ class FinishTests(unittest.TestCase):
|
||||
enforce.assert_called_once_with(current)
|
||||
|
||||
def test_unknown_gate_profile_never_merges_or_enforces(self):
|
||||
self.plan['profile'] = 'marketing'
|
||||
self.plan['profile'] = 'all'
|
||||
with mock.patch.object(finish.remote, 'command') as command, mock.patch.object(finish.enforcement, 'inspect') as inspect:
|
||||
self.assertEqual('unsupported-gates', finish.merge_ready(self.plan, self.result)['state'])
|
||||
self.assertEqual('unsupported-gates', finish.enforce_current(self.plan)['state'])
|
||||
|
||||
@@ -191,36 +191,6 @@ class PipelineTests(unittest.TestCase):
|
||||
self.assertNotIn("Traceback", result.stderr)
|
||||
return result
|
||||
|
||||
def test_node_artifact_reuses_install_and_preserves_branch_artifact_policy(self):
|
||||
self.write_manifest(profile="node-artifact", context="qqq-maven-registry-credentials",
|
||||
npm_scopes=["@nocode-js", "@qrunio"], artifact_path="dist/q-sequential-workflow.bundle.js",
|
||||
build_branches=["main", "feature/initial-dev"], node_version="20")
|
||||
for packed in ([False, True] if PACKED else [False]):
|
||||
for branch in ("main", "develop", "feature/initial-dev", "feature/change"):
|
||||
output = self.render(packed=packed, CIRCLE_BRANCH=branch)
|
||||
self.assertEqual(["verify"], list(output["workflows"]))
|
||||
self.assertEqual(["node_artifact"], list(output["jobs"]))
|
||||
steps = output["jobs"]["node_artifact"]["steps"]
|
||||
self.assertEqual(1, steps.count("checkout"))
|
||||
commands = [step["run"]["command"] for step in steps if isinstance(step, dict) and "run" in step]
|
||||
self.assertEqual(1, commands.count("npm ci --prefer-offline --cache ~/.npm"))
|
||||
self.assertEqual(1, commands.count("npm test"))
|
||||
self.assertEqual(branch in ("main", "feature/initial-dev"), "npm run build" in commands)
|
||||
artifacts = [step["store_artifacts"] for step in steps if isinstance(step, dict) and "store_artifacts" in step]
|
||||
self.assertEqual(int(branch in ("main", "feature/initial-dev")), len(artifacts))
|
||||
self.assertNotIn("npm publish", str(output))
|
||||
self.assertIn("${NPM_TOKEN}", commands[0])
|
||||
self.assertEqual({"ignore": "/.*/"}, output["workflows"]["verify"]["jobs"][0]["node_artifact"]["filters"]["tags"])
|
||||
|
||||
def test_node_artifact_rejects_commands_paths_and_branch_regex(self):
|
||||
baseline = {"profile": "node-artifact", "context": "registry", "npm_scopes": [],
|
||||
"artifact_path": "dist/bundle.js", "build_branches": ["main"]}
|
||||
for invalid in ({"artifact_path": "dist/../secret"}, {"artifact_path": "/etc/passwd"},
|
||||
{"build_branches": ["/.*/"]}, {"npm_scopes": ["@scope;echo bad"]},
|
||||
{"publish": {"release": True}}, {"context": "$(echo bad)"}):
|
||||
self.write_manifest(**{**baseline, **invalid})
|
||||
self.render(ok=False)
|
||||
|
||||
def assert_full(self, result, workflow="test_only"):
|
||||
self.assertEqual(list(result["workflows"]), ["verify"])
|
||||
self.assertNotIn("docs_only", result.get("jobs", {}))
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
"""Recognize native ownership without duplicate CI or weaker PR protections."""
|
||||
import base64
|
||||
import copy
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
import yaml
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'tools'))
|
||||
import enforce_orb_checks as enforcement
|
||||
import finish_enrollment as finish
|
||||
|
||||
|
||||
class NativeTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = 'a' * 40
|
||||
self.head = 'b' * 40
|
||||
self.caller = enforcement.native.bridge.canonical_next(self.pin)
|
||||
self.signed = True
|
||||
self.worker_drift = False
|
||||
self.runs = [{'id': i, 'name': gate['context'], 'app': {'id': 15368},
|
||||
'status': 'completed', 'conclusion': 'success'}
|
||||
for i, gate in enumerate(enforcement.native.gates())]
|
||||
self.record = {'id': 1, 'enforcement': 'active', 'target': 'branch',
|
||||
'source_type': 'Repository', 'source': 'QRun-IO/example', 'bypass_actors': [],
|
||||
'rules': [{'type': 'required_status_checks', 'parameters': {
|
||||
'strict_required_status_checks_policy': False,
|
||||
'required_status_checks': [{'context': g['context'], 'integration_id': g['app_id']}
|
||||
for g in enforcement.gates('frontend-next')]}}]}
|
||||
|
||||
def request(self, path, method='GET', payload=None):
|
||||
self.assertEqual('GET', method, 'Recognition must not mutate correct protections')
|
||||
if '/contents/' in path:
|
||||
if '.github/workflows/ci.yml?' in path:
|
||||
raw = yaml.safe_dump(self.caller)
|
||||
elif 'repos/QRun-IO/qqq-orb/' in path:
|
||||
name = path.split('/contents/')[1].split('?')[0]
|
||||
raw = (ROOT / name).read_text(encoding='utf-8') + ('# drift' if self.worker_drift else '')
|
||||
else:
|
||||
data = ({'profile': 'frontend-next', 'orb_version': '0.8', 'default_branch': 'main'}
|
||||
if '/.qqq-ci.yml?' in path else enforcement.standard.canonical_caller('frontend-next', '0.8'))
|
||||
raw = yaml.safe_dump(data)
|
||||
return {'type': 'file', 'encoding': 'base64', 'content': base64.b64encode(raw.encode()).decode()}
|
||||
if path.endswith('/commits/' + self.pin):
|
||||
return {'commit': {'verification': {'verified': self.signed}}}
|
||||
if '/check-runs?' in path:
|
||||
return {'check_runs': copy.deepcopy(self.runs)}
|
||||
if '/status?' in path:
|
||||
return {'statuses': []}
|
||||
if '/rulesets/1' in path:
|
||||
return copy.deepcopy(self.record)
|
||||
if '/rules/branches/' in path:
|
||||
return [{'type': 'required_status_checks', 'ruleset_source_type': 'Repository',
|
||||
'ruleset_source': 'QRun-IO/example', 'ruleset_id': 1}]
|
||||
if path.endswith('/protection'):
|
||||
return None
|
||||
if '/branches/' in path:
|
||||
return {'commit': {'sha': self.head}}
|
||||
return {'archived': False}
|
||||
|
||||
def test_main_recognition_retains_all_eight_pr_gates_without_image_run(self):
|
||||
plan = enforcement.inspect('QRun-IO/example', 'main', '0.8', self.request)
|
||||
self.assertFalse(plan['changed'])
|
||||
self.assertEqual('rulesets', plan['protection_mode'])
|
||||
self.assertEqual(enforcement.gates('frontend-next'), plan['required_status_checks']['checks'])
|
||||
self.assertEqual(8, len(plan['gates']))
|
||||
enforcement.enforce(plan, self.request)
|
||||
|
||||
def test_caller_drift_unsigned_and_changed_workers_fail_closed(self):
|
||||
self.caller['jobs']['ci']['uses'] = 'untrusted/repo/ci.yml@' + self.pin
|
||||
with self.assertRaisesRegex(ValueError, 'canonical'):
|
||||
enforcement.inspect('QRun-IO/example', 'main', '0.8', self.request)
|
||||
self.caller = enforcement.native.bridge.canonical_next(self.pin)
|
||||
self.signed = False
|
||||
with self.assertRaisesRegex(ValueError, 'not verified'):
|
||||
enforcement.inspect('QRun-IO/example', 'main', '0.8', self.request)
|
||||
self.signed = True
|
||||
self.worker_drift = True
|
||||
with self.assertRaisesRegex(ValueError, 'supported contract'):
|
||||
enforcement.inspect('QRun-IO/example', 'main', '0.8', self.request)
|
||||
|
||||
def test_missing_main_gate_wrong_app_and_missing_pr_protection_reject(self):
|
||||
self.runs[0]['app']['id'] = 18001
|
||||
with self.assertRaises(ValueError):
|
||||
enforcement.inspect('QRun-IO/example', 'main', '0.8', self.request)
|
||||
self.runs[0]['app']['id'] = 15368
|
||||
self.record['rules'][0]['parameters']['required_status_checks'].pop()
|
||||
with self.assertRaisesRegex(ValueError, 'missing app-bound gate'):
|
||||
enforcement.inspect('QRun-IO/example', 'main', '0.8', self.request)
|
||||
|
||||
def test_pr_qualification_requires_both_image_architectures(self):
|
||||
with mock.patch.object(finish.remote, 'api', side_effect=self.request):
|
||||
missing = finish.qualification('QRun-IO/example', self.head, 'frontend-next')
|
||||
self.assertEqual(sorted(enforcement.native.PR_GATES[-2:]), missing)
|
||||
for i, name in enumerate(enforcement.native.PR_GATES[-2:], 20):
|
||||
self.runs.append({'id': i, 'name': name, 'app': {'id': 15368},
|
||||
'status': 'completed', 'conclusion': 'success'})
|
||||
self.assertEqual([], finish.qualification('QRun-IO/example', self.head, 'frontend-next'))
|
||||
|
||||
def test_develop_has_no_native_push_contract(self):
|
||||
with self.assertRaisesRegex(ValueError, 'main only'):
|
||||
enforcement.native.validate('QRun-IO/example', self.head, 'develop', self.request, enforcement.standard.load_yaml)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -118,67 +118,41 @@ class ReconcileTests(unittest.TestCase):
|
||||
self.assertEqual('submitted', result['state'])
|
||||
self.assertEqual([['gh', 'pr', 'create']], seen)
|
||||
|
||||
def test_new_api_submission_is_atomic_and_exact(self):
|
||||
def test_new_submission_requires_signed_commit_and_never_force_pushes(self):
|
||||
plan = self.plan()
|
||||
mutations = []
|
||||
committed = False
|
||||
seen = []
|
||||
|
||||
def request(path, missing=False):
|
||||
if '/git/ref/' in path:
|
||||
return None
|
||||
if '/pulls?' in path:
|
||||
return []
|
||||
return self.submission_api(plan, path, missing)
|
||||
|
||||
def mutate(path, payload):
|
||||
mutations.append((path, payload))
|
||||
return {'data': {'createCommitOnBranch': {'commit': {'oid': self.new}}}}
|
||||
def command(args, cwd=None):
|
||||
nonlocal committed
|
||||
seen.append(args)
|
||||
if args[:2] == ['git', 'clone']:
|
||||
root = Path(args[-1])
|
||||
(root / '.circleci').mkdir(parents=True)
|
||||
for name, data in self.sources.items():
|
||||
(root / name).write_bytes(data)
|
||||
elif args[:2] == ['git', 'rev-parse']:
|
||||
return self.new if committed else self.head
|
||||
elif args[:2] == ['git', 'commit']:
|
||||
self.assertIn('-S', args)
|
||||
for name in remote.PATHS:
|
||||
self.assertEqual(plan['replacements'][name], (cwd / name).read_bytes())
|
||||
committed = True
|
||||
elif args[:3] == ['gh', 'pr', 'create']:
|
||||
return 'https://github.com/QRun-IO/example/pull/3'
|
||||
return ''
|
||||
|
||||
with mock.patch.object(remote, 'api', side_effect=request), mock.patch.object(remote, 'mutation', side_effect=mutate), mock.patch.object(remote, 'command') as command:
|
||||
self.assertEqual('existing-pr', remote.apply(plan)['state'])
|
||||
command.assert_not_called()
|
||||
self.assertEqual(('repos/' + self.repo + '/git/refs', {'ref': 'refs/heads/' + plan['automation_branch'], 'sha': self.head}), mutations[0])
|
||||
commit = mutations[1][1]['variables']['input']
|
||||
self.assertEqual(self.head, commit['expectedHeadOid'])
|
||||
self.assertEqual({'repositoryNameWithOwner': self.repo, 'branchName': plan['automation_branch']}, commit['branch'])
|
||||
self.assertEqual(plan['replacements'], {item['path']: base64.b64decode(item['contents']) for item in commit['fileChanges']['additions']})
|
||||
|
||||
def test_base_only_branch_resumes_without_creating_another_ref(self):
|
||||
plan = self.plan()
|
||||
result = {'data': {'createCommitOnBranch': {'commit': {'oid': self.new}}}}
|
||||
with mock.patch.object(remote, 'api', return_value={'commit': {'sha': self.head}}), mock.patch.object(remote, 'mutation', return_value=result) as mutation:
|
||||
self.assertEqual(self.new, remote.signed_api_commit(plan, {'object': {'sha': self.head}}))
|
||||
self.assertEqual(1, mutation.call_count)
|
||||
self.assertEqual('graphql', mutation.call_args.args[0])
|
||||
|
||||
def test_existing_completed_branch_is_not_mutated(self):
|
||||
with mock.patch.object(remote, 'mutation') as mutation:
|
||||
self.assertEqual(self.new, remote.signed_api_commit(self.plan(), {'object': {'sha': self.new}}))
|
||||
mutation.assert_not_called()
|
||||
|
||||
def test_target_drift_prevents_commit_on_base_only_branch(self):
|
||||
plan = self.plan()
|
||||
with mock.patch.object(remote, 'api', return_value={'commit': {'sha': 'c' * 40}}), mock.patch.object(remote, 'mutation') as mutation:
|
||||
with self.assertRaises(ValueError):
|
||||
remote.signed_api_commit(plan, {'object': {'sha': self.head}})
|
||||
mutation.assert_not_called()
|
||||
|
||||
def test_graphql_errors_fail_closed(self):
|
||||
response = mock.Mock(returncode=0, stdout='{"errors": [{"message": "conflict"}]}')
|
||||
with mock.patch.object(remote.subprocess, 'run', return_value=response):
|
||||
with self.assertRaises(ValueError):
|
||||
remote.mutation('graphql', {})
|
||||
|
||||
def test_unsigned_api_commit_cannot_create_pr(self):
|
||||
plan = self.plan()
|
||||
def request(path, missing=False):
|
||||
if '/git/ref/' in path:
|
||||
return {'object': {'sha': self.head}}
|
||||
value = self.submission_api(plan, path, missing)
|
||||
if '/commits/' in path:
|
||||
value['commit']['verification']['verified'] = False
|
||||
return value
|
||||
with mock.patch.object(remote, 'api', side_effect=request), mock.patch.object(remote, 'mutation', return_value={'data': {'createCommitOnBranch': {'commit': {'oid': self.new}}}}), mock.patch.object(remote, 'command') as command:
|
||||
with self.assertRaises(ValueError):
|
||||
remote.apply(plan)
|
||||
command.assert_not_called()
|
||||
with mock.patch.object(remote, 'api', side_effect=request), mock.patch.object(remote, 'command', side_effect=command):
|
||||
self.assertEqual('submitted', remote.apply(plan)['state'])
|
||||
pushes = [args for args in seen if args[:2] == ['git', 'push']]
|
||||
self.assertEqual([['git', 'push', 'origin', 'HEAD:refs/heads/' + plan['automation_branch']]], pushes)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -20,9 +20,6 @@ class RolloutTests(unittest.TestCase):
|
||||
def checkout(self, name, profile='qbit', explicit=False, **policy):
|
||||
root = self.root / name
|
||||
(root / '.circleci').mkdir(parents=True)
|
||||
if profile == 'node-artifact':
|
||||
policy = {'context': 'registry', 'npm_scopes': ['@example'],
|
||||
'artifact_path': 'dist/bundle.js', 'build_branches': ['main'], **policy}
|
||||
manifest = {'profile': profile, 'orb_version': '0.7.4', 'default_branch': 'develop', **policy}
|
||||
caller = rollout.standard.canonical_caller(profile, '0.7.4', explicit_manifest=explicit,
|
||||
release_tag_policy=manifest.get('release_tag_policy'))
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
"""Central execution rejects untrusted branches and preserves partial evidence."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools'))
|
||||
import run_enrollment
|
||||
|
||||
|
||||
class RunnerTests(unittest.TestCase):
|
||||
def environment(self):
|
||||
return {'CIRCLE_PROJECT_USERNAME': 'QRun-IO', 'CIRCLE_PROJECT_REPONAME': 'qqq-orb',
|
||||
'CIRCLE_BRANCH': 'main', 'GITHUB_TOKEN': 'test-only-secret'}
|
||||
|
||||
def test_wrong_owner_branch_repo_tag_or_missing_auth_cannot_execute(self):
|
||||
for change in ({'CIRCLE_PROJECT_USERNAME': 'other'}, {'CIRCLE_PROJECT_REPONAME': 'other'},
|
||||
{'CIRCLE_BRANCH': 'develop'}, {'CIRCLE_TAG': 'v1.0.0'}, {'GITHUB_TOKEN': ''}):
|
||||
execute = Mock()
|
||||
with self.subTest(change=change), self.assertRaises(ValueError):
|
||||
run_enrollment.run({**self.environment(), **change}, execute)
|
||||
execute.assert_not_called()
|
||||
|
||||
def test_timeout_retains_partial_report_without_secrets(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
def execute(args, **kwargs):
|
||||
output = Path(args[args.index('--output') + 1])
|
||||
output.write_text('[{"state":"unresolved"}]')
|
||||
self.assertEqual(1200, kwargs['timeout'])
|
||||
self.assertEqual('test-only-secret', kwargs['env']['GH_TOKEN'])
|
||||
raise subprocess.TimeoutExpired(args, 1200)
|
||||
self.assertEqual(124, run_enrollment.run(self.environment(), execute, directory))
|
||||
output = Path(directory) / 'artifacts/enrollment'
|
||||
self.assertEqual([{'state': 'unresolved'}], json.loads((output / 'result.json').read_text()))
|
||||
self.assertEqual('timed-out', json.loads((output / 'run.json').read_text())['state'])
|
||||
self.assertNotIn('test-only-secret', (output / 'run.json').read_text())
|
||||
|
||||
def test_failed_pass_propagates_nonzero_exit(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
self.assertEqual(2, run_enrollment.run(self.environment(), Mock(return_value=Mock(returncode=2)), directory))
|
||||
self.assertEqual('failed', json.loads((Path(directory) / 'artifacts/enrollment/run.json').read_text())['state'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -3,7 +3,6 @@ import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
@@ -16,38 +15,6 @@ spec.loader.exec_module(migration)
|
||||
|
||||
|
||||
class MigrationTests(unittest.TestCase):
|
||||
def test_hotfix_and_integration_exclusion_preserves_main_tests_and_publications(self):
|
||||
pattern = "/(develop|release/.*|hotfix/.*|integration.*)/"
|
||||
config = self.config(filters={"branches": {"ignore": pattern}, "tags": {"only": []}})
|
||||
for kind, branch in (("snapshot", "develop"), ("release_candidate", r"/release\/.*/"), ("hotfix", r"/hotfix\/.*/")):
|
||||
config["workflows"][kind] = {"jobs": [{"qqq-orb/mvn_publish": {
|
||||
"branch_type": kind, "filters": {"branches": {"only": [branch]}}}}]}
|
||||
config["workflows"]["release"] = {"jobs": [{"qqq-orb/mvn_publish": {
|
||||
"branch_type": "release", "filters": {"branches": {"ignore": "/.*/"},
|
||||
"tags": {"only": [r"/^v\d+\.\d+\.\d+$/"]}}}}]}
|
||||
manifest = migration.infer_manifest(config, "0.8", "develop")
|
||||
self.assertEqual("non-release-no-hotfix-integration", manifest["test_branch_policy"])
|
||||
self.assertFalse(manifest["release_on_main"])
|
||||
self.assertEqual("stable", manifest["release_tag_policy"])
|
||||
self.assertTrue(all(manifest["publish"][kind] for kind in ("snapshot", "release_candidate", "release", "hotfix")))
|
||||
spec = importlib.util.spec_from_file_location("filter_pipeline", Path(__file__).resolve().parents[1] / "src/scripts/generate_pipeline.py")
|
||||
pipeline = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(pipeline)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "manifest.yml"
|
||||
path.write_text(yaml.safe_dump(manifest), encoding="utf-8")
|
||||
loaded = pipeline.load_manifest(path, "0.8")
|
||||
with mock.patch.object(pipeline, "proven_ci_maintenance", return_value=False), mock.patch.object(pipeline, "proven_docs_only", return_value=False), mock.patch.object(pipeline, "git", return_value=b"qualified-head\n"):
|
||||
for branch, tag, kind in (("main", "", None), ("feature/test", "", None),
|
||||
("integration-test", "", None), ("develop", "", "snapshot"),
|
||||
("release/1.0", "", "release_candidate"), ("hotfix/1.0.1", "", "hotfix"),
|
||||
("", "v1.0.0", "release")):
|
||||
result = pipeline.qbit_template(loaded, branch, tag)
|
||||
options = next(iter(next(iter(result["workflows"].values()))["jobs"][0].values()))
|
||||
self.assertEqual(kind, options.get("branch_type"))
|
||||
if kind is None:
|
||||
self.assertEqual(["automation/qbit-rc-pending", pattern], options["filters"]["branches"]["ignore"])
|
||||
|
||||
def test_630_original_filter_intersections_equal_generated_publications(self):
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"publication_pipeline", Path(__file__).resolve().parents[1] / "src/scripts/generate_pipeline.py")
|
||||
|
||||
+21
-49
@@ -14,28 +14,7 @@ spec = importlib.util.spec_from_file_location('standard', ROOT / 'src/scripts/va
|
||||
standard = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(standard)
|
||||
DESIRED = [{'context': name, 'app_id': 18001} for name in ('setup', 'verify')]
|
||||
PROFILE_GATES = {profile: 'verify' for profile in (
|
||||
'qbit', 'core', 'frontend-core', 'frontend-material', 'repository-policy', 'node-artifact')}
|
||||
PROFILE_GATES.update({'all': 'verify-and-smoke', 'cli': 'test_only',
|
||||
'app-starter': 'test_only', 'android': 'test-and-build',
|
||||
'mcp-policy': 'validate'})
|
||||
PROFILES = set(PROFILE_GATES) | {'frontend-next'}
|
||||
_native_spec = importlib.util.spec_from_file_location('native_next_gates', ROOT / 'tools/native_next_gates.py')
|
||||
native = importlib.util.module_from_spec(_native_spec)
|
||||
_native_spec.loader.exec_module(native)
|
||||
|
||||
|
||||
def gates(profile):
|
||||
if profile == 'frontend-next':
|
||||
return native.gates(pull_request=True)
|
||||
return [{'context': name, 'app_id': 18001}
|
||||
for name in ('setup', PROFILE_GATES[profile])]
|
||||
|
||||
|
||||
def same_checks(left, right):
|
||||
"""GitHub may reorder checks; retain exact bindings and duplicate counts."""
|
||||
return sorted(json.dumps(check, sort_keys=True) for check in left) == sorted(
|
||||
json.dumps(check, sort_keys=True) for check in right)
|
||||
PROFILES = {'qbit', 'core', 'frontend-core', 'frontend-material', 'repository-policy'}
|
||||
|
||||
|
||||
def api(path, method='GET', payload=None):
|
||||
@@ -56,17 +35,17 @@ def api(path, method='GET', payload=None):
|
||||
return json.loads(result.stdout) if result.stdout.strip() else None
|
||||
|
||||
|
||||
def required_checks(before, runs, desired_gates=DESIRED, observed_gates=None):
|
||||
"""Require successful event-appropriate gates and preserve every PR requirement."""
|
||||
for desired in (desired_gates if observed_gates is None else observed_gates):
|
||||
def required_checks(before, runs):
|
||||
"""Append app-bound gates only after both succeeded; preserve all other gates."""
|
||||
for desired in DESIRED:
|
||||
matches = [run for run in runs if run['name'] == desired['context'] and run['app']['id'] == desired['app_id']]
|
||||
if not matches or max(matches, key=lambda run: run['id'])['conclusion'] != 'success':
|
||||
raise ValueError('Current branch head has no successful app-bound gate: ' + desired['context'])
|
||||
raise ValueError('Current branch head has no successful CircleCI ' + desired['context'])
|
||||
prior = (before or {}).get('required_status_checks') or {}
|
||||
checks = [dict(check) for check in prior.get('checks', [])]
|
||||
represented = {check['context'] for check in checks}
|
||||
checks += [{'context': name, 'app_id': -1} for name in prior.get('contexts', []) if name not in represented]
|
||||
for desired in desired_gates:
|
||||
for desired in DESIRED:
|
||||
matches = [check for check in checks if check['context'] == desired['context']]
|
||||
if any(check.get('app_id') not in (None, -1, desired['app_id']) for check in matches):
|
||||
raise ValueError('Existing gate uses a different app: ' + desired['context'])
|
||||
@@ -75,7 +54,7 @@ def required_checks(before, runs, desired_gates=DESIRED, observed_gates=None):
|
||||
return {'strict': True, 'checks': checks}
|
||||
|
||||
|
||||
def verified_rulesets(repo, effective, request=api, desired_gates=DESIRED):
|
||||
def verified_rulesets(repo, effective, request=api):
|
||||
"""Recognize active repository rulesets with bound gates and no bypass actors."""
|
||||
selected = [rule for rule in effective if rule['type'] == 'required_status_checks']
|
||||
if not selected or any(rule.get('ruleset_source_type') != 'Repository'
|
||||
@@ -91,7 +70,7 @@ def verified_rulesets(repo, effective, request=api, desired_gates=DESIRED):
|
||||
records.append(record)
|
||||
requirements = [rule['parameters'] for record in records for rule in record['rules']
|
||||
if rule['type'] == 'required_status_checks']
|
||||
for desired in desired_gates:
|
||||
for desired in DESIRED:
|
||||
if not any(check['context'] == desired['context'] and check.get('integration_id') == desired['app_id']
|
||||
for parameters in requirements for check in parameters['required_status_checks']):
|
||||
raise ValueError('Ruleset is missing app-bound gate: ' + desired['context'])
|
||||
@@ -117,16 +96,10 @@ def inspect(repo, branch, version, request=api):
|
||||
raise ValueError('Canonical declarations must be regular files')
|
||||
source.append(base64.b64decode(item['content'], validate=False).decode('utf-8'))
|
||||
standard.validate(*source, version)
|
||||
profile = standard.load_yaml(source[1])['profile']
|
||||
if profile not in PROFILES:
|
||||
raise ValueError('Profile has no supported shared branch gates')
|
||||
desired_gates = gates(profile)
|
||||
observed_gates = desired_gates
|
||||
if profile == 'frontend-next':
|
||||
native.validate(repo, head, branch, request, standard.load_yaml)
|
||||
observed_gates = native.gates()
|
||||
if standard.load_yaml(source[1])['profile'] not in PROFILES:
|
||||
raise ValueError('Profile does not use the shared setup/verify gate pair')
|
||||
rules = request(root + '/rules/branches/' + branch)
|
||||
rulesets, ruleset_strict = verified_rulesets(repo, rules, request, desired_gates) if rules else ([], False)
|
||||
rulesets, ruleset_strict = verified_rulesets(repo, rules, request) if rules else ([], False)
|
||||
before = request(prefix + '/protection')
|
||||
restrictions = (before or {}).get('restrictions')
|
||||
use_ruleset = (not rulesets and restrictions is not None
|
||||
@@ -140,33 +113,32 @@ def inspect(repo, branch, version, request=api):
|
||||
if len(batch) < 100:
|
||||
break
|
||||
page += 1
|
||||
desired = required_checks(before, runs, desired_gates, observed_gates)
|
||||
desired = required_checks(before, runs)
|
||||
if use_ruleset:
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before, 'gates': desired_gates,
|
||||
'required_status_checks': {'strict': False, 'checks': desired_gates},
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before,
|
||||
'required_status_checks': {'strict': False, 'checks': DESIRED},
|
||||
'changed': True, 'protection_mode': 'create-ruleset'}
|
||||
if rulesets:
|
||||
desired['strict'] = ruleset_strict or bool(((before or {}).get('required_status_checks') or {}).get('strict'))
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before, 'gates': desired_gates,
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before,
|
||||
'required_status_checks': desired, 'changed': False, 'protection_mode': 'rulesets',
|
||||
'effective_rules': rules, 'rulesets': rulesets}
|
||||
current = (before or {}).get('required_status_checks') or {}
|
||||
ready = (current.get('strict') is True and same_checks(current.get('checks', []), desired['checks'])
|
||||
ready = (current.get('strict') is True and current.get('checks') == desired['checks']
|
||||
and (before or {}).get('enforce_admins', {}).get('enabled') is True)
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before, 'gates': desired_gates,
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before,
|
||||
'required_status_checks': desired, 'changed': not ready}
|
||||
|
||||
|
||||
def enforce(plan, request=api):
|
||||
"""Recheck drift, use narrow updates, and verify preservation of other settings."""
|
||||
desired_gates = plan.get('gates', DESIRED)
|
||||
root = 'repos/' + plan['repository']
|
||||
prefix = root + '/branches/' + plan['branch']
|
||||
if request(prefix)['commit']['sha'] != plan['head'] or request(prefix + '/protection') != plan['before']:
|
||||
raise ValueError('Branch or protection changed after preflight')
|
||||
rules = request(root + '/rules/branches/' + plan['branch'])
|
||||
if plan.get('protection_mode') == 'rulesets':
|
||||
if rules != plan['effective_rules'] or verified_rulesets(plan['repository'], rules, request, desired_gates)[0] != plan['rulesets']:
|
||||
if rules != plan['effective_rules'] or verified_rulesets(plan['repository'], rules, request)[0] != plan['rulesets']:
|
||||
raise ValueError('Ruleset changed after preflight')
|
||||
return
|
||||
if rules:
|
||||
@@ -187,9 +159,9 @@ def enforce(plan, request=api):
|
||||
'rules': [{'type': 'required_status_checks', 'parameters': {
|
||||
'strict_required_status_checks_policy': False, 'do_not_enforce_on_create': False,
|
||||
'required_status_checks': [{'context': gate['context'], 'integration_id': gate['app_id']}
|
||||
for gate in desired_gates]}}]})
|
||||
for gate in DESIRED]}}]})
|
||||
effective = request(root + '/rules/branches/' + plan['branch'])
|
||||
verified_rulesets(plan['repository'], effective, request, desired_gates)
|
||||
verified_rulesets(plan['repository'], effective, request)
|
||||
if request(prefix + '/protection') != plan['before']:
|
||||
raise ValueError('Classic access policy changed during ruleset creation')
|
||||
return
|
||||
@@ -206,7 +178,7 @@ def enforce(plan, request=api):
|
||||
request(prefix + '/protection/enforce_admins', 'POST')
|
||||
after = request(prefix + '/protection')
|
||||
actual = after['required_status_checks']
|
||||
if not actual['strict'] or not same_checks(actual['checks'], plan['required_status_checks']['checks']) or not after['enforce_admins']['enabled']:
|
||||
if not actual['strict'] or actual['checks'] != plan['required_status_checks']['checks'] or not after['enforce_admins']['enabled']:
|
||||
raise ValueError('Protection readback did not match requested gates')
|
||||
if before:
|
||||
for key, value in before.items():
|
||||
|
||||
@@ -5,8 +5,8 @@ import enforce_orb_checks as enforcement
|
||||
import reconcile_enrollment as remote
|
||||
|
||||
|
||||
def qualification(repo, head, profile='qbit'):
|
||||
"""Require profile-specific app-bound gates and every advertised latest check/status."""
|
||||
def qualification(repo, head):
|
||||
"""Require both app-bound orb gates and every advertised latest check/status."""
|
||||
checks, page = [], 1
|
||||
while True:
|
||||
batch = remote.api(f'repos/{repo}/commits/{head}/check-runs?filter=latest&per_page=100&page={page}')['check_runs']
|
||||
@@ -15,9 +15,8 @@ def qualification(repo, head, profile='qbit'):
|
||||
break
|
||||
page += 1
|
||||
reasons = []
|
||||
for gate in enforcement.gates(profile):
|
||||
name = gate['context']
|
||||
found = [check for check in checks if check['name'] == name and check['app']['id'] == gate['app_id']]
|
||||
for name in ('setup', 'verify'):
|
||||
found = [check for check in checks if check['name'] == name and check['app']['id'] == 18001]
|
||||
if not found or max(found, key=lambda check: check['id'])['conclusion'] != 'success':
|
||||
reasons.append(name)
|
||||
for check in checks:
|
||||
@@ -50,9 +49,7 @@ def merge_ready(plan, result):
|
||||
if pr['state'] != 'MERGED':
|
||||
if pr['baseRefOid'] != plan['head'] or remote.api(f'repos/{repo}/branches/{plan["branch"]}')['commit']['sha'] != plan['head']:
|
||||
return {'state': 'stale-base', 'url': result['url']}
|
||||
if plan['profile'] == 'frontend-next':
|
||||
enforcement.native.validate(repo, head, plan['branch'], remote.api, enforcement.standard.load_yaml)
|
||||
pending = qualification(repo, head, plan['profile'])
|
||||
pending = qualification(repo, head)
|
||||
if pending:
|
||||
return {'state': 'waiting-checks', 'checks': pending, 'url': result['url']}
|
||||
remote.command(['gh', 'pr', 'merge', str(pr['number']), '--repo', repo, '--squash', '--match-head-commit', head])
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Ubuntu Jammy ships gh 2.4, which lacks API --slurp and modern merge guards.
|
||||
# Pin the official amd64 release and its GitHub release asset SHA-256.
|
||||
version=2.103.0
|
||||
checksum=fdd768eb70f6409f80fcfa9f3a1c0adf0fc98d827ab3ce0bed2ac22762c5d786
|
||||
archive=$(mktemp)
|
||||
binary=$(mktemp)
|
||||
trap 'rm -f "$archive" "$binary"' EXIT
|
||||
curl --fail --silent --show-error --location --retry 3 \
|
||||
"https://github.com/cli/cli/releases/download/v${version}/gh_${version}_linux_amd64.tar.gz" -o "$archive"
|
||||
printf '%s %s\n' "$checksum" "$archive" | sha256sum --check --status
|
||||
tar -xOzf "$archive" "gh_${version}_linux_amd64/bin/gh" > "$binary"
|
||||
sudo install -m 0755 "$binary" /usr/local/bin/gh
|
||||
gh --version
|
||||
gh api --help | grep -q -- --slurp
|
||||
gh pr merge --help | grep -q -- --match-head-commit
|
||||
@@ -1,51 +0,0 @@
|
||||
"""Validate the canonical native bridge and its immutable shared worker contract."""
|
||||
import base64
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
spec = importlib.util.spec_from_file_location('next_bridge', ROOT / 'src/scripts/generate_next_workflow.py')
|
||||
bridge = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(bridge)
|
||||
MAIN_GATES = [
|
||||
'ci / Typecheck, lint, unit tests and coverage',
|
||||
'ci / Mocked e2e (Playwright, chromium)',
|
||||
'ci / Collaboration e2e (MSW; chromium, firefox, webkit, mobile, tablet)',
|
||||
'ci / Bundle budget (static export)', 'ci / Storybook build',
|
||||
'acceptance / acceptance gate',
|
||||
]
|
||||
PR_GATES = MAIN_GATES + ['dashboard-image / build (amd64, ubuntu-24.04)',
|
||||
'dashboard-image / build (arm64, ubuntu-24.04-arm)']
|
||||
|
||||
|
||||
def gates(pull_request=False):
|
||||
return [{'context': name, 'app_id': 15368} for name in (PR_GATES if pull_request else MAIN_GATES)]
|
||||
|
||||
|
||||
def validate(repo, head, branch, request, load_yaml):
|
||||
"""Only main has a push trigger; require exact caller and reviewed worker bytes."""
|
||||
if branch != 'main':
|
||||
raise ValueError('Next native branch verification supports main only')
|
||||
|
||||
def content(owner, path, ref):
|
||||
item = request(f'repos/{owner}/contents/{path}?ref={ref}')
|
||||
if item.get('type') != 'file' or item.get('encoding') != 'base64':
|
||||
raise ValueError('Native workflow must be a regular file')
|
||||
return base64.b64decode(item['content']).decode('utf-8').replace('\r\n', '\n')
|
||||
|
||||
caller = load_yaml(content(repo, '.github/workflows/ci.yml', head))
|
||||
try:
|
||||
pin = caller['jobs']['ci']['uses'].rsplit('@', 1)[1]
|
||||
expected = bridge.canonical_next(pin)
|
||||
except (KeyError, TypeError, IndexError, ValueError):
|
||||
raise ValueError('Native caller has no valid immutable worker pin') from None
|
||||
if caller != expected:
|
||||
raise ValueError('Native caller differs from the canonical shared bridge')
|
||||
commit = request('repos/QRun-IO/qqq-orb/commits/' + pin)
|
||||
if not commit['commit']['verification']['verified']:
|
||||
raise ValueError('Shared native worker commit is not verified')
|
||||
for name in ('next-ci.yml', 'next-acceptance.yml', 'next-dashboard-image.yml'):
|
||||
path = '.github/workflows/' + name
|
||||
if content('QRun-IO/qqq-orb', path, pin) != (ROOT / path).read_text(encoding='utf-8'):
|
||||
raise ValueError('Pinned native worker differs from the supported contract: ' + name)
|
||||
return pin
|
||||
@@ -50,50 +50,6 @@ def content(repo, path, head):
|
||||
return base64.b64decode(item['content'])
|
||||
|
||||
|
||||
def mutation(path, payload):
|
||||
"""Use the existing gh identity; never print credentials or response bodies."""
|
||||
result = subprocess.run(['gh', 'api', path, '--method', 'POST', '--input', '-'],
|
||||
input=json.dumps(payload), capture_output=True,
|
||||
text=True, encoding='utf-8', timeout=60)
|
||||
if result.returncode:
|
||||
raise ValueError('GitHub mutation failed; inspect remote state before retrying')
|
||||
try:
|
||||
data = json.loads(result.stdout)
|
||||
except ValueError:
|
||||
raise ValueError('Invalid GitHub mutation response') from None
|
||||
if not isinstance(data, dict) or data.get('errors'):
|
||||
raise ValueError('GitHub mutation did not succeed')
|
||||
return data
|
||||
|
||||
|
||||
def signed_api_commit(plan, ref):
|
||||
"""Resume a base-only branch; append atomically without local Git/SSH keys."""
|
||||
repo, branch, base = plan['repository'], plan['automation_branch'], plan['head']
|
||||
if ref is None:
|
||||
mutation(f'repos/{repo}/git/refs', {'ref': 'refs/heads/' + branch, 'sha': base})
|
||||
elif ref['object']['sha'] != base:
|
||||
return ref['object']['sha']
|
||||
if api(f'repos/{repo}/branches/{plan["branch"]}')['commit']['sha'] != base:
|
||||
raise ValueError('Target branch moved before submission')
|
||||
additions = [{'path': path, 'contents': base64.b64encode(plan['replacements'][path]).decode('ascii')}
|
||||
for path in PATHS if plan['originals'][path] != plan['replacements'][path]]
|
||||
result = mutation('graphql', {
|
||||
'query': 'mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid } } }',
|
||||
'variables': {'input': {
|
||||
'branch': {'repositoryNameWithOwner': repo, 'branchName': branch},
|
||||
'expectedHeadOid': base,
|
||||
'message': {'headline': 'ci: enroll in the shared QQQ orb',
|
||||
'body': 'Co-Authored-By: Codex <noreply@openai.com>'},
|
||||
'fileChanges': {'additions': additions}}}})
|
||||
try:
|
||||
head = result['data']['createCommitOnBranch']['commit']['oid']
|
||||
except (KeyError, TypeError):
|
||||
raise ValueError('GitHub commit response is incomplete') from None
|
||||
if not isinstance(head, str) or not re.fullmatch(r'[0-9a-f]{40}', head):
|
||||
raise ValueError('GitHub commit response has no valid SHA')
|
||||
return head
|
||||
|
||||
|
||||
def inspect(target, version):
|
||||
"""Resolve observed repository identity and reuse the shared enrollment planner."""
|
||||
if not isinstance(target, dict) or set(target) != {'repository', 'branch'}:
|
||||
@@ -147,7 +103,29 @@ def apply(plan):
|
||||
if api(f'repos/{repo}/branches/{plan["branch"]}')['commit']['sha'] != plan['head']:
|
||||
raise ValueError('Target branch changed after preflight')
|
||||
ref = api(f'repos/{repo}/git/ref/heads/{branch}', missing=True)
|
||||
head = signed_api_commit(plan, ref)
|
||||
if ref is None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory) / 'checkout'
|
||||
command(['git', 'clone', '-c', 'core.autocrlf=false', '--depth', '1', '--single-branch', '--branch', plan['branch'],
|
||||
f'git@github.com:{repo}.git', str(root)])
|
||||
if command(['git', 'rev-parse', 'HEAD'], root) != plan['head']:
|
||||
raise ValueError('Target branch moved before checkout')
|
||||
for path in PATHS:
|
||||
target = enroll_consumers.declaration(root, path)
|
||||
current = target.read_bytes() if target.exists() else None
|
||||
if current != plan['originals'][path]:
|
||||
raise ValueError('Checkout differs from immutable preflight')
|
||||
target.write_bytes(plan['replacements'][path])
|
||||
command(['git', 'add', '--', *PATHS], root)
|
||||
command(['git', 'diff', '--cached', '--check'], root)
|
||||
command(['git', 'commit', '-S', '-m', 'ci: enroll in the shared QQQ orb', '-m',
|
||||
'Co-Authored-By: Codex <noreply@openai.com>'], root)
|
||||
head = command(['git', 'rev-parse', 'HEAD'], root)
|
||||
if api(f'repos/{repo}/branches/{plan["branch"]}')['commit']['sha'] != plan['head']:
|
||||
raise ValueError('Target branch moved before submission')
|
||||
command(['git', 'push', 'origin', f'HEAD:refs/heads/{branch}'], root)
|
||||
else:
|
||||
head = ref['object']['sha']
|
||||
verify_submission(plan, head)
|
||||
pulls = api(f'repos/{repo}/pulls?state=all&head={repo.split("/")[0]}:{branch}&base={plan["branch"]}')
|
||||
if pulls:
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""One bounded central reconciliation pass; no executor polling for PR checks."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def run(environment=None, execute=subprocess.run, root=None):
|
||||
env = dict(os.environ if environment is None else environment)
|
||||
if (env.get('CIRCLE_PROJECT_USERNAME') != 'QRun-IO'
|
||||
or env.get('CIRCLE_PROJECT_REPONAME') != 'qqq-orb'
|
||||
or env.get('CIRCLE_BRANCH') != 'main' or env.get('CIRCLE_TAG')):
|
||||
raise ValueError('Reconciliation requires the orb main branch')
|
||||
token = env.get('GH_TOKEN') or env.get('GITHUB_TOKEN')
|
||||
if not token:
|
||||
raise ValueError('Existing GitHub authentication is required')
|
||||
env['GH_TOKEN'] = token
|
||||
root = Path(root) if root else Path(__file__).resolve().parents[1]
|
||||
output = root / 'artifacts/enrollment'
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
args = [sys.executable, str(root / 'tools/reconcile_enrollment.py'),
|
||||
'--organization', 'QRun-IO', '--orb-version', '0.8',
|
||||
'--output', str(output / 'result.json'), '--apply', '--merge-ready', '--enforce']
|
||||
try:
|
||||
result = execute(args, cwd=root, env=env, timeout=1200, check=False)
|
||||
code = result.returncode
|
||||
state = 'completed' if code == 0 else 'failed'
|
||||
except subprocess.TimeoutExpired:
|
||||
code, state = 124, 'timed-out'
|
||||
(output / 'run.json').write_text(json.dumps({'state': state, 'exit_code': code,
|
||||
'report_available': (output / 'result.json').exists(),
|
||||
'note': 'Completion of a pass does not prove all repositories conform; inspect unresolved and waiting entries.'}, indent=2), encoding='utf-8')
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(run())
|
||||
@@ -91,7 +91,6 @@ def test_filters(filters):
|
||||
"/(develop|main|release/.*|integration.*)/": "feature",
|
||||
"/(develop|main|release/.*)/": "non-release-no-main",
|
||||
"/(develop|release/.*|hotfix/.*)/": "non-release-no-hotfix",
|
||||
"/(develop|release/.*|hotfix/.*|integration.*)/": "non-release-no-hotfix-integration",
|
||||
"/(develop|main|release/.*|hotfix/.*)/": "non-release-no-main-hotfix",
|
||||
"/(develop|main|release/.*|hotfix/.*|integration.*)/": "feature-no-hotfix",
|
||||
}.get(pattern.replace(r"\/", "/"))
|
||||
|
||||
Reference in new issue
Block a user