Skip to content

Commit

Permalink
improve release script
Browse files Browse the repository at this point in the history
  • Loading branch information
lofcz committed Jan 9, 2025
1 parent 3e54753 commit 6297034
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
NEW_VERSION=""
# Function to compare version numbers
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
# Check each project for changes and update versions
for proj in $(find . -name "*.csproj"); do
PROJECT_NAME=$(basename "$proj")
Expand All @@ -46,6 +51,11 @@ jobs:
# Get current version from csproj
CURRENT_VERSION=$(grep -oP '(?<=<Version>).*(?=</Version>)' "$proj" || echo "0.0.0")
if [ -z "$CURRENT_VERSION" ]; then
echo "Warning: Could not find version in $proj"
continue
fi
# Split version into parts
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
Expand All @@ -57,24 +67,37 @@ jobs:
# Calculate new version based on release type
case "${{ github.event.inputs.release_type }}" in
"major")
NEW_VERSION="$((MAJOR + 1)).0.0"
PROJECT_NEW_VERSION="$((MAJOR + 1)).0.0"
;;
"minor")
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
PROJECT_NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
"patch")
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
PROJECT_NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
# Update version in csproj
sed -i "s/<Version>.*<\/Version>/<Version>${NEW_VERSION}<\/Version>/g" "$proj"
sed -i "s/<Version>.*<\/Version>/<Version>${PROJECT_NEW_VERSION}<\/Version>/g" "$proj"
CHANGED_PROJECTS="$CHANGED_PROJECTS$PROJECT_NAME -> $NEW_VERSION\n"
CHANGED_PROJECTS="$CHANGED_PROJECTS$PROJECT_NAME -> $PROJECT_NEW_VERSION\n"
SHOULD_RELEASE="true"
# Update NEW_VERSION if this project's version is higher
if [ -z "$NEW_VERSION" ] || version_gt "$PROJECT_NEW_VERSION" "$NEW_VERSION"; then
NEW_VERSION="$PROJECT_NEW_VERSION"
echo "New highest version: $NEW_VERSION from $PROJECT_NAME"
fi
fi
done
if [ -z "$NEW_VERSION" ]; then
echo "No version changes detected"
exit 0
fi
echo "Final highest version will be: v$NEW_VERSION"
# Set environment variables for next steps
echo "CHANGED_PROJECTS<<EOF" >> $GITHUB_ENV
echo -e "$CHANGED_PROJECTS" >> $GITHUB_ENV
Expand Down Expand Up @@ -146,11 +169,18 @@ jobs:

# Commit version updates and create tag
- name: Commit version updates
if: env.SHOULD_RELEASE == 'true'
if: env.SHOULD_RELEASE == 'true' && env.NEW_VERSION != ''
run: |
if [ -z "${{ env.NEW_VERSION }}" ]; then
echo "Error: NEW_VERSION is not set"
exit 1
fi
echo "Creating release for version v${{ env.NEW_VERSION }}"
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update project versions"
git commit -m "Update project versions to v${{ env.NEW_VERSION }}"
git tag -a "v${{ env.NEW_VERSION }}" -m "Release v${{ env.NEW_VERSION }}"
git push --follow-tags

0 comments on commit 6297034

Please sign in to comment.