Skip to content
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

Fix the update-collections script - bump release in spec and build vendored_collections.yml correctly #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update the release number in the changelog entry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



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