-
Notifications
You must be signed in to change notification settings - Fork 210
Fix bump-version to use YAML parsing for packages.yml updates #2148
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
Open
devin-ai-integration
wants to merge
2
commits into
master
Choose a base branch
from
devin/1773346628-fix-bump-version-yaml
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| import yaml | ||
|
|
||
| PACKAGES_FILE = "./elementary/monitor/dbt_project/packages.yml" | ||
| HELPER_COMMENTS = """ | ||
| # NOTE - for unreleased CLI versions we often need to update the package version to a commit hash (please leave this | ||
| # commented, so it will be easy to access) | ||
| # - git: https://github.com/elementary-data/dbt-data-reliability.git | ||
| # revision: <COMMIT_HASH> | ||
| # When releasing a new version of the package, if the current version is using a commit hash, update the version to the new version. | ||
| # - package: elementary-data/elementary | ||
| # version: {version} | ||
| """ | ||
|
|
||
|
|
||
| def bump_packages_version(version: str) -> None: | ||
| with open(PACKAGES_FILE) as f: | ||
| data = yaml.safe_load(f) | ||
|
|
||
| packages = data.get("packages") or [] | ||
|
|
||
| new_packages = [] | ||
| elementary_found = False | ||
| for pkg in packages: | ||
| if "git" in pkg and "dbt-data-reliability" in pkg["git"]: | ||
| # Replace git hash reference with proper package reference | ||
| new_packages.append( | ||
| { | ||
| "package": "elementary-data/elementary", | ||
| "version": version, | ||
| } | ||
| ) | ||
| elementary_found = True | ||
| elif pkg.get("package") == "elementary-data/elementary": | ||
| # Update existing package version | ||
| pkg["version"] = version | ||
| new_packages.append(pkg) | ||
| elementary_found = True | ||
| else: | ||
| new_packages.append(pkg) | ||
|
|
||
| if not elementary_found: | ||
| print( | ||
| "::error::Could not find elementary-data/elementary or " | ||
| "dbt-data-reliability entry in packages.yml" | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| data["packages"] = new_packages | ||
| with open(PACKAGES_FILE, "w") as f: | ||
| yaml.dump(data, f, default_flow_style=False, sort_keys=False) | ||
|
|
||
| # Append the helper comments for developer convenience | ||
| with open(PACKAGES_FILE, "a") as f: | ||
| f.write(HELPER_COMMENTS.format(version=version)) | ||
|
|
||
| print(f"Updated packages.yml to version {version}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| version = os.environ.get("PKG_VERSION", "") | ||
| if not version: | ||
| print("::error::PKG_VERSION environment variable is not set") | ||
| sys.exit(1) | ||
| bump_packages_version(version) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: elementary-data/elementary
Length of output: 622
PyYAML's
safe_load/dumpstrip all comments frompackages.yml.The file contains 7 substantive comments (e.g., version management notes for unreleased CLI versions), all of which are dropped during the round-trip through
yaml.safe_load()at lines 19–20 andyaml.dump()at lines 52–57. This contradicts the PR's stated goal of preserving commented content. Use a round-trip YAML editor that retains comments and formatting instead.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is by design. The script intentionally uses
yaml.safe_load()/yaml.dump()to strip comments, then re-appends the helper comments block explicitly (lines 58-59). This ensures the comments are always up-to-date with the correct version, regardless of what state the file was in before. Usingruamel.yamlfor round-trip preservation would add complexity without benefit here, since the comments need to be regenerated with the new version anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.