-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathbump_packages_version.py
More file actions
67 lines (55 loc) · 2.19 KB
/
bump_packages_version.py
File metadata and controls
67 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)