-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |