#!/usr/bin/env bash # Set options set -e set -o pipefail # Define colors and styles readonly RESET='\033[0m' readonly BOLD='\033[1m' readonly DIM='\033[2m' readonly ITALIC='\033[3m' readonly UNDERLINE='\033[4m' readonly RED='\033[31m' readonly GREEN='\033[32m' readonly YELLOW='\033[33m' readonly BLUE='\033[34m' readonly MAGENTA='\033[35m' readonly CYAN='\033[36m' readonly WHITE='\033[37m' # Define emoji readonly ROCKET="🚀" readonly PACKAGE="đŸ“Ļ" readonly CALENDAR="📅" readonly CLOCK="🕒" readonly INFO="â„šī¸" readonly WARNING="âš ī¸" readonly CHECK="✓" readonly BRANCH="đŸŒŋ" readonly TAG="đŸˇī¸" readonly GITHUB="⭐" readonly STAR="⭐" readonly NPM="đŸ“Ļ" readonly PACKAGIST="đŸŽ¯" # Configuration readonly ORGANIZATION="php-flasher" readonly MAIN_BRANCH="2.x" readonly REPOSITORIES=( "flasher" "flasher-laravel" "flasher-symfony" "flasher-noty" "flasher-noty-laravel" "flasher-noty-symfony" "flasher-notyf" "flasher-notyf-laravel" "flasher-notyf-symfony" "flasher-sweetalert" "flasher-sweetalert-laravel" "flasher-sweetalert-symfony" "flasher-toastr" "flasher-toastr-laravel" "flasher-toastr-symfony" ) # Print functions print_header() { echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}" echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher Status ${ROCKET} │${RESET}" echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${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() { echo -e "\n${BOLD}${CYAN} $1 ${2:-}${RESET}" } warning_msg() { echo -e " ${YELLOW}${WARNING} $*${RESET}" } success_msg() { echo -e " ${GREEN}${CHECK} $*${RESET}" } error_msg() { echo -e " ${RED}${ERROR} $*${RESET}" } info_msg() { echo -e "${BLUE}${INFO} $*${RESET}" } # Get the latest tag for a repository get_latest_tag() { local repo=$1 git ls-remote --tags --refs "git@github.com:${ORGANIZATION}/${repo}.git" | sort -t '/' -k 3 -V | tail -n1 | awk -F/ '{print $3}' } # Get commit count since last tag get_commit_count_since_tag() { local repo=$1 local tag=$2 git rev-list "${tag}..HEAD" --count 2>/dev/null || echo "0" } # Get repository statistics get_repo_stats() { local repo=$1 local tmp_dir="/tmp/php-flasher-status/${repo}" mkdir -p "$tmp_dir" if [ ! -d "$tmp_dir/.git" ]; then git clone -q "git@github.com:${ORGANIZATION}/${repo}.git" "$tmp_dir" 2>/dev/null fi ( cd "$tmp_dir" git fetch -q origin 2>/dev/null echo "$(git rev-parse --short HEAD)|$(git rev-parse --abbrev-ref HEAD)|$(git log -1 --format='%cr')|$(git log -1 --format='%s')" ) } # Check composer.json version check_composer_version() { local file="composer.json" if [ -f "$file" ]; then grep -o '"version": *"[^"]*"' "$file" 2>/dev/null | cut -d'"' -f4 || echo "N/A" else echo "N/A" fi } # Add curl with proper user agent for API calls curl_cmd() { # You can set your GitHub token as an environment variable local gh_token=${GITHUB_TOKEN:-""} local auth_header="" if [ ! -z "$gh_token" ]; then auth_header="-H \"Authorization: token $gh_token\"" fi curl -s -H "User-Agent: PHP-Flasher-Status-Check" $auth_header "$@" } # Get GitHub stars for a repository get_github_stars() { local repo=$1 local response=$(curl_cmd "https://api.github.com/repos/${ORGANIZATION}/${repo}") local stars=$(echo "$response" | grep -o '"stargazers_count":[0-9]*' | cut -d':' -f2) echo "${stars:-0}" } # Get Packagist version get_packagist_version() { local package=$1 local response=$(curl -s -f "https://repo.packagist.org/p2/php-flasher/${package}.json") if [ $? -eq 0 ] && [ ! -z "$response" ]; then 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() { local package=$1 # Convert package name format if [[ "$package" == "flasher" ]]; then package="flasher" elif [[ "$package" == *"-prime" ]]; then # Remove -prime suffix for npm package name package=${package%-prime} elif [[ "$package" == *"-laravel" || "$package" == *"-symfony" ]]; then # These packages don't have npm versions echo "N/A" return fi local response=$(curl_cmd "https://registry.npmjs.org/@flasher/${package}/latest") local version=$(echo "$response" | grep -o '"version":"[^"]*"' | cut -d'"' -f4) echo "${version:-N/A}" } # Display repository information display_repo_info() { local repo=$1 local latest_tag=$(get_latest_tag "$repo") local stats=($(get_repo_stats "$repo" | tr '|' ' ')) local github_stars=$(get_github_stars "$repo") local npm_version="N/A" local packagist_version="N/A" # Get NPM version for specific packages if [[ "$repo" == "flasher" || \ "$repo" == "flasher-noty" || \ "$repo" == "flasher-notyf" || \ "$repo" == "flasher-sweetalert" || \ "$repo" == "flasher-toastr" ]]; then npm_version=$(get_npm_version "$repo") fi # Get Packagist version packagist_version=$(get_packagist_version "$repo") # Display repository information 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 echo -e " ${NPM} NPM : v${npm_version}" fi echo -e " ${GITHUB} Last Commit : ${stats[0]:-unknown} (${stats[2]:-unknown})" echo -e " ${INFO} Message : ${stats[3]:-unknown}" local commits_since_tag=$(get_commit_count_since_tag "$repo" "$latest_tag") if [ "$commits_since_tag" -gt 0 ]; then warning_msg "$commits_since_tag commit(s) since last tag" fi } # Check git status check_git_status() { print_section "Git Status" "${GITHUB}" local current_branch=$(git rev-parse --abbrev-ref HEAD) echo -e " ${BRANCH} Current Branch : ${current_branch}" if [ "$current_branch" != "$MAIN_BRANCH" ]; then warning_msg " Not on main branch ($MAIN_BRANCH)" fi if [[ ! -z "$(git status --porcelain)" ]]; then warning_msg " Working directory is not clean" git status --short | sed 's/^/ /' else success_msg " Working directory is clean" fi 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") if [ "$behind" -gt 0 ]; then warning_msg " Branch is behind by $behind commit(s)" fi if [ "$ahead" -gt 0 ]; then warning_msg " Branch is ahead by $ahead commit(s)" fi if [ "$behind" -eq 0 ] && [ "$ahead" -eq 0 ]; then success_msg " Branch is up to date with origin" fi } # Check dependencies check_dependencies() { print_section "Dependencies" "${PACKAGE}" if [ -f "composer.json" ]; then echo -e " ${BOLD}Composer Dependencies:${RESET}" composer show | grep "php-flasher/" | sed 's/^/ /' || echo " No PHP-Flasher dependencies found" fi if [ -f "package.json" ]; then echo -e "\n ${BOLD}NPM Dependencies:${RESET}" npm list | grep "@flasher/" | sed 's/^/ /' || echo " No Flasher dependencies found" fi } # Display modified files display_modified_files() { print_section "Modified Files" "📝" local modified_files=$(git diff --name-only) if [ ! -z "$modified_files" ]; then echo -e " ${BOLD}Modified files:${RESET}" echo "$modified_files" | sed 's/^/ /' else success_msg " No modified files" fi } # Main execution main() { print_header # Check current repository status check_git_status # Check dependencies check_dependencies # Display modified files display_modified_files # Display repositories information print_section "Repositories Status" "${PACKAGE}" for repo in "${REPOSITORIES[@]}"; do display_repo_info "$repo" done # Display release readiness print_section "Release Readiness" "${ROCKET}" local ready=true if [ ! -z "$(git status --porcelain)" ]; then warning_msg "Working directory is not clean" ready=false fi if [ "$(git rev-parse --abbrev-ref HEAD)" != "$MAIN_BRANCH" ]; then warning_msg "Not on main branch ($MAIN_BRANCH)" ready=false fi if $ready; then success_msg "Ready for release!" echo -e "\n${BOLD}${GREEN}Suggested next steps:${RESET}" echo -e "1. Run: ${ITALIC}./bin/split${RESET}" echo -e "2. Run: ${ITALIC}./bin/release ${RESET}" else warning_msg "Not ready for release. Please fix the issues above." fi } # Execute main function main