Skip to content

Commit eab1b32

Browse files
authored
Merge pull request #26 from cloudengine-labs/copilot/review-bug-1-pull-request
fix(gitlab-ci): BUG-1 — empty stages and no deploy job when `--type deploy` without `--kubernetes`
2 parents df20ac6 + c7f71d1 commit eab1b32

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

cli/scaffold_gitlab.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,22 @@ def _test_job(lang_config):
225225

226226

227227
def _deploy_job(args):
228-
"""Kubernetes deploy job."""
228+
"""Kubernetes deploy job, or a generic deploy stub when kubernetes is disabled."""
229229
if not args.kubernetes:
230-
return {}
230+
protected_branches = [b.strip() for b in args.branches.split(",")]
231+
rules = [
232+
{"if": f"$CI_COMMIT_BRANCH == \"{b}\"", "when": "manual" if b != protected_branches[0] else "on_success"}
233+
for b in protected_branches
234+
]
235+
return {
236+
"deploy": {
237+
"stage": "deploy",
238+
"script": [
239+
"echo \"Deploy stage — configure your deployment scripts here\"",
240+
],
241+
"rules": rules,
242+
}
243+
}
231244

232245
protected_branches = [b.strip() for b in args.branches.split(",")]
233246

@@ -298,7 +311,7 @@ def generate_pipeline(args, custom_values):
298311
if args.type in ("test", "complete"):
299312
pipeline.update(_test_job(lang_config))
300313

301-
if args.type in ("deploy", "complete") and args.kubernetes:
314+
if args.type == "deploy" or (args.type == "complete" and args.kubernetes):
302315
pipeline.update(_deploy_job(args))
303316

304317
pipeline.update(custom_values)

tests/test_comprehensive.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ def test_deploy_pipeline_no_kubernetes_empty_stages(self):
619619
"""
620620
BUG-1: When type='deploy' and kubernetes=False, the generated
621621
pipeline has an empty stages list, which is invalid for GitLab CI.
622-
Expected: at least one stage should be present even for non-k8s deploy.
622+
Expected: at least one stage should be present even for non-k8s deploy,
623+
and a deploy job stub must be present in the pipeline.
623624
"""
624625
with tempfile.TemporaryDirectory() as tmp:
625626
out = os.path.join(tmp, ".gitlab-ci.yml")
@@ -636,6 +637,10 @@ def test_deploy_pipeline_no_kubernetes_empty_stages(self):
636637
assert len(stages) > 0, (
637638
"Expected at least one stage in a deploy pipeline, got: {!r}".format(stages)
638639
)
640+
# A deploy job stub must be present so the pipeline is valid
641+
assert "deploy" in data, (
642+
"Expected a deploy job in the pipeline, got keys: {!r}".format(list(data.keys()))
643+
)
639644

640645

641646
# ===========================================================================

0 commit comments

Comments
 (0)