Anouar di Kali
01/03/2024, 2:05 PM/*
* File: FileName.kt
* Author: Author name
* Created on: time
* Description:
* @since : [Project Version]
*/
tapchicoma
01/03/2024, 2:35 PM[Project version]
and replaces it with actual versionMessias Junior
01/03/2024, 2:43 PMsince
is the version where the file was created, isnt? So I think automating it could be a bit misleadingVampire
01/03/2024, 2:54 PMVampire
01/03/2024, 2:55 PM[Project Version]
you could also just put the actual version there.
What is the use-case?Anouar di Kali
01/03/2024, 3:04 PMAnouar di Kali
01/03/2024, 4:05 PM# Extract the version number from build.gradle.kts
VERSION=$(grep -Eo 'version\s*=\s*"[^"]+"' build.gradle.kts | sed -E 's/version\s*=\s*"([^"]+)"/\1/')
#Or Extract the version number from the branch name assuming the format is like 'featurevX.Y'
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
VERSION=$(echo $BRANCH_NAME | grep -Eo '[vV][A-Z0-9][^ ]*')
# Find all modified .kt files
MODIFIED_FILES=$(git diff --cached --name-only | grep '\.kt$')
# Check if the version number was found
if [ -z "$VERSION" ]; then
# If version number was not found, check if any modified file contains @version
for file in $MODIFIED_FILES; do
if grep -q "@version" "$file"; then
echo "Error: @version found in $file but unable to extract version from build.gradle.kts."
exit 1
fi
done
else
# If version number was found, replace @version with the extracted version in all modified files
for file in $MODIFIED_FILES; do
sed -i "s/@version/${VERSION}/g" "$file"
git add "$file"
done
fi