Skip to content
Open
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
33 changes: 31 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,37 @@ jobs:
echo "tmp_version_branch=v4" >> "$GITHUB_ENV"
- if: ${{ startsWith(github.event.release.tag_name, 'v5.' ) }}
run: |
echo "Setting version_branch to main"
echo "tmp_version_branch=main" >> "$GITHUB_ENV"
RELEASE_VERSION="${{ github.event.release.tag_name }}"
RELEASE_VERSION="${RELEASE_VERSION#v}"
RELEASE_MAJOR_MINOR=$(echo "$RELEASE_VERSION" | cut -d. -f1-2)

# getting this version from POM would require pulling the whole repo
MAIN_POM_VERSION=$(curl -fsSL "https://raw.githubusercontent.com/${{ github.repository }}/main/pom.xml" | python3 -c "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using a python script for this is way overkill. The previous solution was better, imo. Or we could use something as simple as yq '.project.version' pom.xml

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We are not cloning the repo in this job. So this is why I opted to pull the version like this. Of course we could pull the repo.

import xml.etree.ElementTree as ET, sys
root = ET.parse(sys.stdin).getroot()
ns = root.tag.split('}')[0].lstrip('{') if '}' in root.tag else ''
tag = '{' + ns + '}version' if ns else 'version'
v = root.find(tag)
if v is None:
sys.exit(1)
print(v.text)
")
if [ -z "$MAIN_POM_VERSION" ]; then
echo "Failed to determine main branch POM version"
exit 1
fi
MAIN_MAJOR_MINOR=$(echo "$MAIN_POM_VERSION" | cut -d. -f1-2)

echo "Release tag major.minor: $RELEASE_MAJOR_MINOR"
echo "Main branch major.minor: $MAIN_MAJOR_MINOR"

if [ "$RELEASE_MAJOR_MINOR" = "$MAIN_MAJOR_MINOR" ]; then
echo "Setting version_branch to main"
echo "tmp_version_branch=main" >> "$GITHUB_ENV"
else
echo "Setting version_branch to ${RELEASE_MAJOR_MINOR}.x"
echo "tmp_version_branch=${RELEASE_MAJOR_MINOR}.x" >> "$GITHUB_ENV"
fi
- if: ${{ env.tmp_version_branch == '' }}
name: Fail if version_branch is not set
run: |
Expand Down
Loading