diff --git a/bin/dependency-check-pr.sh b/bin/dependency-check-pr.sh index 996b351..86b6e0f 100755 --- a/bin/dependency-check-pr.sh +++ b/bin/dependency-check-pr.sh @@ -2,6 +2,9 @@ set -eou pipefail IFS=$'\n\t' +white="\e[97m" +green="\e[32m" +reset="\e[0m" readonly AUTHOR_EMAIL="bot@getpantheon.com" readonly AUTHOR_NAME="Pantheon Automation" @@ -22,22 +25,21 @@ main() { local CURRENT_TAG CURRENT_TAG="$(yq ".dependencies.${NAME}.current_tag" "${DEPENDENCIES_YML}")" - echo "Current Tag: ${CURRENT_TAG}" + echo -e "Current Tag: ${white}${CURRENT_TAG}${reset}" local REPO REPO="$(yq ".dependencies.${NAME}.repo" "${DEPENDENCIES_YML}")" + local SOURCE + SOURCE="$(yq ".dependencies.${NAME}.source" "${DEPENDENCIES_YML}")" + local LATEST_TAG - if LATEST_TAG=$(gh release view -R "${REPO}" --json tagName -q .tagName 2>/dev/null); then - echo "Latest Tag: ${LATEST_TAG}" - else - echo "Release not found, trying tags..." - LATEST_TAG=$(gh api "repos/${REPO}/tags" --jq '.[0].name' 2>/dev/null) - echo "Latest Tag: ${LATEST_TAG}" - fi + LATEST_TAG="$(get_latest_tag "${REPO}" "${SOURCE}")" + echo -e "Latest Tag: ${white}${LATEST_TAG}${reset}" # We likely don't even need to version compare, just == if [[ "${CURRENT_TAG}" == "${LATEST_TAG}" ]]; then + echo "${CURRENT_TAG} is the latest version..." continue fi @@ -124,7 +126,33 @@ ${PR_NOTE}" echo "No commits found for diff." fi fi - echo "✨ Done" + echo -e "✨ ${green}Done${reset} ✨" +} + +# Get the latest tag from the source. If source is undefined, default to "github". +# Usage example: LATEST_TAG=$(get_latest_tag "mongodb-php-library" "pecl") +get_latest_tag() { + local repo="$1" + local source="$2" + local LATEST_TAG + + # We're defaulting to GitHub, but we want to check against releases AND tags. + if [[ "${source}" == "github" || "${source}" == "null" || "${source}" == "" ]]; then + LATEST_TAG=$(gh release view -R "${REPO}" --json tagName -q .tagName 2>/dev/null) + # Check for a release first, then fall back to tags + if [[ -z "${LATEST_TAG}" ]]; then + LATEST_TAG=$(gh api "repos/${REPO}/tags" --jq '.[0].name' 2>/dev/null) + fi + # Oh, you want a PECL? + elif [[ "${source}" == "pecl" ]]; then + LATEST_TAG=$(curl -s https://pecl.php.net/rest/r/"${repo}"/latest.txt) + # New source, who dis? + else + echo "Unknown source: ${source}" + exit 1 + fi + + echo "${LATEST_TAG}" } replace_version_in_file() { diff --git a/bin/test-dependencies-yml.sh b/bin/test-dependencies-yml.sh index 448d64b..787c151 100755 --- a/bin/test-dependencies-yml.sh +++ b/bin/test-dependencies-yml.sh @@ -5,6 +5,7 @@ set -eou pipefail # Define some colors. red="\e[31m" green="\e[32m" +white="\e[97m" reset="\e[0m" # Get the filename from the first positional argument @@ -35,7 +36,7 @@ for key in $(yq eval '.dependencies | keys | .[]' "$filename"); do # Get the current_tag value using yq current_tag=$(yq eval ".dependencies.${key}.current_tag" "$filename") - echo -n "Found ${current_tag}..." + echo -ne "${white}Found ${current_tag}${reset}..." # Check if the value matches the version pattern if [[ ! $current_tag =~ $version_pattern ]]; then diff --git a/bin/test-textfile.sh b/bin/test-textfile.sh index 8f8f7cd..378e106 100755 --- a/bin/test-textfile.sh +++ b/bin/test-textfile.sh @@ -5,6 +5,7 @@ set -eou pipefail # Define some colors. red="\e[31m" green="\e[32m" +white="\e[97m" reset="\e[0m" # Get the filename from the first positional argument @@ -12,7 +13,7 @@ filename="$1" # Check if the filename argument is provided if [ -z "$filename" ]; then - echo "No filename specified." + echo "${red}No filename specified.${reset}" echo "Usage: bash ./bin/test-textfile.sh " exit 1 fi @@ -43,11 +44,11 @@ while IFS= read -r line; do # Output the extension name being checked echo "Validating version for $formatted_name..." - echo "Found $version!" + echo -e "${white}Found $version!${reset} ✅" # Check if the version matches the pattern if [[ ! $version =~ $version_pattern ]]; then - echo "Invalid version: $version" + echo -e "${red}Invalid version: $version${reset} ❌" valid_versions=false fi done <<< "$file_contents" diff --git a/bin/validate-dependencies-yml-schema.sh b/bin/validate-dependencies-yml-schema.sh index 6ef0abb..ba41db3 100755 --- a/bin/validate-dependencies-yml-schema.sh +++ b/bin/validate-dependencies-yml-schema.sh @@ -5,6 +5,7 @@ set -eou pipefail # Define some colors. red="\e[31m" green="\e[32m" +white="\e[97m" reset="\e[0m" # Get the filename from the first positional argument @@ -23,11 +24,13 @@ shopt -s nocasematch # Regular expression patterns for validation version_pattern='^(v)?([0-9]+(\.[0-9]+)*(-[A-Za-z0-9]+)?|[A-Za-z0-9]+-[0-9]+(\.[0-9]+)*(-[A-Za-z0-9]+)?|.+)$' repo_pattern='^[^/]+/[^/]+$' +source_pattern='^(github|pecl)?$' # Initialize a flag variable to track validation status valid_schema=true valid_versions=true valid_repos=true +valid_sources=true echo "Checking ${filename} for valid schema..." @@ -45,10 +48,29 @@ if "$valid_schema"; then while IFS=" " read -r key; do echo -n "Validating ${key}..." + # Fetch and validate source, if it's empty assume 'github' + source=$(yq eval ".dependencies.${key}.source" "$filename" 2>/dev/null) + if [[ -z "$source" || "$source" == null ]]; then + source="github" + echo -ne "Checking source... Found null, assuming ${white}${source}${reset} " + else + echo -ne "Checking source... Found ${white}${source}${reset} " + fi + + if [[ ! $source =~ $source_pattern ]]; then + echo -e "${red}Invalid source for ${key}: ${source}${reset}" + valid_sources=false + else + echo -ne "✅..." + fi + + # Based on source, select appropriate repo pattern + [[ "$source" == "pecl" ]] && repo_pattern='^[^/]+$' || repo_pattern='^[^/]+/[^/]+$' + echo -n "Checking current_tag..." # Validate current_tag value current_tag=$(yq eval ".dependencies.${key}.current_tag" "$filename") - echo -n "Found ${current_tag} " + echo -ne "${white}Found ${current_tag}${reset} " if [[ -z "$current_tag" || ! $current_tag =~ $version_pattern ]]; then echo -e "${red}Invalid version for ${key}: ${current_tag}${reset}" valid_versions=false @@ -59,7 +81,7 @@ if "$valid_schema"; then echo -n "Checking repo..." # Validate repo value repo=$(yq eval ".dependencies.${key}.repo" "$filename") - echo -n "Found ${repo} " + echo -ne "Found ${white}${repo}${reset} " if [[ -z "$repo" || ! $repo =~ $repo_pattern ]]; then echo -e "${red}Invalid repo for ${key}: ${repo}${reset}" valid_repos=false @@ -72,6 +94,11 @@ fi # Print summary based on validation results echo "" +if ! "$valid_sources"; then + echo -e "${red}One or more dependencies have invalid sources.${reset}" + exit 1 +fi + if ! "$valid_schema"; then echo -e "${red}Invalid dependencies.yml schema: missing 'dependencies:' key.${reset}" exit 1 diff --git a/fixtures/PHP_EXTENSION_VERSIONS b/fixtures/PHP_EXTENSION_VERSIONS index 87df0f8..dd2c170 100644 --- a/fixtures/PHP_EXTENSION_VERSIONS +++ b/fixtures/PHP_EXTENSION_VERSIONS @@ -2,7 +2,7 @@ declare -r APCU_DEFAULT_VERSION=5.1.22 declare -r IMAGICK_DEFAULT_VERSION=3.7.0 declare -r MONGODB_DEFAULT_VERSION=1.14.2 -declare -r OAUTH_DEFAULT_VERSION=2.0.7 +declare -r OAUTH_DEFAULT_VERSION=2.0.6 declare -r REDIS_DEFAULT_VERSION=5.3.7 declare -r SQLSRV_DEFAULT_VERSION=5.10.0 declare -r YAML_DEFAULT_VERSION=2.2.2 diff --git a/fixtures/dependencies.yml b/fixtures/dependencies.yml index e1971f5..fdd8469 100644 --- a/fixtures/dependencies.yml +++ b/fixtures/dependencies.yml @@ -1,35 +1,43 @@ dependencies: + oauth: + current_tag: 2.0.6 + repo: oauth + source: pecl # Defines PECL as the source so we check their API for the latest version. In this case, the "repo" name must be the same as the PECL package name (minus the version), e.g. https://pecl.php.net/package/oauth. apcu: current_tag: v5.1.22 - repo: krakjoe/apcu + repo: apcu + source: pecl imagick: current_tag: 3.7.0 - repo: Imagick/imagick - mongodb: - current_tag: 1.14.2 - repo: mongodb/mongo-php-library - oauth: - current_tag: 2.0.7 - repo: thephpleague/oauth2-client + repo: imagick + source: pecl redis: current_tag: 5.3.7 - repo: phpredis/phpredis + repo: redis + source: pecl + igbinary: + current_tag: 3.2.12 + repo: igbinary + source: pecl + msgpack: + current_tag: msgpack-2.2.0RC2 + repo: msgpack + source: pecl sqlsrv: current_tag: v5.10.0 - repo: microsoft/msphpsql + repo: sqlsrv + source: pecl yaml: current_tag: 2.2.2 repo: php/pecl-file_formats-yaml + source: github # This is optional if GitHub, but it should work if defined. + mongodb: + current_tag: 1.14.2 + repo: mongodb/mongo-php-library uploadprogress: current_tag: uploadprogress-2.0.2 repo: php/pecl-php-uploadprogress newrelic: current_tag: v10.10.0.1 repo: newrelic/newrelic-php-agent - pr_note: "This update should only be handled by the team that manages New Relic." - igbinary: - current_tag: 3.2.12 - repo: igbinary/igbinary - msgpack: - current_tag: msgpack-2.2.0RC2 - repo: msgpack/msgpack-php \ No newline at end of file + pr_note: "This update should only be handled by the team that manages New Relic." \ No newline at end of file