Skip to content

Commit

Permalink
Add branch parsing script
Browse files Browse the repository at this point in the history
  • Loading branch information
rasa-jmac committed Dec 20, 2023
1 parent 57f574c commit 70e8905
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scripts/get_tags_from_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import ast
import os
import subprocess
import sys

def get_tags_from_branches(branches):
tags = []

for branch in branches:
# Strip ".x" suffix from branch name.
branch_name = branch.rstrip('.x')

# Try to fetch all git tags for the given branch.
# `output` will be sorted in the descending order.
try:
output = subprocess.check_output(
f'git tag | sort -r -V | grep -E "^{branch_name}.[0-9]+$"',
shell=True,
universal_newlines=True
)
except subprocess.CalledProcessError:
print(f'Failed to retrieve tags for `{branch_name}` branch.')
continue

branch_tags = output.strip().split('\n')
tags.extend(branch_tags)

return tags

input_branches = sys.argv[1]

# Convert stringified list to a Python list.
branches = ast.literal_eval(input_branches)
tags = get_tags_from_branches(branches)

print(f'{tags}')

with open(os.environ['GITHUB_OUTPUT'], 'a') as github_output_file:
print(f'tags={tags}', file=github_output_file)

0 comments on commit 70e8905

Please sign in to comment.