Skip to content

Commit 8229635

Browse files
Fix bump-version to use YAML parsing for packages.yml updates
The sed-based version replacement in bump-version.yml had two issues: 1. It only matched 'version: X.Y.Z' patterns, missing the case where master has a git hash reference for dbt-data-reliability 2. It also matched commented-out version lines Replace the sed commands for packages.yml with a Python script that properly parses the YAML and handles both cases: - Updates an existing package version reference - Replaces a git hash reference with a proper package version The sed replacement for docs snippets and pyproject.toml is kept as-is since those files always have a version pattern. Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent 2f98ef7 commit 8229635

2 files changed

Lines changed: 86 additions & 8 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import sys
3+
4+
import yaml
5+
6+
PACKAGES_FILE = "./elementary/monitor/dbt_project/packages.yml"
7+
HELPER_COMMENTS = """
8+
# NOTE - for unreleased CLI versions we often need to update the package version to a commit hash (please leave this
9+
# commented, so it will be easy to access)
10+
# - git: https://github.com/elementary-data/dbt-data-reliability.git
11+
# revision: <COMMIT_HASH>
12+
# When releasing a new version of the package, if the current version is using a commit hash, update the version to the new version.
13+
# - package: elementary-data/elementary
14+
# version: {version}
15+
"""
16+
17+
18+
def bump_packages_version(version: str) -> None:
19+
with open(PACKAGES_FILE) as f:
20+
data = yaml.safe_load(f)
21+
22+
packages = data.get("packages") or []
23+
24+
new_packages = []
25+
elementary_found = False
26+
for pkg in packages:
27+
if "git" in pkg and "dbt-data-reliability" in pkg["git"]:
28+
# Replace git hash reference with proper package reference
29+
new_packages.append(
30+
{
31+
"package": "elementary-data/elementary",
32+
"version": version,
33+
}
34+
)
35+
elementary_found = True
36+
elif pkg.get("package") == "elementary-data/elementary":
37+
# Update existing package version
38+
pkg["version"] = version
39+
new_packages.append(pkg)
40+
elementary_found = True
41+
else:
42+
new_packages.append(pkg)
43+
44+
if not elementary_found:
45+
print(
46+
"::error::Could not find elementary-data/elementary or "
47+
"dbt-data-reliability entry in packages.yml"
48+
)
49+
sys.exit(1)
50+
51+
data["packages"] = new_packages
52+
with open(PACKAGES_FILE, "w") as f:
53+
yaml.dump(data, f, default_flow_style=False, sort_keys=False)
54+
55+
# Append the helper comments for developer convenience
56+
with open(PACKAGES_FILE, "a") as f:
57+
f.write(HELPER_COMMENTS.format(version=version))
58+
59+
print(f"Updated packages.yml to version {version}")
60+
61+
62+
if __name__ == "__main__":
63+
version = os.environ.get("PKG_VERSION", "")
64+
if not version:
65+
print("::error::PKG_VERSION environment variable is not set")
66+
sys.exit(1)
67+
bump_packages_version(version)

.github/workflows/bump-version.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,27 @@ jobs:
6161
- name: Bump version
6262
run: |
6363
sed -i 's/^version = "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"/version = "${{ inputs.cli-version }}"/' ./pyproject.toml
64-
- name: Bump version for package (using input)
65-
if: ${{ needs.validate-version.outputs.validated-dbt-package-version != ''}}
64+
- name: Setup Python
65+
uses: actions/setup-python@v5
66+
with:
67+
python-version: "3.10"
68+
- name: Install PyYAML
69+
run: pip install pyyaml
70+
- name: Determine package version
71+
id: pkg-version
6672
run: |
67-
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.validated-dbt-package-version }}/' ./elementary/monitor/dbt_project/packages.yml
68-
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.validated-dbt-package-version }}/' ./docs/_snippets/quickstart-package-install.mdx
69-
- name: Bump version for package (using default)
70-
if: ${{ needs.validate-version.outputs.validated-dbt-package-version == ''}}
73+
if [ -n "${{ needs.validate-version.outputs.validated-dbt-package-version }}" ]; then
74+
echo "version=${{ needs.validate-version.outputs.validated-dbt-package-version }}" >> $GITHUB_OUTPUT
75+
else
76+
echo "version=${{ needs.validate-version.outputs.default-dbt-package-version }}" >> $GITHUB_OUTPUT
77+
fi
78+
- name: Bump version for packages.yml
79+
env:
80+
PKG_VERSION: ${{ steps.pkg-version.outputs.version }}
81+
run: python .github/scripts/bump_packages_version.py
82+
- name: Bump version for docs snippet
7183
run: |
72-
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.default-dbt-package-version }}/' ./elementary/monitor/dbt_project/packages.yml
73-
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ needs.validate-version.outputs.default-dbt-package-version }}/' ./docs/_snippets/quickstart-package-install.mdx
84+
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ steps.pkg-version.outputs.version }}/' ./docs/_snippets/quickstart-package-install.mdx
7485
- name: Commit changes
7586
run: git commit -am "release v${{ inputs.cli-version }}"
7687
- name: Push code

0 commit comments

Comments
 (0)