Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGS-6802] add support for pecl as source to check #14

Merged
merged 20 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions bin/dependency-check-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -eou pipefail
IFS=$'\n\t'
white="\e[97m"
green="\e[32m"
reset="\e[0m"
pwtyler marked this conversation as resolved.
Show resolved Hide resolved

readonly AUTHOR_EMAIL="bot@getpantheon.com"
readonly AUTHOR_NAME="Pantheon Automation"
Expand All @@ -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

Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion bin/test-dependencies-yml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions bin/test-textfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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
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 <filename>"
exit 1
fi
Expand Down Expand Up @@ -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"
Expand Down
31 changes: 29 additions & 2 deletions bin/validate-dependencies-yml-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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..."

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fixtures/PHP_EXTENSION_VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 25 additions & 17 deletions fixtures/dependencies.yml
Original file line number Diff line number Diff line change
@@ -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
pr_note: "This update should only be handled by the team that manages New Relic."