Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the commit of the terraform rendering optional (replaces PR 995) #1149

Merged
merged 12 commits into from
Mar 8, 2022
8 changes: 6 additions & 2 deletions qhub/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
},
}

CICD_CONFIGURATION = {"type": "PLACEHOLDER", "branch": "main"}
CICD_CONFIGURATION = {
"type": "PLACEHOLDER",
"branch": "main",
"commit_render": True,
}

AUTH_PASSWORD = {
"type": "password",
Expand Down Expand Up @@ -255,7 +259,7 @@ def render_config(
config["provider"] = cloud_provider

if ci_provider is not None and ci_provider != "none":
config["ci_cd"] = {"type": ci_provider, "branch": "main"}
config["ci_cd"] = {"type": ci_provider, "branch": "main", "commit_render": True}
iameskild marked this conversation as resolved.
Show resolved Hide resolved

if terraform_state is not None:
config["terraform_state"] = {"type": terraform_state}
Expand Down
9 changes: 6 additions & 3 deletions qhub/provider/cicd/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def gen_qhub_ops(config):

env_vars = gha_env_vars(config)
branch = config["ci_cd"]["branch"]
commit_render = config["ci_cd"]["commit_render"]
iameskild marked this conversation as resolved.
Show resolved Hide resolved
qhub_version = config["qhub_version"]

push = GHA_on_extras(branches=[branch], paths=["qhub-config.yaml"])
Expand Down Expand Up @@ -245,9 +246,11 @@ def gen_qhub_ops(config):
},
)

job1 = GHA_job_id(
name="qhub", runs_on_="ubuntu-latest", steps=[step1, step2, step3, step4, step5]
)
gha_steps = [step1, step2, step3, step4]
if commit_render:
gha_steps.append(step5)

job1 = GHA_job_id(name="qhub", runs_on_="ubuntu-latest", steps=gha_steps)
jobs = GHA_jobs(__root__={"build": job1})

return QhubOps(
Expand Down
7 changes: 7 additions & 0 deletions qhub/provider/cicd/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class GLCI(BaseModel):
def gen_gitlab_ci(config):

branch = config["ci_cd"]["branch"]
commit_render = config["ci_cd"]["commit_render"]
before_script = config["ci_cd"].get("before_script")
after_script = config["ci_cd"].get("after_script")
pip_install = pip_install_qhub(config["qhub_version"])
Expand All @@ -53,13 +54,19 @@ def gen_gitlab_ci(config):
f"git checkout {branch}",
f"{pip_install}",
"qhub deploy --config qhub-config.yaml --disable-prompt --skip-remote-state-provision",
]

commit_render_script = [
"git config user.email 'qhub@quansight.com'",
"git config user.name 'gitlab ci'",
"git add .",
"git diff --quiet && git diff --staged --quiet || (git commit -m '${COMMIT_MSG}'",
f"git push origin {branch})",
]

if commit_render:
script += commit_render_script

rules = [
GLCI_rules(
if_=f"$CI_COMMIT_BRANCH == '{branch}'",
Expand Down
1 change: 1 addition & 0 deletions qhub/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Config:
class CICD(Base):
type: CiEnum
branch: str
commit_render: bool
iameskild marked this conversation as resolved.
Show resolved Hide resolved
before_script: typing.Optional[typing.List[str]]
after_script: typing.Optional[typing.List[str]]

Expand Down