Compare commits

..
Author SHA1 Message Date
james.maesandCodex 8c0530ee74 fix: reject empty ref responses across jq versions
Co-Authored-By: Codex <noreply@openai.com>
2026-10-21 02:13:02 -05:00
james.maesandCodex 225186356a fix: distinguish missing rc refs from github error bodies
Co-Authored-By: Codex <noreply@openai.com>
2026-10-21 02:09:46 -05:00
23 changed files with 53 additions and 2386 deletions

No files matched your search

-2
View File
@@ -49,13 +49,11 @@ jobs:
python3 tests/test_cli_ci_contract.py
python3 tests/test_maven_ci_contract.py
python3 tests/test_standardize_qbit.py
python3 tests/test_qbit_hotfix_profile.py
python3 tests/test_rollout_version.py
python3 tests/test_validate_standard.py
python3 tests/test_voyage_profile.py
python3 tests/test_next_native.py
python3 tests/test_auxiliary_workflows.py
python3 tests/test_qbit_codeql.py
python3 tests/test_intellij_plugin.py
python3 tests/test_workflow_lint.py
python3 tests/test_business_e2e.py
-58
View File
@@ -1,58 +0,0 @@
name: QBit CodeQL
'on':
workflow_call:
permissions:
contents: read
actions: read
security-events: write
packages: read
jobs:
analyze:
name: Analyze branch source
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Select languages present in this checkout
id: languages
run: |
python3 <<'PY'
import os
from pathlib import PurePosixPath
import subprocess
import sys
files = subprocess.check_output(['git', 'ls-files', '-z']).decode('utf-8').split('\0')
extensions = {PurePosixPath(name).suffix.lower() for name in files if name}
languages = []
if extensions & {'.java', '.kt', '.kts'}:
languages.append('java-kotlin')
if extensions & {'.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'}:
languages.append('javascript-typescript')
if '.py' in extensions:
languages.append('python')
if any((name.startswith('.github/workflows/') and PurePosixPath(name).suffix in {'.yml', '.yaml'})
or PurePosixPath(name).name in {'action.yml', 'action.yaml'} for name in files if name):
languages.append('actions')
if not languages:
sys.exit('No supported source in this branch; classify placeholders before enabling QBit scanning')
build_mode = 'autobuild' if extensions & {'.kt', '.kts'} else 'none'
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as output:
output.write('languages=' + ','.join(languages) + '\n')
output.write('build-mode=' + build_mode + '\n')
PY
- uses: actions/setup-java@v4
if: steps.languages.outputs.build-mode == 'autobuild'
with:
distribution: temurin
java-version: '21'
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ steps.languages.outputs.languages }}
build-mode: ${{ steps.languages.outputs.build-mode }}
- name: Build Kotlin sources
if: steps.languages.outputs.build-mode == 'autobuild'
uses: github/codeql-action/autobuild@v4
- name: Analyze source
uses: github/codeql-action/analyze@v4
+5 -5
View File
@@ -135,7 +135,7 @@ jobs:
echo "merge_sha=$merge_sha"
echo "merged_at=$merged_at"
} >> "$GITHUB_OUTPUT"
echo "Pushed $branch; the CircleCI publisher cuts the RC." >> "$GITHUB_STEP_SUMMARY"
echo "Pushed $branch; CircleCI publish_release_candidate cuts the RC." >> "$GITHUB_STEP_SUMMARY"
echo "Release line: $branch. Waiting without a runner for qbit-rc-published." >> "$GITHUB_STEP_SUMMARY"
- name: Persist trusted release intent
if: steps.merge.outputs.merge_sha != ''
@@ -203,7 +203,7 @@ jobs:
raise ReleaseFailure("Status response does not identify the exact release merge")
# Circle's workflow Check Run is stable even when job statuses receive -1/-2 suffixes.
publishers = [x for x in status.get("check_runs", [])
if x.get("name") in ("publish_release_candidate", "verify") and x.get("app", {}).get("id") == 18001]
if x.get("name") == "publish_release_candidate" and x.get("app", {}).get("id") == 18001]
if not publishers:
return ""
publisher = max(publishers, key=lambda x: x["id"])
@@ -265,10 +265,10 @@ jobs:
job.get('branch'), str(job.get('build_num'))) != (repo, merge, branch, build):
raise ReleaseFailure('Timeout job does not identify the exact cut')
workflow = job.get('workflows', {})
if workflow.get('workflow_name') not in ('publish_release_candidate', 'verify') or workflow.get('job_name') != 'qqq-orb/mvn_publish':
if workflow.get('workflow_name') != 'publish_release_candidate' or workflow.get('job_name') != 'qqq-orb/mvn_publish':
raise ReleaseFailure('Unexpected Circle publication workflow/job')
if (publisher.get('head_sha') != merge or publisher.get('app', {}).get('id') != 18001
or publisher.get('name') != workflow.get('workflow_name')
or publisher.get('name') != 'publish_release_candidate'
or publisher.get('status') != 'completed' or publisher.get('conclusion') != 'failure'):
raise ReleaseFailure('Recovery requires the failed exact Circle publisher')
from urllib.parse import urlsplit
@@ -335,7 +335,7 @@ jobs:
directory = pathlib.Path(directory)
status = json.loads((directory / 'status.json').read_text())
intent = json.loads((directory / 'intent.json').read_text())
publishers = [p for p in status['check_runs'] if p.get('name') in ('publish_release_candidate', 'verify') and p.get('app', {}).get('id') == 18001]
publishers = [p for p in status['check_runs'] if p.get('name') == 'publish_release_candidate' and p.get('app', {}).get('id') == 18001]
if status.get('sha') != merge or not publishers:
raise ReleaseFailure('Exact publisher evidence missing')
class NoRedirect(urllib.request.HTTPRedirectHandler):
-2
View File
@@ -58,13 +58,11 @@ test-pipelines: pack
bash tests/test_cli_ci_behavior.sh
python3 tests/test_cli_ci_contract.py
python3 tests/test_standardize_qbit.py
python3 tests/test_qbit_hotfix_profile.py
python3 tests/test_rollout_version.py
python3 tests/test_validate_standard.py
python3 tests/test_voyage_profile.py
python3 tests/test_next_native.py
python3 tests/test_auxiliary_workflows.py
python3 tests/test_qbit_codeql.py
python3 tests/test_intellij_plugin.py
python3 tests/test_workflow_lint.py
python3 tests/test_business_e2e.py
-12
View File
@@ -3,18 +3,6 @@
`tools/audit_estate.py` classifies repositories from explicit mappings and observed source.
It never changes consumers, branch rules or publication settings.
Source auditing reads the repository's current default branch unless
`--live --source-branch main` (or an explicit `release/...` or `hotfix/...` branch)
is supplied. Run separate audits for each maintained source branch: a clean
default-branch report does not establish conformity on main or release branches.
The selected branch is resolved to an immutable commit before any files are read.
Reports identify both `source_branch` and the repository's `default_branch`;
the manifest's `default_branch` must still match the repository default.
Unavailable selected branches remain unknown without falling back to default.
Explicit branch selection requires live lookup and cannot relabel an offline SHA.
Required-check policy still controls which branch settings are inspected;
`--source-branch` changes source selection, not that enforcement policy.
- Circle profiles include android, mcp-policy and marketing. Their manifest and canonical
setup caller remain mandatory; a missing configuration is a finding.
- MCP, business-platform and the organization `.github` repository use approved native
+6 -18
View File
@@ -61,23 +61,11 @@ parser is pinned to PyYAML 6.0.3 and uses its safe loader.
| Event | Workflow | Job contract |
| --- | --- | --- |
| develop | verify | existing mvn_publish, snapshot |
| release/* | verify | existing mvn_publish, release_candidate |
| vX.Y.Z tag resolving to the checkout | verify | existing mvn_publish, release |
| main, feature/*, hotfix/*, other/unknown branch | verify | existing mvn_test_only |
| Disabled publication or unrecognized/unproven tag | verify | full verification, no publication |
Generated `qbit`, `core`, `frontend-core`, and `frontend-material` pipelines use
the stable workflow name `verify`. All selected jobs, dependencies and filters
remain intact; this adds no executor or duplicate build. Other profiles retain
their existing workflow names and native checks.
When upgrading from legacy workflow names, upgrade the immutable RC worker pin
alongside the orb so finalization recognizes both names. Confirm the CircleCI
app's successful `verify` check on the exact migration commit before replacing
legacy required contexts. Require `setup` and `verify` on managed branches,
preserving other required checks and controls. Human approval is not required;
automated checks authorize the migration.
| develop | publish_snapshot | existing mvn_publish, snapshot |
| release/* | publish_release_candidate | existing mvn_publish, release_candidate |
| vX.Y.Z tag resolving to the checkout | publish_release | existing mvn_publish, release |
| main, feature/*, hotfix/*, other/unknown branch | test_only | existing mvn_test_only |
| Disabled publication or unrecognized/unproven tag | test_only | full verification, no publication |
The pipeline SHA must match the checkout when Circle supplies it. A tagged release
must resolve to that checkout; missing local tags are fetched individually. A main
@@ -194,7 +182,7 @@ manifest validation already ran in setup. It adds no new security scanner and
makes no security-scanning claim. Keep docs-only disabled if those paths are build
inputs or packaged application content.
The light route keeps workflow `verify` and names its job
The light route keeps workflow `test_only` and names its job
`qqq-orb/mvn_test_only`. Verify actual CircleCI/GitHub status contexts on the canary
before changing any protection rule; workflow/job identity alone is not proof of
the hosted context name. Current protections must not be removed speculatively.
-12
View File
@@ -1,12 +0,0 @@
# Shared QBit source scanning
Generate the thin caller with `python3 src/scripts/generate_auxiliary_workflow.py qbit-codeql --ref <immutable-worker-sha>`.
The reusable worker selects supported languages from tracked files in the actual checked-out branch. Historical Java branches therefore do not request an absent Actions database. Java, JavaScript/TypeScript, Python and Actions share one job; Kotlin selects an actual build instead of silently omitting Kotlin from no-build Java analysis.
The caller scans pull requests, main/develop/release/hotfix pushes and weekly, cancels superseded PR scans, and contains no scan implementation. Set `codeql_worker_sha` in the estate enforcement policy to require the exact canonical caller independently of other native worker pins. Existing default-setup repositories remain unchanged until migrated.
Roll out to both active default and maintained branches. Verify the worker on representative branch contents and preserve existing query coverage before replacing GitHub default setup; do not run duplicate default and advanced scanners permanently. Default setup cannot select languages independently for historical branches. A branch with no supported application or workflow source is a placeholder to classify, not a passing application scan.
Local tests execute the embedded language-selection step against real git indexes, including absent Actions, untracked generated files, mixed source, Kotlin and placeholders. Hosted CodeQL database creation and SARIF upload must also pass before claiming rollout completion.
References: [GitHub setup types](https://docs.github.com/en/code-security/concepts/code-scanning/setup-types) and [CodeQL build modes](https://docs.github.com/en/code-security/reference/code-scanning/codeql/build-options-for-compiled-languages).
+1 -13
View File
@@ -8,16 +8,11 @@ recognized contracts:
|---|---|---|
| `release_on_main` | boolean, default false | Main pushes select the existing release job when release publishing is enabled. |
| `release_tag_policy` | `stable`, `v-prefix`, `none` | Stable `v1.2.3`, the existing broad `/v.*/` contract, or no tags. |
| `test_branch_policy` | `all`, `non-release`, `non-release-no-integration`, `feature`, `non-release-no-main`, `non-release-no-hotfix`, `non-release-no-main-hotfix`, `feature-no-hotfix` | Selects an audited test branch exclusion. |
| `publish.hotfix` | boolean, default false | Runs the existing Maven hotfix publisher for nonempty `hotfix/*` branch events only when explicitly enabled. |
| `test_branch_policy` | `all`, `non-release`, `non-release-no-integration`, `feature`, `non-release-no-main` | Selects one of the five audited test branch exclusions. |
`feature` preserves the original exclusion of develop, main, release branches,
and integration-prefixed branches; it is not a new feature-prefix-only rule.
All policies continue to exclude the RC coordination lock branch.
The three hotfix exclusions preserve the corresponding legacy policies while
the single shared publisher handles hotfix events. Existing manifests do not
enable hotfix publication implicitly; migration enables it only when the source
configuration contains the recognized hotfix publisher and branch filter.
No consumer-supplied regex, command, job, or arbitrary branch-publication rule
is accepted.
@@ -44,10 +39,3 @@ Focused tests cover the immutable inventory, unknown-filter rejection, canonical
caller agreement, main opt-in, broad/stable tag selection, HEAD provenance,
publication opt-out and test exclusions. The packed generator suite also exercises
main, broad RC-shaped tags, and excluded integration branches.
Fifteen additional main-branch fixtures exercise 195 branch/tag cases,
checking both test and publication selection. Source and packed generator tests
also verify hotfix opt-in, its boolean validation, and unchanged main behavior.
CMS's original YAML is retained with its immutable source SHA: its unquoted
stable-tag regex is invalid YAML. The fixture repairs only that quoting. Both
audited spellings of the stable regex map to the same ASCII-digit tag policy;
arbitrary regexes remain rejected.
+1 -12
View File
@@ -26,8 +26,7 @@ https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-t
- Finalization retrieves the unique unexpired intent artifact and verifies its
originating successful `release-rc.yml` run, repository, trigger and attempt.
Callback fields must match that immutable intent.
- The exact merge SHA must have a successful `verify` (or legacy
`publish_release_candidate`) Check Run
- The exact merge SHA must have a successful `publish_release_candidate` Check Run
from CircleCI app ID `18001`; unrelated job statuses cannot authorize release.
Terminal publisher failure stops finalization immediately. Pending/absent publication cannot authorize a tag.
The RC bump must have exactly that one parent and the release branch must still
@@ -108,13 +107,3 @@ is gone, the completed release needs no recovery dispatch. Ordinary callbacks an
scheduled reconciliation retain the requirement for a successful Circle publisher.
Central status API: https://central.sonatype.org/publish/publish-portal-api/
### Auditing independent worker revisions
The estate audit accepts `rc_worker_sha` in a profile or repository policy. For
example, set `profiles.qbit.rc_worker_sha` to the approved immutable RC worker
commit and keep `--worker-sha` at the approved revision for unchanged native
workers. The audit still compares every caller to its exact canonical template
and rejects mutable or mismatched pins. This avoids a fleet-wide native caller
update when only RC release behavior changes. Required-check policy is separate;
omitting it continues to report enforcement as unknown.
+4 -19
View File
@@ -110,8 +110,6 @@ def load_manifest(path, setup_version):
publish_keys = ("release",)
if profile in ("qbit", "core"):
publish_keys += ("asciidoc",)
if profile == "qbit":
publish_keys += ("hotfix",)
if profile not in ("qbit", "cli", "all", "app-starter", "voyage", "frontend-next"):
publish_keys += ("feature", "hotfix")
publishing = mapping(data.get("publish", {}), publish_keys, "publish")
@@ -128,8 +126,7 @@ def load_manifest(path, setup_version):
if tag_policy not in ("stable", "v-prefix", "none"):
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-main-hotfix", "feature-no-hotfix"):
if test_policy not in ("all", "non-release", "non-release-no-integration", "feature", "non-release-no-main"):
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),
@@ -139,8 +136,7 @@ def load_manifest(path, setup_version):
"release_tag_policy": tag_policy, "test_branch_policy": test_policy,
"docs_only": boolean(data, "docs_only", False),
"publish_context": publish_context,
"publish": {key: boolean(publishing, key, key != "asciidoc" and profile not in ("cli", "all")
and not (profile == "qbit" and key == "hotfix"))
"publish": {key: boolean(publishing, key, key != "asciidoc" and profile not in ("cli", "all"))
for key in publish_keys}}
@@ -177,7 +173,7 @@ def proven_docs_only(config, branch, tag):
def event_kind(branch, tag, release_on_main=False, release_tag_policy="stable"):
if tag:
if release_tag_policy == "none" or not re.fullmatch(r"v.*" if release_tag_policy == "v-prefix" else r"v\d+\.\d+\.\d+", tag, flags=re.ASCII):
if release_tag_policy == "none" or not re.fullmatch(r"v.*" if release_tag_policy == "v-prefix" else r"v\d+\.\d+\.\d+", tag):
return "test"
tagged = git("rev-parse", "--verify", f"refs/tags/{tag}^{{commit}}")
if not tagged and git("fetch", "--no-tags", "origin", f"refs/tags/{tag}:refs/tags/{tag}") is not None:
@@ -195,8 +191,6 @@ def event_kind(branch, tag, release_on_main=False, release_tag_policy="stable"):
def qbit_template(config, branch, tag):
"""Profile-owned template; add future profiles as reviewed renderers, not raw YAML."""
kind = event_kind(branch, tag, config.get("release_on_main", False), config.get("release_tag_policy", "stable"))
if not tag and re.fullmatch(r"hotfix/.+", branch) and config["publish"].get("hotfix", False):
kind = "hotfix"
if kind != "test" and not config["publish"][kind]:
kind = "test"
workflow = "test_only" if kind == "test" else "publish_" + kind
@@ -207,10 +201,7 @@ def qbit_template(config, branch, tag):
ignores = {"all": None, "non-release": "/(develop|release/.*)/",
"non-release-no-integration": "/(develop|release/.*|integration.*)/",
"feature": "/(develop|main|release/.*|integration.*)/",
"non-release-no-main": "/(develop|main|release/.*)/",
"non-release-no-hotfix": "/(develop|release/.*|hotfix/.*)/",
"non-release-no-main-hotfix": "/(develop|main|release/.*|hotfix/.*)/",
"feature-no-hotfix": "/(develop|main|release/.*|hotfix/.*|integration.*)/"}
"non-release-no-main": "/(develop|main|release/.*)/"}
ignored = ignores[config.get("test_branch_policy", "all")]
if ignored:
filters["branches"]["ignore"] = ["automation/qbit-rc-pending", ignored]
@@ -450,12 +441,6 @@ def main():
if expected and (not re.fullmatch(r"[0-9a-fA-F]{40}", expected) or git("rev-parse", "HEAD") != (expected + "\n").encode()):
raise ManifestError("Checkout does not match the pipeline commit")
output = PROFILE_TEMPLATES[config["profile"]](config, os.environ.get("CIRCLE_BRANCH", ""), os.environ.get("CIRCLE_TAG", ""))
if config["profile"] in ("qbit", "core", "frontend-core", "frontend-material"):
# One whole-workflow check follows the same commit from feature to release.
# Keep every selected job, dependency and filter; add no runner or duplicate build.
if len(output["workflows"]) != 1:
raise ManifestError("Stable verification requires exactly one selected workflow")
output["workflows"] = {"verify": next(iter(output["workflows"].values()))}
parameters = continuation_parameters(config["profile"])
if config["profile"] == "core":
output["parameters"] = copy.deepcopy(CORE_TEMPLATE["parameters"])
+4 -19
View File
@@ -110,8 +110,6 @@ def load_manifest(path, setup_version):
publish_keys = ("release",)
if profile in ("qbit", "core"):
publish_keys += ("asciidoc",)
if profile == "qbit":
publish_keys += ("hotfix",)
if profile not in ("qbit", "cli", "all", "app-starter", "voyage", "frontend-next"):
publish_keys += ("feature", "hotfix")
publishing = mapping(data.get("publish", {}), publish_keys, "publish")
@@ -128,8 +126,7 @@ def load_manifest(path, setup_version):
if tag_policy not in ("stable", "v-prefix", "none"):
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-main-hotfix", "feature-no-hotfix"):
if test_policy not in ("all", "non-release", "non-release-no-integration", "feature", "non-release-no-main"):
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),
@@ -139,8 +136,7 @@ def load_manifest(path, setup_version):
"release_tag_policy": tag_policy, "test_branch_policy": test_policy,
"docs_only": boolean(data, "docs_only", False),
"publish_context": publish_context,
"publish": {key: boolean(publishing, key, key != "asciidoc" and profile not in ("cli", "all")
and not (profile == "qbit" and key == "hotfix"))
"publish": {key: boolean(publishing, key, key != "asciidoc" and profile not in ("cli", "all"))
for key in publish_keys}}
@@ -177,7 +173,7 @@ def proven_docs_only(config, branch, tag):
def event_kind(branch, tag, release_on_main=False, release_tag_policy="stable"):
if tag:
if release_tag_policy == "none" or not re.fullmatch(r"v.*" if release_tag_policy == "v-prefix" else r"v\d+\.\d+\.\d+", tag, flags=re.ASCII):
if release_tag_policy == "none" or not re.fullmatch(r"v.*" if release_tag_policy == "v-prefix" else r"v\d+\.\d+\.\d+", tag):
return "test"
tagged = git("rev-parse", "--verify", f"refs/tags/{tag}^{{commit}}")
if not tagged and git("fetch", "--no-tags", "origin", f"refs/tags/{tag}:refs/tags/{tag}") is not None:
@@ -195,8 +191,6 @@ def event_kind(branch, tag, release_on_main=False, release_tag_policy="stable"):
def qbit_template(config, branch, tag):
"""Profile-owned template; add future profiles as reviewed renderers, not raw YAML."""
kind = event_kind(branch, tag, config.get("release_on_main", False), config.get("release_tag_policy", "stable"))
if not tag and re.fullmatch(r"hotfix/.+", branch) and config["publish"].get("hotfix", False):
kind = "hotfix"
if kind != "test" and not config["publish"][kind]:
kind = "test"
workflow = "test_only" if kind == "test" else "publish_" + kind
@@ -207,10 +201,7 @@ def qbit_template(config, branch, tag):
ignores = {"all": None, "non-release": "/(develop|release/.*)/",
"non-release-no-integration": "/(develop|release/.*|integration.*)/",
"feature": "/(develop|main|release/.*|integration.*)/",
"non-release-no-main": "/(develop|main|release/.*)/",
"non-release-no-hotfix": "/(develop|release/.*|hotfix/.*)/",
"non-release-no-main-hotfix": "/(develop|main|release/.*|hotfix/.*)/",
"feature-no-hotfix": "/(develop|main|release/.*|hotfix/.*|integration.*)/"}
"non-release-no-main": "/(develop|main|release/.*)/"}
ignored = ignores[config.get("test_branch_policy", "all")]
if ignored:
filters["branches"]["ignore"] = ["automation/qbit-rc-pending", ignored]
@@ -450,12 +441,6 @@ def main():
if expected and (not re.fullmatch(r"[0-9a-fA-F]{40}", expected) or git("rev-parse", "HEAD") != (expected + "\n").encode()):
raise ManifestError("Checkout does not match the pipeline commit")
output = PROFILE_TEMPLATES[config["profile"]](config, os.environ.get("CIRCLE_BRANCH", ""), os.environ.get("CIRCLE_TAG", ""))
if config["profile"] in ("qbit", "core", "frontend-core", "frontend-material"):
# One whole-workflow check follows the same commit from feature to release.
# Keep every selected job, dependency and filter; add no runner or duplicate build.
if len(output["workflows"]) != 1:
raise ManifestError("Stable verification requires exactly one selected workflow")
output["workflows"] = {"verify": next(iter(output["workflows"].values()))}
parameters = continuation_parameters(config["profile"])
if config["profile"] == "core":
output["parameters"] = copy.deepcopy(CORE_TEMPLATE["parameters"])
+1 -1
View File
@@ -116,7 +116,7 @@ def reconcile(api, repo):
validate_run(run, intent, repo, merge, run_id)
checks = api.request(prefix + 'commits/' + merge + '/check-runs?filter=latest&per_page=100')
publishers = [c for c in checks.get('check_runs', [])
if c.get('name') in ('publish_release_candidate', 'verify') and c.get('app', {}).get('id') == 18001]
if c.get('name') == 'publish_release_candidate' and c.get('app', {}).get('id') == 18001]
if not publishers:
return 'publisher-running'
publisher = max(publishers, key=lambda c: c['id'])
+1 -41
View File
@@ -263,7 +263,7 @@
},
"concurrency": {
"group": "e2e-${{ github.ref }}",
"cancel-in-progress": "${{ github.event_name == 'pull_request' }}"
"cancel-in-progress": "${{ github.event_name == 'pull_request' }}"
},
"jobs": {
"validate": {
@@ -427,45 +427,5 @@
}
}
}
},
"qbit-codeql": {
"repository": null,
"profile": "qbit",
"path": ".github/workflows/codeql.yml",
"caller": {
"name": "CodeQL",
"on": {
"push": {
"branches": [
"main",
"develop",
"release/**",
"hotfix/**"
]
},
"pull_request": {},
"schedule": [
{
"cron": "41 16 * * 0"
}
],
"workflow_dispatch": {}
},
"permissions": {
"contents": "read",
"actions": "read",
"security-events": "write",
"packages": "read"
},
"concurrency": {
"group": "codeql-${{ github.event.pull_request.number || github.ref }}",
"cancel-in-progress": "${{ github.event_name == 'pull_request' }}"
},
"jobs": {
"analyze": {
"uses": "QRun-IO/qqq-orb/.github/workflows/qbit-codeql.yml@WORKER_SHA"
}
}
}
}
}
File diff suppressed because it is too large. Load diff
-92
View File
@@ -26,79 +26,6 @@ class Snapshot:
class AuditTests(unittest.TestCase):
def test_qbit_scanner_policy_requires_exact_canonical_worker(self):
entry = dict(ENTRY, name='qbit-help', nameWithOwner='QRun-IO/qbit-help')
manifest = {'profile': 'qbit', 'orb_version': VERSION, 'default_branch': 'develop',
'publish': {'snapshot': False, 'release_candidate': False, 'release': False}}
files = {'.qqq-ci.yml': audit.generator.yaml.safe_dump(manifest),
'.circleci/config.yml': audit.generator.yaml.safe_dump(audit.standard.canonical_caller('qbit', VERSION))}
policy = dict(POLICY, codeql_worker_sha='b' * 40)
report = audit.audit(entry, Snapshot(files), VERSION, SHA, policy)
self.assertTrue(any(f['code'] == 'missing_native_maintenance_bridge' for f in report['findings']))
files['.github/workflows/codeql.yml'] = audit.generator.yaml.safe_dump(audit.auxiliary.canonical('qbit-codeql', 'b' * 40), sort_keys=False)
self.assertEqual([], audit.audit(entry, Snapshot(files), VERSION, SHA, policy)['findings'])
files['.github/workflows/codeql.yml'] = files['.github/workflows/codeql.yml'].replace('b' * 40, 'a' * 40)
report = audit.audit(entry, Snapshot(files), VERSION, SHA, policy)
self.assertTrue(any(f['code'] == 'native_maintenance_bridge_drift' for f in report['findings']))
def test_live_snapshot_reads_requested_branch_and_keeps_default_identity(self):
entry = dict(ENTRY, sourceBranch='release/1.2')
replies = [{'default_branch': 'develop', 'archived': False}, {'sha': SHA},
{'truncated': False, 'tree': []}]
with patch.object(audit, 'gh', side_effect=replies) as gh:
snapshot = audit.Snapshot(entry, live=True)
self.assertEqual('develop', snapshot.default_branch)
self.assertEqual('release/1.2', snapshot.branch)
self.assertEqual('repos/QRun-IO/qctl/commits/release%2F1.2', gh.call_args_list[1].args[0])
def test_other_source_branch_does_not_change_manifest_default_branch(self):
entry = dict(ENTRY, name='qbit-help', nameWithOwner='QRun-IO/qbit-help')
manifest = {'profile': 'qbit', 'orb_version': VERSION, 'default_branch': 'develop',
'publish': {'snapshot': False, 'release_candidate': False, 'release': False}}
files = {'.qqq-ci.yml': audit.generator.yaml.safe_dump(manifest),
'.circleci/config.yml': audit.generator.yaml.safe_dump(audit.standard.canonical_caller('qbit', VERSION))}
snapshot = Snapshot(files)
snapshot.branch = 'main'
snapshot.default_branch = 'develop'
report = audit.audit(entry, snapshot, VERSION, SHA, POLICY)
self.assertEqual([], report['findings'])
self.assertEqual('main', report['source_branch'])
self.assertEqual('develop', report['default_branch'])
def test_selected_branch_read_failure_is_unknown_not_default_fallback(self):
captured = []
def factory(entry, live):
captured.append(entry)
raise audit.ReadError('branch unavailable')
report = audit.run([ENTRY], VERSION, SHA, {}, live=True,
snapshot_factory=factory, source_branch='main')
self.assertEqual('main', captured[0]['sourceBranch'])
self.assertEqual('unknown', report['results'][0]['status'])
self.assertEqual('main', report['results'][0]['source_branch'])
self.assertNotIn('sourceBranch', ENTRY)
def test_omitted_source_branch_still_reads_repository_default(self):
replies = [{'default_branch': 'develop', 'archived': False}, {'sha': SHA},
{'truncated': False, 'tree': []}]
with patch.object(audit, 'gh', side_effect=replies) as gh:
snapshot = audit.Snapshot(ENTRY, live=True)
self.assertEqual('develop', snapshot.branch)
self.assertEqual('develop', snapshot.default_branch)
self.assertEqual('repos/QRun-IO/qctl/commits/develop', gh.call_args_list[1].args[0])
def test_explicit_source_branch_cannot_relabel_offline_snapshot(self):
with self.assertRaises(ValueError):
audit.run([ENTRY], VERSION, SHA, {}, source_branch='main')
with self.assertRaises(audit.ReadError):
audit.Snapshot(dict(ENTRY, sourceBranch='main'), live=False)
def test_invalid_source_branch_is_rejected_before_api_calls(self):
for branch in ('', 'main?ref=develop', 'main\n', 123):
with self.subTest(branch=branch), patch.object(audit, 'gh') as gh:
with self.assertRaises(audit.ReadError):
audit.Snapshot(dict(ENTRY, sourceBranch=branch), live=True)
gh.assert_not_called()
def native(self, files=None, checks=None, policy=POLICY):
files = files if files is not None else {'.github/workflows/build.yml': audit.qctl.generate(SHA)}
return audit.audit(ENTRY, Snapshot(files, checks), VERSION, SHA, policy)
@@ -147,25 +74,6 @@ class AuditTests(unittest.TestCase):
report = audit.audit(entry, Snapshot({'.qqq-ci.yml': audit.generator.yaml.safe_dump(manifest)}), VERSION, SHA, POLICY)
self.assertIn('missing_rc_bridge', [f['code'] for f in report['findings']])
def test_rc_pin_policy_does_not_force_unchanged_auxiliary_worker_updates(self):
entry = dict(ENTRY, name='qbit-authentik', nameWithOwner='QRun-IO/qbit-authentik')
rc_sha = 'b' * 40
definition = audit.auxiliary.BRIDGES['qbit-schema-drift']
manifest = {'profile': 'qbit', 'orb_version': VERSION, 'default_branch': 'develop', 'release_completion': True}
files = {audit.rc_worker.CALLER_PATH: audit.rc_worker.generate(rc_sha),
definition['path']: audit.generator.yaml.safe_dump(audit.auxiliary.canonical('qbit-schema-drift', SHA), sort_keys=False),
'.qqq-ci.yml': audit.generator.yaml.safe_dump(manifest),
'.circleci/config.yml': audit.generator.yaml.safe_dump(audit.standard.canonical_caller('qbit', VERSION))}
policy = dict(POLICY, rc_worker_sha=rc_sha)
self.assertEqual('pass', audit.audit(entry, Snapshot(files), VERSION, SHA, policy)['status'])
for pin in (SHA, 'main', ''):
with self.subTest(pin=pin):
report = audit.audit(entry, Snapshot(files), VERSION, SHA, dict(POLICY, rc_worker_sha=pin))
self.assertTrue(report['findings'])
files[definition['path']] = files[definition['path']].replace(SHA, rc_sha)
report = audit.audit(entry, Snapshot(files), VERSION, SHA, policy)
self.assertIn('native_maintenance_bridge_drift', [f['code'] for f in report['findings']])
def test_qbit_rc_bridge_missing_drift_pin_and_duplicate(self):
entry = dict(ENTRY, name='qbit-test', nameWithOwner='QRun-IO/qbit-test')
path = audit.rc_worker.CALLER_PATH
+13 -36
View File
@@ -192,12 +192,10 @@ class PipelineTests(unittest.TestCase):
return result
def assert_full(self, result, workflow="test_only"):
self.assertEqual(list(result["workflows"]), ["verify"])
self.assertEqual(list(result["workflows"]), [workflow])
self.assertNotIn("docs_only", result.get("jobs", {}))
job, options = next(iter(result["workflows"]["verify"]["jobs"][0].items()))
job, options = next(iter(result["workflows"][workflow]["jobs"][0].items()))
self.assertEqual(job, "qqq-orb/mvn_test_only" if workflow == "test_only" else "qqq-orb/mvn_publish")
if workflow != "test_only":
self.assertEqual(options["branch_type"], workflow.removeprefix("publish_"))
self.assertEqual(options["context"], ["qqq-maven-registry-credentials"])
self.assertFalse(options["compile_before_verify"])
return options
@@ -227,24 +225,6 @@ class PipelineTests(unittest.TestCase):
self.write_manifest(publish={"asciidoc": True})
self.assertTrue(self.assert_full(self.render(CIRCLE_BRANCH="develop"), "publish_snapshot")["publish_asciidoc"])
def test_qbit_hotfix_is_opt_in_in_source_and_packed_generator(self):
for packed in ([False, True] if PACKED else [False]):
self.write_manifest()
self.assert_full(self.render(packed=packed, CIRCLE_BRANCH="hotfix/1.2.3"))
self.write_manifest(publish={"hotfix": True})
options = self.assert_full(self.render(packed=packed, CIRCLE_BRANCH="hotfix/1.2.3"), "publish_hotfix")
self.assertNotIn("notify_rc_published", options)
self.assert_full(self.render(packed=packed, CIRCLE_BRANCH="main"))
self.assert_full(self.render(packed=packed, CIRCLE_BRANCH="hotfix/"))
self.write_manifest(publish={"hotfix": "true"})
self.render(packed=packed, CIRCLE_BRANCH="hotfix/1.2.3", ok=False)
def test_stable_tags_require_ascii_digits_in_source_and_packed_generator(self):
tag = "v\u0661.\u0662.\u0663"
self.git("tag", tag)
for packed in ([False, True] if PACKED else [False]):
self.assert_full(self.render(packed=packed, CIRCLE_TAG=tag))
def test_qbit_rc_completion_is_explicit_and_rc_only(self):
options = self.assert_full(self.render(CIRCLE_BRANCH="release/1"), "publish_release_candidate")
self.assertFalse(options["notify_rc_published"])
@@ -318,8 +298,8 @@ class PipelineTests(unittest.TestCase):
self.change_docs()
for packed in ([False, True] if PACKED else [False]):
result = self.render(packed=packed)
self.assertEqual(list(result["workflows"]), ["verify"])
options = result["workflows"]["verify"]["jobs"][0]["docs_only"]
self.assertEqual(list(result["workflows"]), ["test_only"])
options = result["workflows"]["test_only"]["jobs"][0]["docs_only"]
self.assertEqual(options["name"], "qqq-orb/mvn_test_only")
self.assertIn("git diff --check", result["jobs"]["docs_only"]["steps"][1]["run"]["command"])
(self.repo / "App.java").write_text("changed\n", encoding="utf-8")
@@ -380,8 +360,8 @@ class PipelineTests(unittest.TestCase):
for branch, tag, workflow in events:
with self.subTest(workflow=workflow):
result = self.render(CIRCLE_BRANCH=branch, CIRCLE_TAG=tag)
self.assertEqual(list(result["workflows"]), ["verify"])
actual = result["workflows"]["verify"]["jobs"]
self.assertEqual(list(result["workflows"]), [workflow])
actual = result["workflows"][workflow]["jobs"]
expected = baseline["workflows"][workflow]["jobs"]
self.assertEqual(len(actual), len(expected))
for before, after in zip(expected, actual):
@@ -442,8 +422,8 @@ class PipelineTests(unittest.TestCase):
with self.subTest(branch=branch, enabled=enabled):
result = self.render(CIRCLE_BRANCH=branch, QQQ_CI_RUN_PLAYWRIGHT=str(enabled).lower())
workflow = base + ("_with_playwright" if enabled else "")
self.assertEqual(list(result["workflows"]), ["verify"])
jobs = result["workflows"]["verify"]["jobs"]
self.assertEqual(list(result["workflows"]), [workflow])
jobs = result["workflows"][workflow]["jobs"]
self.assertEqual(len(jobs), 2 if enabled else 1)
maven = [j for j in jobs if next(iter(j)).startswith("qqq-orb/mvn_frontend_")]
self.assertEqual(len(maven), 1)
@@ -474,10 +454,8 @@ class PipelineTests(unittest.TestCase):
("hotfix/fix", "", "publish_hotfix_release"), ("", "publish-fixture", "publish_feature"),
("", "v1.0.0", "publish_release")]:
result = self.render(CIRCLE_BRANCH=branch, CIRCLE_TAG=tag)
self.assertEqual(list(result["workflows"]), ["verify"])
options = next(iter(result["workflows"]["verify"]["jobs"][0].values()))
expected_kind = {"publish_hotfix_release": "hotfix"}.get(workflow, workflow.removeprefix("publish_"))
self.assertEqual(options["branch_type"], expected_kind)
self.assertEqual(list(result["workflows"]), [workflow])
options = next(iter(result["workflows"][workflow]["jobs"][0].values()))
if profile == "frontend-core":
self.assertTrue(options["npm_trusted_publishing"])
self.assertEqual(options["node_version"], "24.21")
@@ -485,9 +463,9 @@ class PipelineTests(unittest.TestCase):
else:
self.assertEqual(options["context"], ["qqq-maven-registry-credentials"])
main = self.render(CIRCLE_BRANCH="main")
self.assertEqual(list(main["workflows"]), ["verify"])
self.assertEqual(list(main["workflows"]), ["publish_release" if profile == "frontend-core" else "test_only"])
rc_tag = self.render(CIRCLE_BRANCH="", CIRCLE_TAG="v1.0.0-RC.1")
self.assertEqual(list(rc_tag["workflows"]), ["verify"])
self.assertEqual(list(rc_tag["workflows"]), ["publish_release" if profile == "frontend-core" else "test_only"])
def test_profile_specific_options_rejected(self):
for profile, options in [("qbit", {"node_version": "22"}), ("frontend-core", {"browsers": False}),
@@ -554,8 +532,7 @@ class PipelineTests(unittest.TestCase):
{"CIRCLE_BRANCH": "integration-example"}):
result = self.render(**environment)
if environment.get("CIRCLE_BRANCH") != "integration-example":
self.assertEqual(list(result["workflows"]), ["verify"])
self.assertEqual(result["workflows"]["verify"]["jobs"][0]["qqq-orb/mvn_publish"]["branch_type"], "release")
self.assertIn("publish_release", result["workflows"])
if PACKED:
self.assertEqual(result, self.render(packed=True, **environment))
-58
View File
@@ -1,58 +0,0 @@
import json
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
import yaml
ROOT = Path(__file__).parents[1]
class BranchLanguages(unittest.TestCase):
def select(self, tracked, untracked=()):
worker = yaml.safe_load((ROOT / '.github/workflows/qbit-codeql.yml').read_text())
script = next(s['run'] for s in worker['jobs']['analyze']['steps'] if s.get('id') == 'languages')
script = script.split("python3 <<'PY'\n", 1)[1].rsplit('\nPY', 1)[0]
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
subprocess.run(['git', 'init', '-q', directory], check=True)
for name in (*tracked, *untracked):
path = root / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text('fixture')
if tracked:
subprocess.run(['git', 'add', '--', *tracked], cwd=root, check=True)
output = root / 'outputs'
result = subprocess.run([sys.executable, '-c', script], cwd=root,
env={**os.environ, 'GITHUB_OUTPUT': str(output)}, capture_output=True, text=True)
return result, output.read_text() if output.exists() else ''
def test_historical_java_branch_does_not_scan_absent_actions(self):
result, output = self.select(['src/Example.java'])
self.assertEqual(0, result.returncode, result.stderr)
self.assertIn('languages=java-kotlin\n', output)
self.assertIn('build-mode=none\n', output)
def test_current_branch_preserves_all_present_supported_languages(self):
result, output = self.select(['src/Example.java', '.github/workflows/ci.yaml', 'web/app.tsx', 'tools/check.py'])
self.assertEqual(0, result.returncode, result.stderr)
self.assertIn('languages=java-kotlin,javascript-typescript,python,actions\n', output)
def test_kotlin_requires_a_build(self):
result, output = self.select(['src/Example.kt', '.github/workflows/ci.yml'])
self.assertEqual(0, result.returncode, result.stderr)
self.assertIn('build-mode=autobuild\n', output)
def test_untracked_files_do_not_select_languages(self):
result, output = self.select(['src/Example.java'], ['web/generated.js', '.github/workflows/untracked.yml'])
self.assertEqual(0, result.returncode, result.stderr)
self.assertIn('languages=java-kotlin\n', output)
def test_placeholder_fails_explicitly(self):
result, output = self.select(['README.md'])
self.assertNotEqual(0, result.returncode)
self.assertIn('No supported source', result.stderr)
if __name__ == '__main__':
unittest.main()
-73
View File
@@ -1,73 +0,0 @@
"""Preserve the audited main-branch hotfix contracts in the shared profile."""
import importlib.util
import json
from pathlib import Path
import re
import unittest
from unittest import mock
import yaml
ROOT = Path(__file__).resolve().parents[1]
def load(name, path):
spec = importlib.util.spec_from_file_location(name, ROOT / path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
migration = load('migration', 'tools/standardize_qbit.py')
pipeline = load('pipeline', 'src/scripts/generate_pipeline.py')
def selects(filters, branch, tag):
selector = filters.get('tags' if tag else 'branches', {})
if tag and not selector:
return False
def matches(patterns):
patterns = patterns if isinstance(patterns, list) else [patterns]
return any(re.fullmatch(p[1:-1], tag or branch, flags=re.ASCII) is not None if p.startswith('/') and p.endswith('/') else p == (tag or branch) for p in patterns)
return ('only' not in selector or matches(selector['only'])) and ('ignore' not in selector or not matches(selector['ignore']))
class HotfixMigrationTests(unittest.TestCase):
def test_audited_main_job_selection_is_preserved(self):
fixtures = json.loads((ROOT/'tests/fixtures/qbit-main-hotfix-policies.json').read_text())
for fixture in fixtures:
manifest = migration.infer_manifest(fixture['config'], '0.7.13', 'develop')
with mock.patch.object(Path, 'read_text', return_value=yaml.safe_dump(manifest)):
config = pipeline.load_manifest('unused', '0.7.13')
cases = [(branch, '') for branch in ('main','develop','feature/a','release/1','hotfix/1.2.3','integration-test','staging')]
cases += [('', tag) for tag in ('v1.2.3','v1.2.3-RC.1','vanything','publish1','invalid','v\u0661.\u0662.\u0663')]
for branch, tag in cases:
with self.subTest(repository=fixture['repository'], branch=branch, tag=tag):
expected = sorted((job, options.get('branch_type')) for workflow in fixture['config']['workflows'].values() for entry in workflow['jobs'] for job, options in entry.items() if selects(options.get('filters', {}), branch, tag))
with mock.patch.object(pipeline, 'git', return_value=b'verified-head\n'):
generated = pipeline.qbit_template(config, branch, tag)
actual = sorted((job, options.get('branch_type')) for workflow in generated['workflows'].values() for entry in workflow['jobs'] for job, options in entry.items() if selects(options.get('filters', {}), branch, tag))
# The canonical setup's tag filter prevents non-release tag runs.
caller = migration.canonical_caller('0.7.13', manifest['release_tag_policy'])
setup = caller['workflows']['setup']['jobs'][0]['qqq-orb/generate_pipeline']
if not selects(setup['filters'], branch, tag): actual = []
self.assertEqual(actual, expected)
def test_cms_repair_only_quotes_the_existing_tag_pattern(self):
fixtures = json.loads((ROOT/'tests/fixtures/qbit-main-hotfix-policies.json').read_text())
fixture = next(row for row in fixtures if row['repository'] == 'QRun-IO/qbit-cms')
with self.assertRaises(yaml.YAMLError):
yaml.safe_load(fixture['original_yaml'])
repaired = fixture['original_yaml'].replace(r'only: [/^v[0-9]+\.[0-9]+\.[0-9]+$/]',
r"only: ['/^v[0-9]+\.[0-9]+\.[0-9]+$/']")
self.assertEqual(yaml.safe_load(repaired), fixture['config'])
def test_stable_tag_selection_uses_ascii_digits(self):
with mock.patch.object(pipeline, 'git', return_value=b'verified-head\n'):
self.assertEqual(pipeline.event_kind('', 'v\u0661.\u0662.\u0663'), 'test')
self.assertEqual(pipeline.event_kind('', 'v1.2.3'), 'release')
def test_existing_manifest_does_not_enable_hotfix_publication(self):
raw = 'profile: qbit\norb_version: 0.7.13\ndefault_branch: develop\n'
with mock.patch.object(Path, 'read_text', return_value=raw):
config = pipeline.load_manifest('unused','0.7.13')
self.assertFalse(config['publish'].get('hotfix', False))
result = pipeline.qbit_template(config, 'hotfix/1.2.3', '')
self.assertIn('qqq-orb/mvn_test_only', result['workflows']['test_only']['jobs'][0])
if __name__ == '__main__': unittest.main()
-11
View File
@@ -58,17 +58,6 @@ class FixtureAPI:
class SweepTests(unittest.TestCase):
def test_stable_gate_and_mixed_name_latest_failure(self):
api = FixtureAPI()
api.status['check_runs'][0]['name'] = 'verify'
self.assertEqual('dispatched', sweep.reconcile(api, REPO))
api.sent.clear()
api.status['check_runs'].append(dict(api.status['check_runs'][0],
id=10, name='publish_release_candidate', conclusion='failure'))
with self.assertRaises(sweep.InvalidIntent):
sweep.reconcile(api, REPO)
self.assertEqual([], api.sent)
def test_idle_never_dispatches_or_reads_artifacts(self):
api = FixtureAPI(); api.lock = None
self.assertEqual('idle', sweep.reconcile(api, REPO))
-11
View File
@@ -23,17 +23,6 @@ def bump(parent=SHA, version='1.2.3-RC.4'):
class ReleaseGuardTests(unittest.TestCase):
def test_stable_workflow_preserves_exact_source_and_latest_attempt_checks(self):
result = status()
result['check_runs'][0]['name'] = 'verify'
self.assertEqual('1.2.3-RC.4', evaluate(SHA, result, bump()))
result['check_runs'].append(dict(result['check_runs'][0], id=10, conclusion='failure'))
with self.assertRaisesRegex(Failure, 'CircleCI failed'):
evaluate(SHA, result, bump())
result['check_runs'] = [dict(result['check_runs'][0], head_sha=OTHER)]
with self.assertRaises(Failure):
evaluate(SHA, result, bump())
def test_success_exact_built_source(self):
self.assertEqual('1.2.3-RC.4', evaluate(SHA, status(), bump()))
-9
View File
@@ -30,15 +30,6 @@ def validate(job, publisher):
class TimeoutRecoveryTests(unittest.TestCase):
def test_stable_gate_must_match_the_actual_publishing_workflow(self):
job, publisher = evidence()
job['workflows']['workflow_name'] = 'verify'
publisher['name'] = 'verify'
validate(job, publisher)
publisher['name'] = 'publish_release_candidate'
with self.assertRaises(Failure):
validate(job, publisher)
def test_exact_upload_timeout_after_successful_verify(self):
self.assertEqual((124, 0), validate(*evidence()))
+13 -38
View File
@@ -6,10 +6,6 @@ Example: python tools/audit_estate.py --inventory inventory.json --orb-version 0
Policy: {"profiles":{"qbit":{"required_checks":{"main":["observed context"],
"develop":["observed context"]}}},"repositories":{"QRun-IO/example":{...}}}.
Only use contexts verified on hosted canaries. Absent policy is unknown, not pass.
Use --live --source-branch main (or release/...) to inspect that branch's source;
omitting it retains default-branch auditing. Unavailable branches remain unknown.
A profile/repository policy may set rc_worker_sha independently of --worker-sha
so an RC-only worker change does not require updating unchanged native workers.
"""
import argparse
import base64
@@ -73,17 +69,11 @@ class Snapshot:
raise ReadError('invalid repository name')
self.live = live
self.path = entry.get('localPath', '')
requested = entry.get('sourceBranch')
if requested is not None and (not live or not isinstance(requested, str)
or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9._/-]*', requested)):
raise ReadError('explicit source branch requires a valid branch name and live lookup')
self.default_branch = (entry.get('defaultBranchRef') or {}).get('name')
self.branch = requested or self.default_branch
self.branch = (entry.get('defaultBranchRef') or {}).get('name')
self.sha = entry.get('sha', '')
if live:
info = gh('repos/' + self.repo)
self.default_branch = info['default_branch']
self.branch = requested or self.default_branch
self.branch = info['default_branch']
if info['archived']:
raise ReadError('repository is now archived; refresh inventory')
self.sha = gh('repos/' + self.repo + '/commits/' + quote(self.branch, safe=''))['sha']
@@ -177,8 +167,7 @@ def audit(entry, snapshot, version, worker_sha, policy):
name = entry['name']
profile = policy.get('profile') or ('qbit' if name.startswith('qbit-') else PROFILES.get(name))
result = {'repository': entry['nameWithOwner'], 'sha': snapshot.sha,
'default_branch': getattr(snapshot, 'default_branch', snapshot.branch),
'source_branch': snapshot.branch, 'profile': profile, 'findings': [], 'required_checks': {}}
'default_branch': snapshot.branch, 'profile': profile, 'findings': [], 'required_checks': {}}
findings = result['findings']
def finding(code, path=None, detail=None):
findings.append({k: v for k, v in {'code': code, 'path': path, 'detail': detail}.items() if v is not None})
@@ -207,7 +196,7 @@ def audit(entry, snapshot, version, worker_sha, policy):
manifest = Path(directory) / 'manifest.yml'
manifest.write_text(raw, encoding='utf-8')
generator.load_manifest(manifest, pin)
if data.get('default_branch') != result['default_branch']:
if data.get('default_branch') != snapshot.branch:
finding('default_branch_drift', '.qqq-ci.yml')
if caller is not None:
standard.validate(caller, raw, pin)
@@ -220,12 +209,11 @@ def audit(entry, snapshot, version, worker_sha, policy):
if profile == 'qbit' and (rc_enabled or existing_rc):
path = rc_worker.CALLER_PATH
raw = rc_source
rc_sha = policy.get("rc_worker_sha", worker_sha)
if raw is None:
finding('missing_rc_bridge', path)
elif not re.fullmatch(r'[0-9a-f]{40}', rc_sha or ''):
elif not re.fullmatch(r'[0-9a-f]{40}', worker_sha or ''):
finding('native_pin_policy_missing', path)
elif raw != rc_worker.generate(rc_sha):
elif raw != rc_worker.generate(worker_sha):
finding('rc_bridge_drift', path)
else:
native_paths.add(path)
@@ -233,22 +221,17 @@ def audit(entry, snapshot, version, worker_sha, policy):
if other != path and 'qbit-release-rc.yml@' in snapshot.read(other):
finding('duplicate_rc_bridge', other)
for kind, definition in auxiliary.BRIDGES.items():
bridge_sha = worker_sha
if kind == 'qbit-codeql':
if profile != 'qbit' or 'codeql_worker_sha' not in policy:
continue
bridge_sha = policy['codeql_worker_sha']
elif definition['repository'] != entry['nameWithOwner']:
if definition['repository'] != entry['nameWithOwner']:
continue
path = definition['path']
raw = snapshot.read(path)
if raw is None:
finding('missing_native_maintenance_bridge', path)
continue
if not re.fullmatch(r'[0-9a-f]{40}', bridge_sha or ''):
if not re.fullmatch(r'[0-9a-f]{40}', worker_sha or ''):
finding('native_pin_policy_missing', path)
continue
expected = generator.yaml.safe_dump(auxiliary.canonical(kind, bridge_sha), sort_keys=False)
expected = generator.yaml.safe_dump(auxiliary.canonical(kind, worker_sha), sort_keys=False)
if raw != expected:
finding('native_maintenance_bridge_drift', path)
else:
@@ -338,13 +321,9 @@ def audit(entry, snapshot, version, worker_sha, policy):
return result
def run(entries, version, worker_sha, policies, live=False, snapshot_factory=Snapshot, source_branch=None):
if source_branch is not None and not live:
raise ValueError('Explicit source branch audits require --live')
def run(entries, version, worker_sha, policies, live=False, snapshot_factory=Snapshot):
results = []
for entry in entries:
if source_branch is not None:
entry = dict(entry, sourceBranch=source_branch)
if entry.get('isArchived'):
results.append({'repository': entry['nameWithOwner'], 'status': 'archived_skip'})
continue
@@ -355,11 +334,10 @@ def run(entries, version, worker_sha, policies, live=False, snapshot_factory=Sna
try:
results.append(audit(entry, snapshot_factory(entry, live), version, worker_sha, policy))
except (ReadError, OSError, ValueError, KeyError, subprocess.TimeoutExpired):
results.append({'repository': entry['nameWithOwner'], 'source_branch': source_branch,
'status': 'unknown', 'reason': 'source/API/policy read failed'})
results.append({'repository': entry['nameWithOwner'], 'status': 'unknown', 'reason': 'source/API/policy read failed'})
return {'inventory_count': len(entries), 'active_count': sum(not e.get('isArchived', False) for e in entries),
'covered_count': len(results), 'unique_repository_count': len({e['nameWithOwner'] for e in entries}),
'live': live, 'source_branch_selector': source_branch or 'default', 'results': results}
'live': live, 'results': results}
def main():
@@ -369,15 +347,12 @@ def main():
parser.add_argument('--worker-sha')
parser.add_argument('--policy', type=Path)
parser.add_argument('--live', action='store_true', help='Read current source and branch rules using existing gh authentication')
parser.add_argument('--source-branch', help='Inspect this branch instead of the repository default; requires --live')
parser.add_argument('--expected-active', type=int, default=68)
parser.add_argument('--output', type=Path)
args = parser.parse_args()
if args.source_branch is not None and not args.live:
parser.error('--source-branch requires --live')
entries = json.loads(args.inventory.read_text(encoding='utf-8'))
policies = json.loads(args.policy.read_text(encoding='utf-8')) if args.policy else {}
report = run(entries, args.orb_version, args.worker_sha, policies, args.live, source_branch=args.source_branch)
report = run(entries, args.orb_version, args.worker_sha, policies, args.live)
report['expected_active_count'] = args.expected_active
report['coverage_matches_expected'] = (report['active_count'] == args.expected_active
and report['unique_repository_count'] == report['inventory_count'])
+4 -9
View File
@@ -43,8 +43,8 @@ def publication_filters(kind, filters):
raise ValueError("Unknown publication filters")
branches = filters.get("branches")
tags = filters.get("tags")
if kind in ("snapshot", "release_candidate", "hotfix"):
expected = {"snapshot": "develop", "release_candidate": r"/release\/.*/", "hotfix": r"/hotfix\/.*/"}[kind]
if kind in ("snapshot", "release_candidate"):
expected = "develop" if kind == "snapshot" else r"/release\/.*/"
if not isinstance(branches, dict) or set(branches) != {"only"} or single_filter(branches["only"]) != expected or tags not in (None, {"only": []}):
raise ValueError("Unknown snapshot/RC filters")
return False, "none"
@@ -58,8 +58,7 @@ def publication_filters(kind, filters):
tag_filter = single_filter(tags["only"])
if not isinstance(tag_filter, str):
raise ValueError("Unknown release tag filter")
policy = {r"/^v\d+\.\d+\.\d+$/": "stable", r"/^v[0-9]+\.[0-9]+\.[0-9]+$/": "stable",
"/v.*/": "v-prefix"}.get(tag_filter)
policy = {r"/^v\d+\.\d+\.\d+$/": "stable", "/v.*/": "v-prefix"}.get(tag_filter)
if policy is None:
raise ValueError("Unknown release tag filter")
return main, policy
@@ -81,9 +80,6 @@ def test_filters(filters):
"/(develop|release/.*|integration.*)/": "non-release-no-integration",
"/(develop|main|release/.*|integration.*)/": "feature",
"/(develop|main|release/.*)/": "non-release-no-main",
"/(develop|release/.*|hotfix/.*)/": "non-release-no-hotfix",
"/(develop|main|release/.*|hotfix/.*)/": "non-release-no-main-hotfix",
"/(develop|main|release/.*|hotfix/.*|integration.*)/": "feature-no-hotfix",
}.get(pattern.replace(r"\/", "/"))
if policy is None:
raise ValueError("Unknown test branch filters")
@@ -123,7 +119,7 @@ def infer_manifest(config, version, default_branch):
raise ValueError("Custom pre-steps require review")
if job.endswith("/mvn_publish"):
kind = options.get("branch_type")
if kind not in ("snapshot", "release_candidate", "release", "hotfix"):
if kind not in ("snapshot", "release_candidate", "release"):
raise ValueError("Custom publication contract requires review")
if kind in publications:
raise ValueError("Duplicate publication jobs require review")
@@ -147,7 +143,6 @@ def infer_manifest(config, version, default_branch):
"test_branch_policy": test_policy or "all",
"publish": {**{kind: kind in publications
for kind in ("snapshot", "release_candidate", "release")},
**({"hotfix": True} if "hotfix" in publications else {}),
"asciidoc": False},
}