Skip to content

fix: release trigger #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 3 additions & 22 deletions .github/workflows/release-trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@ jobs:
run: |
git config --global user.name "SDK Releaser Bot"
git config --global user.email "[email protected]"

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

48 changes: 48 additions & 0 deletions scripts/helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Check if the directory is provided as an argument
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "Usage: $0 <directory> [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
17 changes: 17 additions & 0 deletions scripts/trigger_script.sh
Original file line number Diff line number Diff line change
@@ -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
Loading