mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
update task file and bump script
This commit is contained in:
@@ -0,0 +1,189 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Colors and styles
|
||||||
|
readonly RESET='\033[0m'
|
||||||
|
readonly BOLD='\033[1m'
|
||||||
|
readonly BLUE='\033[34m'
|
||||||
|
readonly GREEN='\033[32m'
|
||||||
|
readonly RED='\033[31m'
|
||||||
|
readonly YELLOW='\033[33m'
|
||||||
|
|
||||||
|
# Emojis
|
||||||
|
readonly ROCKET="🚀"
|
||||||
|
readonly UPDATE="🔄"
|
||||||
|
readonly PACKAGE="📦"
|
||||||
|
readonly SUCCESS="✨"
|
||||||
|
readonly ERROR="❌"
|
||||||
|
readonly WARNING="⚠️"
|
||||||
|
readonly CHECK="✓"
|
||||||
|
|
||||||
|
# Header
|
||||||
|
print_header() {
|
||||||
|
echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}"
|
||||||
|
echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher Version ${ROCKET} │${RESET}"
|
||||||
|
echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${RESET}\n"
|
||||||
|
echo -e " Date : $(date -u '+%Y-%m-%d %H:%M:%S') UTC"
|
||||||
|
echo -e " User : $(whoami)"
|
||||||
|
echo -e " Directory: $(pwd)\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Version validation
|
||||||
|
validate_version() {
|
||||||
|
local version=$1
|
||||||
|
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo -e "\n${RED}${ERROR} Invalid version format: $version${RESET}"
|
||||||
|
echo -e " Version must be in format X.Y.Z (e.g., 2.1.6)\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get current version from Flasher class
|
||||||
|
get_current_version() {
|
||||||
|
local file="src/Prime/Flasher.php"
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
local version=$(grep -o "const VERSION = '[0-9]\+\.[0-9]\+\.[0-9]\+'" "$file" | grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+")
|
||||||
|
echo "$version"
|
||||||
|
else
|
||||||
|
echo -e "${RED}${ERROR} Flasher.php not found in src/Prime/Flasher.php${RESET}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update composer.json file
|
||||||
|
update_composer_file() {
|
||||||
|
local file=$1
|
||||||
|
local current_version=$2
|
||||||
|
local new_version=$3
|
||||||
|
|
||||||
|
# Create a temporary file
|
||||||
|
local tmp_file="${file}.tmp"
|
||||||
|
|
||||||
|
# Use jq with 4-space indentation
|
||||||
|
if command -v jq >/dev/null 2>&1; then
|
||||||
|
jq --indent 4 --arg cv "^${current_version}" --arg nv "^${new_version}" '
|
||||||
|
walk(
|
||||||
|
if type == "object" and has("require") then
|
||||||
|
.require |= with_entries(
|
||||||
|
if .key | startswith("php-flasher/") then
|
||||||
|
.value = $nv
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
' "$file" > "$tmp_file"
|
||||||
|
else
|
||||||
|
# Fallback to sed for simple replacement
|
||||||
|
sed -E "s/\"php-flasher\/[^\"]+\": \"\\^${current_version}\"/\"\\0\": \"^${new_version}\"/" "$file" > "$tmp_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the temporary file exists and has content
|
||||||
|
if [ -s "$tmp_file" ]; then
|
||||||
|
mv "$tmp_file" "$file"
|
||||||
|
echo " ${CHECK} Updated $file"
|
||||||
|
else
|
||||||
|
echo " ${WARNING} Failed to update $file"
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update package.json file
|
||||||
|
update_package_file() {
|
||||||
|
local file=$1
|
||||||
|
local current_version=$2
|
||||||
|
local new_version=$3
|
||||||
|
|
||||||
|
# Create a temporary file
|
||||||
|
local tmp_file="${file}.tmp"
|
||||||
|
|
||||||
|
# Use jq with 4-space indentation
|
||||||
|
if command -v jq >/dev/null 2>&1; then
|
||||||
|
jq --indent 4 --arg cv "^${current_version}" --arg nv "^${new_version}" --arg v "${new_version}" '
|
||||||
|
.version = $v |
|
||||||
|
if has("peerDependencies") then
|
||||||
|
.peerDependencies |= with_entries(
|
||||||
|
if .key | startswith("@flasher/") then
|
||||||
|
.value = $nv
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end |
|
||||||
|
if has("dependencies") then
|
||||||
|
.dependencies |= with_entries(
|
||||||
|
if .key | startswith("@flasher/") then
|
||||||
|
.value = $nv
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
' "$file" > "$tmp_file"
|
||||||
|
else
|
||||||
|
# Fallback to sed for simple replacement
|
||||||
|
sed -E -e "s/\"version\": \"${current_version}\"/\"version\": \"${new_version}\"/" \
|
||||||
|
-e "s/\"@flasher\/[^\"]+\": \"\\^${current_version}\"/\"\\0\": \"^${new_version}\"/" \
|
||||||
|
"$file" > "$tmp_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the temporary file exists and has content
|
||||||
|
if [ -s "$tmp_file" ]; then
|
||||||
|
mv "$tmp_file" "$file"
|
||||||
|
echo " ${CHECK} Updated $file"
|
||||||
|
else
|
||||||
|
echo " ${WARNING} Failed to update $file"
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update version in files
|
||||||
|
update_version() {
|
||||||
|
local current_version=$1
|
||||||
|
local new_version=$2
|
||||||
|
|
||||||
|
echo -e " ${UPDATE} Updating version numbers ($current_version → $new_version)\n"
|
||||||
|
|
||||||
|
# Update PHP class version
|
||||||
|
echo -e " ${PACKAGE} Updating Flasher class version..."
|
||||||
|
if [ -f "src/Prime/Flasher.php" ]; then
|
||||||
|
sed -i '' "s/const VERSION = '$current_version'/const VERSION = '$new_version'/" src/Prime/Flasher.php
|
||||||
|
echo -e " ${CHECK} Updated src/Prime/Flasher.php"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update composer.json files in src directory
|
||||||
|
echo -e "\n ${PACKAGE} Updating composer.json files..."
|
||||||
|
find src -name "composer.json" -type f | while read -r file; do
|
||||||
|
update_composer_file "$file" "$current_version" "$new_version"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Update package.json files in src directory
|
||||||
|
echo -e "\n ${PACKAGE} Updating package.json files..."
|
||||||
|
find src -name "package.json" -type f | while read -r file; do
|
||||||
|
update_package_file "$file" "$current_version" "$new_version"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "\n ${SUCCESS} Version bump complete!\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main execution
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo -e "${RED}${ERROR} Version number is required${RESET}"
|
||||||
|
echo -e "Usage: $0 <version>\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_header
|
||||||
|
new_version=$1
|
||||||
|
current_version=$(get_current_version)
|
||||||
|
validate_version "$new_version"
|
||||||
|
update_version "$current_version" "$new_version"
|
||||||
+70
-159
@@ -5,117 +5,63 @@ vars:
|
|||||||
CURRENT_VERSION: '2.1.5'
|
CURRENT_VERSION: '2.1.5'
|
||||||
NEW_VERSION: '{{.CLI_ARGS | default ""}}'
|
NEW_VERSION: '{{.CLI_ARGS | default ""}}'
|
||||||
|
|
||||||
HEADER: |
|
|
||||||
╭──────────────────────────────────────────╮
|
|
||||||
│ 🚀 PHP-Flasher Tasks Runner 🚀 │
|
|
||||||
╰──────────────────────────────────────────╯
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
desc: Show available tasks
|
desc: Show available tasks
|
||||||
cmds:
|
cmds:
|
||||||
- echo "{{.HEADER}}"
|
|
||||||
- task -l
|
- task -l
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
version:bump:
|
bump:
|
||||||
desc: Bump version in all necessary files
|
desc: Bump version in all necessary files
|
||||||
summary: |
|
|
||||||
Update version numbers across the project
|
|
||||||
Usage: task version:bump 2.1.6
|
|
||||||
cmds:
|
|
||||||
- echo "{{.HEADER}}"
|
|
||||||
- |
|
|
||||||
if [ -z "{{.NEW_VERSION}}" ]; then
|
|
||||||
echo "Error: Version number is required"
|
|
||||||
echo "Usage: task version:bump 2.1.6"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo " Date : {{.DATE}} UTC"
|
|
||||||
echo " Task : Version Bump ({{.CURRENT_VERSION}} -> {{.NEW_VERSION}})"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Update PHP class version
|
|
||||||
echo " 🔄 Updating Flasher class version..."
|
|
||||||
sed -i '' "s/const VERSION = '{{.CURRENT_VERSION}}'/const VERSION = '{{.NEW_VERSION}}'/" src/Prime/Flasher.php
|
|
||||||
|
|
||||||
# Update composer.json files
|
|
||||||
echo " 📦 Updating composer.json files..."
|
|
||||||
find . -name "composer.json" -not -path "./vendor/*" -exec sed -i '' "s/\"php-flasher\/.*\": \"^{{.CURRENT_VERSION}}\"/\"php-flasher\/.*\": \"^{{.NEW_VERSION}}\"/" {} \;
|
|
||||||
|
|
||||||
# Update package.json files
|
|
||||||
echo " 📦 Updating package.json files..."
|
|
||||||
find . -name "package.json" -not -path "./node_modules/*" -exec sed -i '' "s/\"version\": \"{{.CURRENT_VERSION}}\"/\"version\": \"{{.NEW_VERSION}}\"/" {} \;
|
|
||||||
find . -name "package.json" -not -path "./node_modules/*" -exec sed -i '' "s/\"@flasher\/.*\": \"^{{.CURRENT_VERSION}}\"/\"@flasher\/.*\": \"^{{.NEW_VERSION}}\"/" {} \;
|
|
||||||
|
|
||||||
echo " ✨ Version bump complete!"
|
|
||||||
silent: true
|
|
||||||
|
|
||||||
version:validate:
|
|
||||||
desc: Validate version number format
|
|
||||||
vars:
|
|
||||||
VERSION_REGEX: '^[0-9]+\.[0-9]+\.[0-9]+$'
|
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
if [[ ! "{{.NEW_VERSION}}" =~ {{.VERSION_REGEX}} ]]; then
|
if [ -f "bin/bump" ]; then
|
||||||
echo "Error: Invalid version format. Must be X.Y.Z (e.g., 2.1.6)"
|
chmod +x bin/bump
|
||||||
exit 1
|
./bin/bump {{.NEW_VERSION}}
|
||||||
|
else
|
||||||
|
echo " ❌ Bump script not found in bin/bump"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
release:
|
|
||||||
desc: Create and publish a new release
|
|
||||||
cmds:
|
|
||||||
- task: version:validate
|
|
||||||
- task: version:bump
|
|
||||||
- task: lint
|
|
||||||
- task: split
|
|
||||||
- task: npm:publish
|
|
||||||
- task: git:tag
|
|
||||||
silent: true
|
|
||||||
|
|
||||||
split:
|
split:
|
||||||
desc: Split repositories
|
desc: Split repositories
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
echo "{{.HEADER}}"
|
if [ -f "bin/split" ]; then
|
||||||
echo " Date : {{.DATE}} UTC"
|
chmod +x bin/split
|
||||||
echo " Task : Repository Split"
|
./bin/split
|
||||||
echo
|
else
|
||||||
|
echo " ❌ Split script not found in bin/split"
|
||||||
echo " 🔄 Splitting repositories..."
|
exit 1
|
||||||
php bin/split
|
fi
|
||||||
echo " ✨ Split complete!"
|
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
npm:publish:
|
npm:publish:
|
||||||
desc: Publish NPM packages
|
desc: Publish NPM packages
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
echo "{{.HEADER}}"
|
if [ -f "bin/npm" ]; then
|
||||||
echo " Date : {{.DATE}} UTC"
|
chmod +x bin/npm
|
||||||
echo " Task : NPM Package Publishing"
|
./bin/npm {{.NEW_VERSION}}
|
||||||
echo
|
else
|
||||||
|
echo " ❌ NPM script not found in bin/npm"
|
||||||
echo " 📦 Publishing NPM packages..."
|
exit 1
|
||||||
php bin/npm {{.NEW_VERSION}}
|
fi
|
||||||
echo " ✨ NPM publish complete!"
|
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
git:tag:
|
git:tag:
|
||||||
desc: Create and push git tags
|
desc: Create and push git tags
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
echo "{{.HEADER}}"
|
if [ -f "bin/git-tag" ]; then
|
||||||
echo " Date : {{.DATE}} UTC"
|
chmod +x bin/git-tag
|
||||||
echo " Task : Git Tagging"
|
./bin/git-tag {{.NEW_VERSION}}
|
||||||
echo
|
else
|
||||||
|
echo " ❌ Git-tag script not found in bin/git-tag"
|
||||||
echo " 🏷️ Creating git tag v{{.NEW_VERSION}}..."
|
exit 1
|
||||||
git tag -a "v{{.NEW_VERSION}}" -m "Release v{{.NEW_VERSION}}"
|
fi
|
||||||
git push origin "v{{.NEW_VERSION}}"
|
|
||||||
echo " ✨ Git tagging complete!"
|
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
status:
|
status:
|
||||||
@@ -123,95 +69,60 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
if [ -f "bin/status" ]; then
|
if [ -f "bin/status" ]; then
|
||||||
chmod +x bin/status
|
chmod +x bin/status
|
||||||
./bin/status
|
./bin/status
|
||||||
else
|
else
|
||||||
echo " ❌ Status script not found in bin/status"
|
echo " ❌ Status script not found in bin/status"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
silent: true
|
||||||
|
|
||||||
|
lint:
|
||||||
|
desc: Analyze code quality and standards
|
||||||
|
cmds:
|
||||||
|
- |
|
||||||
|
if [ -f "bin/lint" ]; then
|
||||||
|
chmod +x bin/lint
|
||||||
|
./bin/lint
|
||||||
|
else
|
||||||
|
echo " ❌ Lint script not found in bin/lint"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
update:
|
update:
|
||||||
desc: Update project dependencies and rebuild assets
|
desc: Update project dependencies and rebuild assets
|
||||||
cmds:
|
cmds:
|
||||||
- echo "{{.HEADER}}"
|
|
||||||
- |
|
- |
|
||||||
echo " Date : {{.DATE}} UTC"
|
if [ -f "bin/update" ]; then
|
||||||
echo " Task : Update Dependencies"
|
chmod +x bin/update
|
||||||
echo
|
./bin/update
|
||||||
|
else
|
||||||
echo " 📦 Composer Dependencies"
|
echo " ❌ Update script not found in bin/update"
|
||||||
composer update --prefer-lowest -W
|
exit 1
|
||||||
echo " ✓ Dependencies updated successfully"
|
fi
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🔍 NPM Updates Check"
|
|
||||||
npm run ncu || echo " ⚠️ NPM check failed, continuing..."
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 📦 NPM Dependencies"
|
|
||||||
npm install --force || echo " ⚠️ NPM install failed, continuing..."
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🏗️ Building Assets"
|
|
||||||
npm run build || echo " ⚠️ Build failed, continuing..."
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " ✨ Update Complete"
|
|
||||||
echo " ✓ Process finished successfully"
|
|
||||||
silent: true
|
|
||||||
|
|
||||||
lint:
|
|
||||||
desc: Analyze code quality and standards
|
|
||||||
cmds:
|
|
||||||
- echo "{{.HEADER}}"
|
|
||||||
- |
|
|
||||||
echo " Date : {{.DATE}} UTC"
|
|
||||||
echo " Task : Code Quality Check"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🔍 Running Rector"
|
|
||||||
php vendor/bin/rector || echo " ⚠️ Rector found issues"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🎨 Running PHP-CS-Fixer"
|
|
||||||
php vendor/bin/php-cs-fixer fix -v || echo " ⚠️ CS-Fixer found issues"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🔬 Running PHPStan"
|
|
||||||
php vendor/bin/phpstan analyse --memory-limit=-1 || echo " ⚠️ PHPStan found issues"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 📝 Validating Composer Files"
|
|
||||||
composer validate --strict || echo " ⚠️ Validation failed"
|
|
||||||
find src/ -name "composer.json" -exec composer validate --strict {} \; || echo " ⚠️ Package validation failed"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🔎 Running PHPLint"
|
|
||||||
php vendor/bin/phplint || echo " ⚠️ PHPLint found issues"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " 🧪 Running PHPUnit Tests"
|
|
||||||
php vendor/bin/phpunit || echo " ⚠️ Tests failed"
|
|
||||||
echo
|
|
||||||
|
|
||||||
echo " ✨ Quality Check Complete"
|
|
||||||
echo " ✓ All checks finished"
|
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
docs:build:
|
docs:build:
|
||||||
desc: Build documentation
|
desc: Build documentation
|
||||||
dir: docs/
|
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
echo "{{.HEADER}}"
|
if [ -f "bin/docs" ]; then
|
||||||
echo " Date : {{.DATE}} UTC"
|
chmod +x bin/docs
|
||||||
echo " Task : Build Documentation"
|
./bin/docs build
|
||||||
echo
|
else
|
||||||
|
echo " ❌ Docs script not found in bin/docs"
|
||||||
echo " 📚 Installing dependencies"
|
exit 1
|
||||||
npm install --force
|
fi
|
||||||
|
silent: true
|
||||||
echo " 🏗️ Building documentation"
|
|
||||||
npm run build
|
release:
|
||||||
|
desc: Create and publish a new release
|
||||||
|
cmds:
|
||||||
|
- task: validate
|
||||||
|
- task: bump
|
||||||
|
- task: lint
|
||||||
|
- task: split
|
||||||
|
- task: npm:publish
|
||||||
|
- task: git:tag
|
||||||
silent: true
|
silent: true
|
||||||
|
|||||||
Reference in New Issue
Block a user