Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c29ec2f82c |
No files matched your search
@@ -83,7 +83,7 @@ workflows:
|
||||
when: << pipeline.parameters.run_enrollment_reconcile >>
|
||||
jobs:
|
||||
- enrollment-reconcile:
|
||||
context: qqq-maven-registry-credentials
|
||||
context: [qqq-maven-registry-credentials, orb-publishing]
|
||||
filters:
|
||||
branches:
|
||||
only: main
|
||||
|
||||
@@ -66,6 +66,7 @@ jobs:
|
||||
python3 tests/test_discover_enrollment.py
|
||||
python3 tests/test_finish_enrollment.py
|
||||
python3 tests/test_run_enrollment.py
|
||||
python3 tests/test_circle_project_settings.py
|
||||
python3 tests/test_static_analysis_exit.py
|
||||
python3 tests/test_validate_standard.py
|
||||
python3 tests/test_voyage_profile.py
|
||||
|
||||
+68
-53
@@ -1,53 +1,68 @@
|
||||
# GitOps validation
|
||||
|
||||
The orb owns `.github/workflows/gitops.yml`. The consumer keeps only the immutable caller generated by `generate_auxiliary_workflow.py gitops --ref <orb-commit>` at `.github/workflows/validate.yml`.
|
||||
|
||||
One native job downloads Kustomize 5.7.1 with its pinned official SHA-256 and renders every Kustomization, including bases, overlays and proxy declarations. Missing configurations or a failed render fail the job. Rendered resources are discarded rather than logged or uploaded because they may contain Secrets. This checks rendering, not Kubernetes schema compatibility or cluster health. No cluster access or publication credentials are required.
|
||||
|
||||
The caller runs on main pushes and pull requests without path filters, so a required check always reports. Superseded PR runs are canceled. Feature pushes do not create duplicate jobs. Remove the old Circle pipeline only after the native job passes on the consumer, then disable obsolete Circle build requests and require the observed native check with no human review.
|
||||
|
||||
For marketing-website-cd, the prior Circle job only printed Hello World. Its former production role moved to KofTwentyTwo/cluster-gitops; validation does not re-enable that retired deployment path.
|
||||
|
||||
The shared registry includes marketing-website-cd and voyage-cd. Daily enrollment recognizes their canonical main-branch caller without creating Circle configuration. Recognition requires a signed immutable worker pin matching the supported worker, a complete source tree, and no additional Circle or GitHub workflows. Enforcement requires the GitHub Actions app-bound gitops / validate gate and preserves existing branch rules. Unavailable private-repository protections remain an explicit enforcement failure; recognition alone is not enforcement.
|
||||
|
||||
|
||||
### Documentation repositories with shell automation
|
||||
|
||||
Use the canonical `repository-policy` manifest with `shell_checks: true` for
|
||||
repositories containing documentation, YAML/JSON, Mermaid source, and shell tools.
|
||||
The shared job remains one small executor with no publication or deployment.
|
||||
It installs ShellCheck only for this opt-in and checks every tracked `.sh` file
|
||||
with `bash -n` and ShellCheck at warning severity; scripts are never executed.
|
||||
Mermaid files are treated as UTF-8 documentation, not rendered or syntax-validated.
|
||||
Application manifests and other executable languages still require a build profile.
|
||||
|
||||
|
||||
### Homebrew distribution taps
|
||||
|
||||
The `homebrew-tap` profile takes only `tap` (lowercase owner/name) and `formula`.
|
||||
One small job in a digest-pinned Homebrew container validates the exact checkout,
|
||||
reads all OS/architecture variants, fetches their binaries with checksum verification,
|
||||
then installs and tests the Linux formula. It does not publish or update formulae.
|
||||
macOS downloads are verified, but this Linux job does not execute macOS binaries.
|
||||
|
||||
|
||||
### Application template acceptance
|
||||
|
||||
The `application-template` profile renders the checked-out template through pinned
|
||||
qctl code and a checksum-verified catalog. It runs transforms but never post-generation
|
||||
hooks, then performs Maven verify on the generated application with all its tests.
|
||||
The renderer and Maven dependencies are cached; test reports and the generated JAR
|
||||
are retained. This is acceptance of a generated consumer, not Maven publication.
|
||||
Only the standard profile, orb version, and default branch are consumer settings.
|
||||
|
||||
The coordinator also recognizes qctl on main/develop and the approved .github,
|
||||
business-platform, MCP-RAG and IntelliJ callers on main. It verifies each complete
|
||||
workflow inventory, canonical caller, signed immutable orb pin and matching shared
|
||||
worker source before recognizing the repository. Native verification gates bind to
|
||||
the GitHub Actions app; release-only jobs are not merge requirements. No CircleCI
|
||||
caller is added to these native consumers. qctl requires its shared tests; the native binary job is push-only, and
|
||||
full platform release builds retain their existing shared-worker policy.
|
||||
|
||||
Existing classic branch protections without a required-status-check section gain
|
||||
an additive shared ruleset. Signing, reviews, history and access restrictions remain
|
||||
unchanged, and a subsequent reconciliation verifies the effective ruleset.
|
||||
# GitOps validation
|
||||
|
||||
The orb owns `.github/workflows/gitops.yml`. The consumer keeps only the immutable caller generated by `generate_auxiliary_workflow.py gitops --ref <orb-commit>` at `.github/workflows/validate.yml`.
|
||||
|
||||
One native job downloads Kustomize 5.7.1 with its pinned official SHA-256 and renders every Kustomization, including bases, overlays and proxy declarations. Missing configurations or a failed render fail the job. Rendered resources are discarded rather than logged or uploaded because they may contain Secrets. This checks rendering, not Kubernetes schema compatibility or cluster health. No cluster access or publication credentials are required.
|
||||
|
||||
The caller runs on main pushes and pull requests without path filters, so a required check always reports. Superseded PR runs are canceled. Feature pushes do not create duplicate jobs. Remove the old Circle pipeline only after the native job passes on the consumer, then disable obsolete Circle build requests and require the observed native check with no human review.
|
||||
|
||||
For marketing-website-cd, the prior Circle job only printed Hello World. Its former production role moved to KofTwentyTwo/cluster-gitops; validation does not re-enable that retired deployment path.
|
||||
|
||||
The shared registry includes marketing-website-cd and voyage-cd. Daily enrollment recognizes their canonical main-branch caller without creating Circle configuration. Recognition requires a signed immutable worker pin matching the supported worker, a complete source tree, and no additional Circle or GitHub workflows. Enforcement requires the GitHub Actions app-bound gitops / validate gate and preserves existing branch rules. Unavailable private-repository protections remain an explicit enforcement failure; recognition alone is not enforcement.
|
||||
|
||||
|
||||
### Documentation repositories with shell automation
|
||||
|
||||
Use the canonical `repository-policy` manifest with `shell_checks: true` for
|
||||
repositories containing documentation, YAML/JSON, Mermaid source, and shell tools.
|
||||
The shared job remains one small executor with no publication or deployment.
|
||||
It installs ShellCheck only for this opt-in and checks every tracked `.sh` file
|
||||
with `bash -n` and ShellCheck at warning severity; scripts are never executed.
|
||||
Mermaid files are treated as UTF-8 documentation, not rendered or syntax-validated.
|
||||
Application manifests and other executable languages still require a build profile.
|
||||
|
||||
|
||||
### Homebrew distribution taps
|
||||
|
||||
The `homebrew-tap` profile takes only `tap` (lowercase owner/name) and `formula`.
|
||||
One small job in a digest-pinned Homebrew container validates the exact checkout,
|
||||
reads all OS/architecture variants, fetches their binaries with checksum verification,
|
||||
then installs and tests the Linux formula. It does not publish or update formulae.
|
||||
macOS downloads are verified, but this Linux job does not execute macOS binaries.
|
||||
|
||||
|
||||
### Application template acceptance
|
||||
|
||||
The `application-template` profile renders the checked-out template through pinned
|
||||
qctl code and a checksum-verified catalog. It runs transforms but never post-generation
|
||||
hooks, then performs Maven verify on the generated application with all its tests.
|
||||
The renderer and Maven dependencies are cached; test reports and the generated JAR
|
||||
are retained. This is acceptance of a generated consumer, not Maven publication.
|
||||
Only the standard profile, orb version, and default branch are consumer settings.
|
||||
|
||||
The coordinator also recognizes qctl on main/develop and the approved .github,
|
||||
business-platform, MCP-RAG and IntelliJ callers on main. It verifies each complete
|
||||
workflow inventory, canonical caller, signed immutable orb pin and matching shared
|
||||
worker source before recognizing the repository. Native verification gates bind to
|
||||
the GitHub Actions app; release-only jobs are not merge requirements. No CircleCI
|
||||
caller is added to these native consumers. qctl requires its shared tests; the native binary job is push-only, and
|
||||
full platform release builds retain their existing shared-worker policy.
|
||||
|
||||
Existing classic branch protections without a required-status-check section gain
|
||||
an additive shared ruleset. Signing, reviews, history and access restrictions remain
|
||||
unchanged, and a subsequent reconciliation verifies the effective ruleset.
|
||||
|
||||
The same daily pass manages CircleCI's native `autocancel-builds` setting for
|
||||
canonical `repository-policy`, `homebrew-tap`, `application-template`, and
|
||||
`marketing` consumers. Marketing must retain `main` as its default branch;
|
||||
environment deployment remains main-only. CircleCI excludes default-branch,
|
||||
scheduled and rerun workflows from automatic cancellation. This avoids a custom
|
||||
cancellation job and does not add executions to consumer pipelines.
|
||||
|
||||
The pass uses the existing orb-publishing context on the trusted orb main branch.
|
||||
It changes only the cancellation flag, checks for source movement before writing,
|
||||
and verifies preservation of all other flags. Its separate
|
||||
`result.circle-settings.json` artifact records missing credentials/API access,
|
||||
unconverted sources and profiles needing cancellation-policy review explicitly.
|
||||
Publication-heavy profiles are not changed until their non-default release
|
||||
semantics are reviewed; a successful reconciliation pass does not certify them.
|
||||
@@ -0,0 +1,71 @@
|
||||
"""Cost settings preserve source qualification and unrelated project controls."""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools'))
|
||||
import circle_project_settings as settings
|
||||
|
||||
|
||||
class SettingsTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.plan = {'repository': 'QRun-IO/marketing-website', 'profile': 'marketing',
|
||||
'branch': 'main', 'head': 'a' * 40, 'changed': False}
|
||||
self.before = {'autocancel-builds': False, 'setup-workflows': True,
|
||||
'build-fork-prs': False, 'drop-all-build-requests': False}
|
||||
self.source = Mock(side_effect=[{'archived': False, 'default_branch': 'main'},
|
||||
{'commit': {'sha': self.plan['head']}}])
|
||||
|
||||
def test_narrow_update_and_idempotent_readback(self):
|
||||
request = Mock(side_effect=[{'feature_flags': self.before}, {},
|
||||
{'feature_flags': {**self.before, 'autocancel-builds': True}}])
|
||||
result = settings.reconcile(self.plan, self.source, True, request)
|
||||
self.assertEqual({'state': 'enforced', 'changed': True}, result)
|
||||
self.assertEqual({'feature_flags': {'autocancel-builds': True}}, request.call_args_list[1].args[1])
|
||||
request = Mock(return_value={'feature_flags': {**self.before, 'autocancel-builds': True}})
|
||||
source = Mock(return_value={'archived': False, 'default_branch': 'main'})
|
||||
self.assertEqual({'state': 'enforced', 'changed': False},
|
||||
settings.reconcile(self.plan, source, True, request))
|
||||
self.assertEqual(1, request.call_count)
|
||||
|
||||
def test_dry_run_never_writes(self):
|
||||
request = Mock(return_value={'feature_flags': self.before})
|
||||
self.assertEqual({'state': 'inspected', 'changed': True},
|
||||
settings.reconcile(self.plan, self.source, False, request))
|
||||
request.assert_called_once_with(self.plan['repository'])
|
||||
|
||||
def test_unreviewed_profiles_and_unconverted_sources_never_call_api(self):
|
||||
for change, expected in [({'profile': 'qbit'}, 'not-managed'),
|
||||
({'profile': 'native-gitops'}, 'not-managed'),
|
||||
({'changed': True}, 'waiting-source')]:
|
||||
source, request = Mock(), Mock()
|
||||
result = settings.reconcile({**self.plan, **change}, source, True, request)
|
||||
self.assertEqual(expected, result['state'])
|
||||
source.assert_not_called()
|
||||
request.assert_not_called()
|
||||
|
||||
def test_changed_head_or_unexpected_default_branch_prevents_write(self):
|
||||
for responses in [
|
||||
[{'archived': False, 'default_branch': 'main'}, {'commit': {'sha': 'b' * 40}}],
|
||||
[{'archived': False, 'default_branch': 'develop'}],
|
||||
[{'archived': True, 'default_branch': 'main'}],
|
||||
]:
|
||||
request = Mock(return_value={'feature_flags': self.before})
|
||||
result = settings.reconcile(self.plan, Mock(side_effect=responses), True, request)
|
||||
self.assertEqual('unresolved', result['state'])
|
||||
self.assertTrue(all(len(call.args) == 1 for call in request.call_args_list))
|
||||
|
||||
def test_unrelated_setting_drift_and_unavailable_api_are_not_success(self):
|
||||
request = Mock(side_effect=[{'feature_flags': self.before}, {},
|
||||
{'feature_flags': {**self.before, 'autocancel-builds': True,
|
||||
'build-fork-prs': True}}])
|
||||
self.assertEqual('unresolved', settings.reconcile(self.plan, self.source, True, request)['state'])
|
||||
source = Mock(return_value={'archived': False, 'default_branch': 'main'})
|
||||
for response in [Mock(side_effect=ValueError('Central CircleCI credential unavailable')),
|
||||
Mock(return_value={'feature_flags': {}})]:
|
||||
self.assertEqual('unresolved', settings.reconcile(self.plan, source, True, response)['state'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -30,6 +30,7 @@ class RunnerTests(unittest.TestCase):
|
||||
output = Path(args[args.index('--output') + 1])
|
||||
output.write_text('[{"state":"unresolved"}]')
|
||||
self.assertEqual(1200, kwargs['timeout'])
|
||||
self.assertIn('--circle-settings', args)
|
||||
self.assertEqual('test-only-secret', kwargs['env']['GH_TOKEN'])
|
||||
raise subprocess.TimeoutExpired(args, 1200)
|
||||
self.assertEqual(124, run_enrollment.run(self.environment(), execute, directory))
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Manage native cost controls only for profiles with reviewed cancellation semantics."""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from urllib.error import URLError
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
|
||||
AUTOCANCEL_PROFILES = {'repository-policy', 'homebrew-tap', 'application-template', 'marketing'}
|
||||
|
||||
|
||||
def request(repository, payload=None):
|
||||
"""Use existing central credentials; never expose authentication or error bodies."""
|
||||
if not re.fullmatch(r'QRun-IO/[A-Za-z0-9_.-]+', repository):
|
||||
raise ValueError('Only QRun-IO projects can be managed')
|
||||
token = os.environ.get('CIRCLE_TOKEN')
|
||||
if not token:
|
||||
raise ValueError('Central CircleCI credential unavailable')
|
||||
headers = {'Circle-Token': token, 'Accept': 'application/json'}
|
||||
if payload is not None:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
operation = Request('https://circleci.com/api/v1.1/project/github/' + repository + '/settings',
|
||||
headers=headers, method='GET' if payload is None else 'PUT',
|
||||
data=None if payload is None else json.dumps(payload).encode())
|
||||
try:
|
||||
with urlopen(operation, timeout=30) as response:
|
||||
return json.load(response)
|
||||
except (URLError, ValueError):
|
||||
raise ValueError('CircleCI project settings unavailable') from None
|
||||
|
||||
|
||||
def reconcile(plan, source_request, apply=False, settings_request=request):
|
||||
"""Require a current canonical source and preserve every unrelated project flag."""
|
||||
if plan['profile'] not in AUTOCANCEL_PROFILES:
|
||||
return {'state': 'not-managed', 'reason': 'Profile cancellation policy not reviewed'}
|
||||
if plan['changed']:
|
||||
return {'state': 'waiting-source', 'reason': 'Canonical enrollment must land first'}
|
||||
repo = plan['repository']
|
||||
try:
|
||||
info = source_request(f'repos/{repo}')
|
||||
if info['archived'] or (plan['profile'] == 'marketing' and info['default_branch'] != 'main'):
|
||||
raise ValueError('Repository default branch or archive state differs from policy')
|
||||
before = settings_request(repo)['feature_flags']
|
||||
if not isinstance(before, dict) or type(before.get('autocancel-builds')) is not bool:
|
||||
raise ValueError('CircleCI cancellation flag is missing or invalid')
|
||||
changed = not before['autocancel-builds']
|
||||
if apply and changed:
|
||||
if source_request(f'repos/{repo}/branches/{plan["branch"]}')['commit']['sha'] != plan['head']:
|
||||
raise ValueError('Source changed after enrollment inspection')
|
||||
settings_request(repo, {'feature_flags': {'autocancel-builds': True}})
|
||||
after = settings_request(repo)['feature_flags']
|
||||
if after != {**before, 'autocancel-builds': True}:
|
||||
raise ValueError('CircleCI settings readback differs from the narrow update')
|
||||
return {'state': 'enforced' if apply else 'inspected', 'changed': changed}
|
||||
except (ValueError, KeyError, TypeError) as error:
|
||||
return {'state': 'unresolved', 'reason': str(error)}
|
||||
@@ -187,6 +187,7 @@ def main():
|
||||
parser.add_argument('--apply', action='store_true')
|
||||
parser.add_argument('--merge-ready', action='store_true')
|
||||
parser.add_argument('--enforce', action='store_true')
|
||||
parser.add_argument('--circle-settings', action='store_true')
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
if (args.merge_ready or args.enforce) and not args.apply:
|
||||
@@ -219,6 +220,17 @@ def main():
|
||||
if args.enforce:
|
||||
row['enforcement'] = finish_enrollment.enforce_current(plan)
|
||||
args.output.write_text(json.dumps(report, indent=2), encoding='utf-8')
|
||||
if args.circle_settings:
|
||||
import circle_project_settings
|
||||
settings, seen = [], set()
|
||||
for plan in sorted(plans, key=lambda p: p['changed']):
|
||||
if plan['repository'] in seen:
|
||||
continue
|
||||
seen.add(plan['repository'])
|
||||
settings.append({'repository': plan['repository'], 'profile': plan['profile'],
|
||||
**circle_project_settings.reconcile(plan, api, apply=args.apply)})
|
||||
args.output.with_suffix('.circle-settings.json').write_text(
|
||||
json.dumps(settings, indent=2), encoding='utf-8')
|
||||
print(json.dumps({'targets': len(plans), 'changed': sum(p['changed'] for p in plans),
|
||||
'unresolved': sum(row['state'] == 'unresolved' for row in findings),
|
||||
'applied': args.apply}))
|
||||
|
||||
@@ -22,7 +22,8 @@ def run(environment=None, execute=subprocess.run, root=None):
|
||||
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']
|
||||
'--output', str(output / 'result.json'), '--apply', '--merge-ready', '--enforce',
|
||||
'--circle-settings']
|
||||
try:
|
||||
result = execute(args, cwd=root, env=env, timeout=1200, check=False)
|
||||
code = result.returncode
|
||||
|
||||
Reference in new issue
Block a user