Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Last active March 2, 2023 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save managedkaos/c6f170aeffd93cc11962fb006135c365 to your computer and use it in GitHub Desktop.
Save managedkaos/c6f170aeffd93cc11962fb006135c365 to your computer and use it in GitHub Desktop.
import re
import git
import os
repos = {
'terraform': 'https://github.com/hashicorp/terraform.git',
'aws-cli': 'https://github.com/aws/aws-cli.git',
}
for repo_name, repo_url in repos.items():
print(f"Repo: {repo_name}")
# Clone the repository to a local directory
local_dir = f"./{repo_name}"
# If the local directory already exists, use it as the existing repository
if os.path.exists(local_dir):
repo = git.Repo(local_dir)
# Otherwise, clone the repository to the local directory
else:
repo = git.Repo.clone_from(repo_url, local_dir)
# Get all tags in the repository
#tags = sorted(repo.tags, key=lambda t: t.commit.committed_date)
tags = repo.tags
print(f"\tTags: {len(tags)}")
# A dictionary to store the largest patched version for each minor version
largest_patched_versions = {}
# Loop through each tag
for tag in tags:
# Use regular expression to extract the major, minor, and patch versions
match = re.match(r'^v?(\d+)\.(\d+)\.(\d+)$', tag.name)
if match:
major_version = int(match.group(1))
minor_version = int(match.group(2))
patch_version = int(match.group(3))
# If the minor version is not yet in the dictionary, add it with the current tag
if minor_version not in largest_patched_versions:
largest_patched_versions[minor_version] = tag.name
# If the minor version is in the dictionary, check if the patch version is larger
else:
current_patch_version = int(largest_patched_versions[minor_version].split('.')[2])
if patch_version > current_patch_version:
largest_patched_versions[minor_version] = tag.name
# Print the largest patched version for each minor version
for minor_version, largest_patched_version in largest_patched_versions.items():
print(f"\t{largest_patched_version}")
gitdb==4.0.10
GitPython==3.1.31
smmap==5.0.0
/usr/bin/env python3 -m venv ./env
source ./env/bin/activate
/usr/bin/env python3 -m pip install --upgrade pip
/usr/bin/env python3 -m pip install --requirement requirements.txt
/usr/bin/env python3 list-terraform-awscli-github-tags.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment