Created
September 10, 2022 12:22
-
-
Save ppabcd/1441d22056a30d084da7138b1ab16bf9 to your computer and use it in GitHub Desktop.
Pre commit and only increment while release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE="${PWD}/.php_cs.service.php" | |
COMMAND="/usr/bin/php-cs-fixer" | |
CONFIG_URL="https://gist.githubusercontent.com/ppabcd/d0184b7ba0f05b9ed59bd0d12753a5a6/raw/f76e893696b205278d40412f6fd4a2e8e78b399f/.php_cs.service.php" | |
# Version and Release Manager | |
VERSION_FILE="${PWD}/.version" | |
RELEASE="${PWD}/release" | |
VERSION="0.1.0" | |
TEXT_VERSION="v0.1.0" | |
if [ -f "$FILE" ]; then | |
echo "$FILE exists." | |
else | |
echo "$FILE does not exits.\n" | |
echo "Downloading config file." | |
wget -c $CONFIG_URL | |
fi | |
if [ -f "$COMMAND" ]; then | |
echo "$COMMAND exists." | |
else | |
echo "$COMMAND does not exist." | |
wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer | |
[ "$UID" -eq 0 ] || exec sudo chmod +x php-cs-fixer && sudo mv php-cs-fixer /usr/bin/php-cs-fixer | |
fi | |
if [ -f "$RELEASE" ]; then | |
if [ -f "$VERSION_FILE" ]; then | |
# Read file | |
VERSION=$(cat "$VERSION_FILE") | |
# delete v from text | |
VERSION=${VERSION#v} | |
# increment version | |
VERSION=$(echo "$VERSION" | awk -F. '{$NF+=1; print}') | |
# replace space to . | |
VERSION=$(echo "$VERSION" | sed 's/ /./g') | |
# write version to file | |
TEXT_VERSION="v$VERSION" | |
echo "${TEXT_VERSION}" >"$VERSION_FILE" | |
echo "Version: $TEXT_VERSION" | |
else | |
echo "Version file does not exist. Generate v0.1.0" | |
echo "v0.1.0" >"$VERSION_FILE" | |
fi | |
echo "Release file exists. Delete it." | |
git add "$VERSION_FILE" | |
git tag -a "${TEXT_VERSION}" -m "Release $TEXT_VERSION" | |
git push origin "${TEXT_VERSION}" | |
rm "$RELEASE" | |
fi | |
/usr/bin/php-cs-fixer fix . --config=$FILE | |
for file in $(git diff --cached --name-only | grep -E '\.(php)$') | |
do | |
$(git add "$file") | |
echo "Added updated file : ${file}" | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment