This commit is contained in:
Younes ENNAJI
2025-02-21 20:12:25 +01:00
parent 3d5d8d3c9a
commit fdbc5fd270
2 changed files with 115 additions and 87 deletions
+53 -39
View File
@@ -33,36 +33,74 @@ readonly NPM_PACKAGES=(
# Print functions # Print functions
print_header() { print_header() {
echo -e "${BOLD}${BLUE}${ROCKET} PHP-Flasher NPM Release ${ROCKET}${RESET}" echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}"
echo -e "\n" echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher NPM Release ${ROCKET} │${RESET}"
echo -e "${DIM}Generated on: $(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}" echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${RESET}\n"
echo -e "${DIM}By: $(whoami)${RESET}" echo -e " ${DIM}Date : $(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}"
echo -e "${DIM}Working Directory: $(pwd)${RESET}" echo -e " ${DIM}User : $(whoami)${RESET}"
echo -e " ${DIM}Directory: $(pwd)${RESET}"
} }
print_section() { print_section() {
echo -e "\n" echo -e "\n${BOLD}${CYAN}┌─ $1 ${2:-}${RESET}"
echo -e "${BOLD}${CYAN}$1 ${2:-}${RESET}"
} }
success_msg() { success_msg() {
echo -e "${GREEN}${CHECK} $*${RESET}" echo -e " ${GREEN}${CHECK} $*${RESET}"
} }
info_msg() { info_msg() {
echo -e "${BLUE}${LOADING} $*${RESET}" echo -e " ${BLUE}${LOADING} $*${RESET}"
} }
warning_msg() { warning_msg() {
echo -e "${YELLOW}${WARN} $*${RESET}" echo -e " ${YELLOW}${WARN} $*${RESET}"
} }
error_msg() { error_msg() {
echo -e "${RED}${ERROR} $*${RESET}" echo -e " ${RED}${ERROR} $*${RESET}"
} }
skip_msg() { skip_msg() {
echo -e "${YELLOW}${SKIP} $*${RESET}" echo -e " ${YELLOW}${SKIP} $*${RESET}"
}
print_summary() {
local version=$1
local duration=$2
local success_count=$3
local skipped_count=$4
local failed_count=$5
local failed_packages=("${@:6}")
print_section "Release Summary"
echo -e "\n ${DIM}Version : ${BOLD}v${version}${RESET}"
echo -e " ${DIM}Duration : ${BOLD}${duration}s${RESET}"
if [ "$success_count" -gt 0 ]; then
echo -e "\n ${DIM}Published : ${GREEN}${success_count}${RESET} packages"
fi
if [ "$skipped_count" -gt 0 ]; then
echo -e "\n ${DIM}Skipped : ${YELLOW}${skipped_count}${RESET} packages"
fi
if [ "$failed_count" -gt 0 ]; then
echo -e "\n ${DIM}Failed : ${RED}${failed_count}${RESET} packages"
echo -e "\n ${DIM}Failed packages:${RESET}"
for package in "${failed_packages[@]}"; do
echo -e " ${RED}• ${package}${RESET}"
done
fi
echo -e ""
if [ "$success_count" -eq 0 ] && [ "$skipped_count" -gt 0 ]; then
success_msg "All packages were already up to date! ${ROCKET}"
elif [ "$success_count" -gt 0 ]; then
success_msg "NPM release completed successfully! ${ROCKET}"
elif [ "$failed_count" -gt 0 ]; then
error_msg "NPM release completed with failures! ${ERROR}"
fi
} }
# Check if version exists # Check if version exists
@@ -177,34 +215,10 @@ main() {
local end_time=$(date +%s) local end_time=$(date +%s)
local duration=$((end_time - start_time)) local duration=$((end_time - start_time))
print_section "Release Summary" print_summary "$VERSION" "$duration" "$success_count" "$skipped_count" "$failed_count" "${failed_packages[@]}"
echo -e "Version: ${BOLD}v${VERSION}${RESET}"
echo -e "Duration: ${BOLD}${duration}s${RESET}"
if [ "$success_count" -gt 0 ]; then # Exit with failure if any package failed
echo -e "Published: ${GREEN}${success_count}${RESET} packages" [ "$failed_count" -gt 0 ] && exit 1 || exit 0
fi
if [ "$skipped_count" -gt 0 ]; then
echo -e "Skipped: ${YELLOW}${skipped_count}${RESET} packages"
fi
if [ "$failed_count" -gt 0 ]; then
echo -e "Failed: ${RED}${failed_count}${RESET} packages"
echo -e "\nFailed packages:"
for package in "${failed_packages[@]}"; do
echo -e "${RED} - ${package}${RESET}"
done
fi
if [ "$success_count" -eq 0 ] && [ "$skipped_count" -gt 0 ]; then
success_msg "\nAll packages were already up to date! ${ROCKET}"
elif [ "$success_count" -gt 0 ]; then
success_msg "\nNPM release completed successfully! ${ROCKET}"
elif [ "$failed_count" -gt 0 ]; then
error_msg "\nNPM release completed with failures! ${ERROR}"
exit 1
fi
} }
# Execute main function # Execute main function
+62 -48
View File
@@ -56,23 +56,28 @@ readonly REPOSITORIES=(
# Print functions # Print functions
print_header() { print_header() {
echo -e "\n${BOLD}${BLUE}${ROCKET} PHP-Flasher Status Dashboard ${ROCKET}${RESET}" echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}"
echo -e "${DIM}Generated on: $(date '+%Y-%m-%d %H:%M:%S %Z')${RESET}" echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher Status ${ROCKET} │${RESET}"
echo -e "${DIM}By: $(git config user.name) <$(git config user.email)>${RESET}" echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${RESET}\n"
echo -e "${DIM}Working Directory: $(pwd)${RESET}\n" echo -e " ${DIM}Date : $(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}"
echo -e " ${DIM}User : $(whoami)${RESET}"
echo -e " ${DIM}Directory: $(pwd)${RESET}"
} }
print_section() { print_section() {
echo -e "\n${BOLD}${CYAN}$1 ${2:-}${RESET}" echo -e "\n${BOLD}${CYAN} $1 ${2:-}${RESET}"
echo -e "${DIM}${CYAN}$(printf '%.s─' $(seq 1 50))${RESET}"
}
success_msg() {
echo -e "${GREEN}${CHECK} $*${RESET}"
} }
warning_msg() { warning_msg() {
echo -e "${YELLOW}${WARNING} $*${RESET}" echo -e " ${YELLOW}${WARNING} $*${RESET}"
}
success_msg() {
echo -e " ${GREEN}${CHECK} $*${RESET}"
}
error_msg() {
echo -e " ${RED}${ERROR} $*${RESET}"
} }
info_msg() { info_msg() {
@@ -145,9 +150,17 @@ get_github_stars() {
# Get Packagist version # Get Packagist version
get_packagist_version() { get_packagist_version() {
local package=$1 local package=$1
local response=$(curl_cmd "https://repo.packagist.org/p2/php-flasher/${package}.json") local response=$(curl -s -f "https://repo.packagist.org/p2/php-flasher/${package}.json")
local version=$(echo "$response" | grep -o '"latest":"[^"]*"' | cut -d'"' -f4) if [ $? -eq 0 ] && [ ! -z "$response" ]; then
echo "${version:-N/A}" local version=$(echo "$response" | grep -o '"latest":"[^"]*"' | cut -d'"' -f4)
if [ ! -z "$version" ]; then
echo "$version"
else
echo "N/A"
fi
else
echo "N/A"
fi
} }
# Get NPM version # Get NPM version
@@ -175,38 +188,39 @@ display_repo_info() {
local repo=$1 local repo=$1
local latest_tag=$(get_latest_tag "$repo") local latest_tag=$(get_latest_tag "$repo")
local stats=($(get_repo_stats "$repo" | tr '|' ' ')) local stats=($(get_repo_stats "$repo" | tr '|' ' '))
local composer_version=$(check_composer_version)
local github_stars=$(get_github_stars "$repo") local github_stars=$(get_github_stars "$repo")
local packagist_version=$(get_packagist_version "$repo")
local npm_version="N/A" local npm_version="N/A"
local packagist_version="N/A"
# Check NPM version for main packages and those with JavaScript # Get NPM version for specific packages
if [[ "$repo" == "flasher" || "$repo" == *"-prime" || \ if [[ "$repo" == "flasher" || \
"$repo" == "flasher-noty" || "$repo" == "flasher-notyf" || \ "$repo" == "flasher-noty" || \
"$repo" == "flasher-sweetalert" || "$repo" == "flasher-toastr" ]]; then "$repo" == "flasher-notyf" || \
"$repo" == "flasher-sweetalert" || \
"$repo" == "flasher-toastr" ]]; then
npm_version=$(get_npm_version "$repo") npm_version=$(get_npm_version "$repo")
fi fi
echo -e "\n${BOLD}${PACKAGE} ${MAGENTA}${repo}${RESET}" # Get Packagist version
echo -e " ${BRANCH} Branch: ${stats[1]:-unknown}" packagist_version=$(get_packagist_version "$repo")
echo -e " ${TAG} Latest Tag: ${latest_tag:-none}"
echo -e " ${STAR} GitHub Stars: ${github_stars}" # Display repository information
echo -e " ${PACKAGIST} Packagist: v${packagist_version}" echo -e "\n${BOLD}${MAGENTA} ${PACKAGE} ${repo}${RESET}"
echo -e " ${BRANCH} Branch : ${stats[1]:-unknown}"
echo -e " ${TAG} Latest Tag : ${latest_tag:-none}"
echo -e " ${STAR} Stars : ${github_stars}"
echo -e " ${PACKAGIST} Packagist : v${packagist_version}"
if [ "$npm_version" != "N/A" ]; then if [ "$npm_version" != "N/A" ]; then
echo -e " ${NPM} NPM: v${npm_version}" echo -e " ${NPM} NPM : v${npm_version}"
fi fi
echo -e " ${GITHUB} Last Commit: ${stats[0]:-unknown} (${stats[2]:-unknown})" echo -e " ${GITHUB} Last Commit : ${stats[0]:-unknown} (${stats[2]:-unknown})"
echo -e " ${INFO} Last Message: ${stats[3]:-unknown}" echo -e " ${INFO} Message : ${stats[3]:-unknown}"
if [ "$composer_version" != "N/A" ]; then
echo -e " ${INFO} Composer Version: $composer_version"
fi
local commits_since_tag=$(get_commit_count_since_tag "$repo" "$latest_tag") local commits_since_tag=$(get_commit_count_since_tag "$repo" "$latest_tag")
if [ "$commits_since_tag" -gt 0 ]; then if [ "$commits_since_tag" -gt 0 ]; then
warning_msg " $commits_since_tag commit(s) since last tag" warning_msg "$commits_since_tag commit(s) since last tag"
fi fi
} }
@@ -215,30 +229,30 @@ check_git_status() {
print_section "Git Status" "${GITHUB}" print_section "Git Status" "${GITHUB}"
local current_branch=$(git rev-parse --abbrev-ref HEAD) local current_branch=$(git rev-parse --abbrev-ref HEAD)
echo -e "${BOLD}Current Branch:${RESET} $current_branch" echo -e " ${BRANCH} Current Branch : ${current_branch}"
if [ "$current_branch" != "$MAIN_BRANCH" ]; then if [ "$current_branch" != "$MAIN_BRANCH" ]; then
warning_msg "Not on main branch ($MAIN_BRANCH)" warning_msg " Not on main branch ($MAIN_BRANCH)"
fi fi
if [[ ! -z "$(git status --porcelain)" ]]; then if [[ ! -z "$(git status --porcelain)" ]]; then
warning_msg "Working directory is not clean" warning_msg " Working directory is not clean"
git status --short git status --short | sed 's/^/ /'
else else
success_msg "Working directory is clean" success_msg " Working directory is clean"
fi fi
local behind=$(git rev-list HEAD..origin/$current_branch --count 2>/dev/null || echo "0") local behind=$(git rev-list HEAD..origin/$current_branch --count 2>/dev/null || echo "0")
local ahead=$(git rev-list origin/$current_branch..HEAD --count 2>/dev/null || echo "0") local ahead=$(git rev-list origin/$current_branch..HEAD --count 2>/dev/null || echo "0")
if [ "$behind" -gt 0 ]; then if [ "$behind" -gt 0 ]; then
warning_msg "Branch is behind by $behind commit(s)" warning_msg " Branch is behind by $behind commit(s)"
fi fi
if [ "$ahead" -gt 0 ]; then if [ "$ahead" -gt 0 ]; then
warning_msg "Branch is ahead by $ahead commit(s)" warning_msg " Branch is ahead by $ahead commit(s)"
fi fi
if [ "$behind" -eq 0 ] && [ "$ahead" -eq 0 ]; then if [ "$behind" -eq 0 ] && [ "$ahead" -eq 0 ]; then
success_msg "Branch is up to date with origin" success_msg " Branch is up to date with origin"
fi fi
} }
@@ -247,13 +261,13 @@ check_dependencies() {
print_section "Dependencies" "${PACKAGE}" print_section "Dependencies" "${PACKAGE}"
if [ -f "composer.json" ]; then if [ -f "composer.json" ]; then
echo -e "${BOLD}Composer Dependencies:${RESET}" echo -e " ${BOLD}Composer Dependencies:${RESET}"
composer show | grep "php-flasher/" || echo "No PHP-Flasher dependencies found" composer show | grep "php-flasher/" | sed 's/^/ /' || echo " No PHP-Flasher dependencies found"
fi fi
if [ -f "package.json" ]; then if [ -f "package.json" ]; then
echo -e "\n${BOLD}NPM Dependencies:${RESET}" echo -e "\n ${BOLD}NPM Dependencies:${RESET}"
npm list | grep "@flasher/" || echo "No Flasher dependencies found" npm list | grep "@flasher/" | sed 's/^/ /' || echo " No Flasher dependencies found"
fi fi
} }
@@ -263,10 +277,10 @@ display_modified_files() {
local modified_files=$(git diff --name-only) local modified_files=$(git diff --name-only)
if [ ! -z "$modified_files" ]; then if [ ! -z "$modified_files" ]; then
echo -e "${BOLD}Modified files:${RESET}" echo -e " ${BOLD}Modified files:${RESET}"
echo "$modified_files" echo "$modified_files" | sed 's/^/ /'
else else
success_msg "No modified files" success_msg " No modified files"
fi fi
} }