Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
342d3b36d2 | ||
|
|
418a346ab3 |
No files matched your search
@@ -70,10 +70,12 @@ 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"):
|
||||
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"):
|
||||
raise ManifestError("Unsupported profile")
|
||||
allowed = ("profile", "orb_version", "default_branch", "docs_only", "publish")
|
||||
if profile in ("qbit", "core"):
|
||||
if profile == "node-artifact":
|
||||
allowed = ("profile", "orb_version", "default_branch", "node_version", "context", "npm_scopes", "artifact_path", "build_branches")
|
||||
elif 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")
|
||||
@@ -104,6 +106,22 @@ 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",)
|
||||
@@ -460,6 +478,30 @@ 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,10 +70,12 @@ 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"):
|
||||
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"):
|
||||
raise ManifestError("Unsupported profile")
|
||||
allowed = ("profile", "orb_version", "default_branch", "docs_only", "publish")
|
||||
if profile in ("qbit", "core"):
|
||||
if profile == "node-artifact":
|
||||
allowed = ("profile", "orb_version", "default_branch", "node_version", "context", "npm_scopes", "artifact_path", "build_branches")
|
||||
elif 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")
|
||||
@@ -104,6 +106,22 @@ 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",)
|
||||
@@ -460,6 +478,30 @@ 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,6 +47,7 @@ PROFILE_PARAMETERS = {
|
||||
"mcp-policy": {},
|
||||
"repository-policy": {},
|
||||
"marketing": {},
|
||||
"node-artifact": {},
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +67,8 @@ 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:
|
||||
|
||||
@@ -29,6 +29,9 @@ 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')
|
||||
|
||||
@@ -191,6 +191,36 @@ 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", {}))
|
||||
|
||||
@@ -20,6 +20,9 @@ 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'))
|
||||
|
||||
@@ -15,7 +15,7 @@ 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')}
|
||||
'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'})
|
||||
|
||||
Reference in new issue
Block a user