Skip to content

Commit

Permalink
[tasks] add back comments to test_infra_version.yaml (#32344)
Browse files Browse the repository at this point in the history
Co-authored-by: Célian Raimbault <[email protected]>
  • Loading branch information
pducolin and CelianR authored Dec 18, 2024
1 parent 623e2dc commit 99d8d32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 13 additions & 3 deletions tasks/buildimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@ def update_test_infra_definitions(ctx: Context, commit_sha: str, go_mod_only: bo
"""
Update the test-infra-definition image version in the Gitlab CI as well as in the e2e go.mod
"""
if not go_mod_only:
update_test_infra_def(".gitlab/common/test_infra_version.yml", commit_sha[:12], is_dev_image)

print(f"Updating test-infra-definitions to {commit_sha}")
with ctx.cd("test/new-e2e"):
ctx.run(f"go get github.com/DataDog/test-infra-definitions@{commit_sha}")
ctx.run("go mod tidy")

if not go_mod_only:
prefix_comment = """# File generated by inv buildimages.update-test-infra-definitions
# Please do not edit this file manually
# To update the test-infra-definitions version, run `inv buildimages.update-test-infra-definitions --commit-sha <commit_sha>` [--is-dev-image]
"""
update_test_infra_def(
file_path=".gitlab/common/test_infra_version.yml",
image_tag=commit_sha[:12],
is_dev_image=is_dev_image,
prefix_comment=prefix_comment,
)


@task(
help={
Expand Down
5 changes: 2 additions & 3 deletions tasks/libs/ciproviders/gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,12 +1258,10 @@ def full_config_get_all_stages(full_config: dict) -> set[str]:
return all_stages


def update_test_infra_def(file_path, image_tag, is_dev_image=False):
def update_test_infra_def(file_path, image_tag, is_dev_image=False, prefix_comment=""):
"""
Updates TEST_INFRA_DEFINITIONS_BUILDIMAGES in `.gitlab/common/test_infra_version.yml` file
"""
import yaml

test_infra_def = {}
with open(file_path) as test_infra_version_file:
try:
Expand All @@ -1276,6 +1274,7 @@ def update_test_infra_def(file_path, image_tag, is_dev_image=False):
except yaml.YAMLError as e:
raise Exit(f"Error while loading {file_path}: {e}") from e
with open(file_path, "w") as test_infra_version_file:
test_infra_version_file.write(prefix_comment + ('\n\n' if prefix_comment else ''))
# Add explicit_start=True to keep the document start marker ---
# See "Document Start" in https://www.yaml.info/learn/document.html for more details
yaml.dump(test_infra_def, test_infra_version_file, explicit_start=True)
Expand Down

0 comments on commit 99d8d32

Please sign in to comment.