Skip to content

Commit

Permalink
Fix the update-collections script - bump release in spec and build ve…
Browse files Browse the repository at this point in the history
…ndored_collections.yml correctly (#142)

* Bump release in the spec file

* Correctly update vendored_collections.yml in the same order

* Return mistakenly removed ansible.posix to vendored_collections.yml

The script removed it in e26e356 and
that's incorrect

* Print exiting without change for visibility
  • Loading branch information
spetrosi authored Apr 6, 2022
1 parent b9facf2 commit 2f15941
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
32 changes: 26 additions & 6 deletions update_vendored_collections/update_vendored_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,24 @@ def spec_add_changelog(content, collection_tarballs, lines):
return content


def spec_bump_release(content):
print("Bumping release in the spec file")
cur_release = re.search(r"^Release: (\d+)", content, flags=re.MULTILINE).group(1)
new_release = str(int(cur_release) + 1)
content = re.sub(
r"^Release: \d+", "Release: " + new_release, content, flags=re.MULTILINE
)
return content


def update_spec(collection_tarballs, repo):
with open(os.path.join(repo, "linux-system-roles.spec"), "r") as f:
content = f.read()
f.seek(0)
lines = iter(f.readlines())
content = spec_replace_sources(content, collection_tarballs)
content = spec_add_changelog(content, collection_tarballs, lines)
content = spec_bump_release(content)
with open(os.path.join(repo, "linux-system-roles.spec"), "w") as f:
f.write(content)

Expand Down Expand Up @@ -169,15 +180,22 @@ def repo_force_push(repo, remote, branch):
def update_vendored_collections_yml(hsh, collection_tarballs, requirements):
collections_versions = {}
updated_requirements = {"collections": []}
collections_versions_sorted = {}
for collection, tarball in collection_tarballs.items():
version = re.sub(".tar.gz", "", re.sub(".*-", "", tarball))
collections_versions.update({collection: version})
for coll in hsh["collections"]:
for collection, version in collections_versions.items():
if coll["name"] == collection:
updated_requirements["collections"].append(
{"name": coll["name"], "version": version}
)
if coll["name"] not in collections_versions.keys():
collections_versions.update({coll["name"]: coll["version"]})
# Sort collections to be in the same order as hsh["collections"]
for coll in hsh["collections"]:
collections_versions_sorted.update(
{coll["name"]: collections_versions[coll["name"]]}
)
for collection, version in collections_versions_sorted.items():
updated_requirements["collections"].append(
{"name": collection, "version": version}
)
print(f"Update {requirements} with fresh collections versions")
with open(requirements, "w") as f:
yaml.dump(updated_requirements, f)
Expand Down Expand Up @@ -221,7 +239,9 @@ def main():

for coll in hsh["collections"]:
collection_tarballs.update(get_updated_collection_tarball(coll))
if len(collection_tarballs) != 0:
if len(collection_tarballs) == 0:
print("No updates found, exiting")
else:
"""Make a CentOS scratch build"""
clone_repo(centos_repo, centos_branch, centpkg_cmd)
copy_tarballs_to_repo(collection_tarballs, centos_repo)
Expand Down
3 changes: 3 additions & 0 deletions update_vendored_collections/vendored_collections.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
collections:
- name: ansible.posix
version: 1.3.0
- name: community.general
version: 4.6.1

0 comments on commit 2f15941

Please sign in to comment.