diff --git a/.github/workflows/release-trigger.yaml b/.github/workflows/release-trigger.yaml index 7533a0e43..489200cf4 100644 --- a/.github/workflows/release-trigger.yaml +++ b/.github/workflows/release-trigger.yaml @@ -16,25 +16,6 @@ jobs: run: | git config --global user.name "SDK Releaser Bot" git config --global user.email "noreply@stackit.de" - - for file in $(git diff --name-only HEAD~1..HEAD | grep pyproject.toml); do - # Extract the change regarding the version from the pyproject.toml file - version_changes=$(git diff HEAD~1..HEAD $file | grep "version =") - # Check if the extracted change is not empty - if [ -n "$version_changes" ]; then - # Split all found version changes, so we can compare the old and new version. - splitted_version_changes=($(echo "$version_changes" | grep -oP '(?<=version = )[^ ]*')) - # Only create a tag if there has been an actual change in the version, not just a format change. - if [ $(echo "${splitted_version_changes[@]}" | tr ' ' '\n' | sort -u | wc -l) -ne 1 ]; then - dirpath=$(dirname $file) - # Extract just the version number - current_version=$(grep -o "version = .*" ${file} | cut -d '=' -f 2-) - dirpath=$(dirname $file) - cleaned_version=$(echo "$current_version" | tr -d '" ') - # Create the tag based on the updated service and the new version - tag=$(echo "${dirpath}/${cleaned_version}") - git tag -a $tag -m "Release $cleaned_version" - git push origin tag $tag - fi - fi - done + + scripts/trigger_script.sh + \ No newline at end of file diff --git a/scripts/helper.sh b/scripts/helper.sh new file mode 100755 index 000000000..77972dcb5 --- /dev/null +++ b/scripts/helper.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Check if the directory is provided as an argument +if [ $# -lt 1 ] || [ $# -gt 2 ]; then + echo "Usage: $0 [option]" + echo "Options:" + echo " -v | --version Print just the version number" + echo " -p | --path-version Print the concatenation of the path and the version" + exit 1 +fi + +# Check if the directory exists +if [ ! -d "$1" ]; then + echo "Directory '$1' does not exist" + exit 1 +fi + +# Append a trailing slash to the path if it's not already present +if [ "${1: -1}" != "/" ]; then + path="$1/" +else + path="$1" +fi + +# Change into the directory and run the command +cd "$path" || exit 1 +version=$(poetry version) + +# Get the version number +version_number="${version##* }" + +# Get the path and version string +path_version="$path$version_number" + +# Handle options +if [ $# -eq 1 ]; then + # Default behavior: print just the version number + echo "$version_number" +elif [ "$2" = "-v" ] || [ "$2" = "--version" ]; then + # Print just the version number + echo "$version_number" +elif [ "$2" = "-p" ] || [ "$2" = "--path-version" ]; then + # Print the concatenation of the path and the version + echo "$path_version" +else + echo "Invalid option: '$2'" + exit 1 +fi \ No newline at end of file diff --git a/scripts/trigger_script.sh b/scripts/trigger_script.sh new file mode 100755 index 000000000..d3676a804 --- /dev/null +++ b/scripts/trigger_script.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Check all pyproject.toml files that have changed +for file in $(git diff --name-only HEAD~1..HEAD | grep pyproject.toml); do + # Extract the current version and build the expected tag + dirpath=$(dirname $file) + expected_tag=$(scripts/helper.sh $dirpath --path-version) + version=$(scripts/helper.sh $dirpath) + # Check if the tag already exists + if git rev-parse --verify $expected_tag^{tag} &> /dev/null; then + echo "Tag '$expected_tag' already exists." + else + echo "Tag '$expected_tag' does not exist. Creating new tag to trigger release." + git tag -a $expected_tag -m "Release $version" + git push origin tag $expected_tag + fi +done