From 96c02b7825c771b4a7d0850e07fd1f58a7280606 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Mon, 5 Feb 2024 12:45:01 +0100 Subject: [PATCH] feat(nuget): adjust version check action Refs: CPLP-3400 --- scripts/check_package_versions.sh | 41 +---------- scripts/check_package_versions_local.sh | 36 +--------- scripts/nuget_version_check.sh | 90 +++++++++++++++++++++++++ scripts/update_framework_versions.sh | 2 +- 4 files changed, 94 insertions(+), 75 deletions(-) create mode 100755 scripts/nuget_version_check.sh diff --git a/scripts/check_package_versions.sh b/scripts/check_package_versions.sh index 0476669631..cf26739f76 100755 --- a/scripts/check_package_versions.sh +++ b/scripts/check_package_versions.sh @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation +# Copyright (c) 2024 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -19,42 +19,5 @@ #!/bin/bash -# Get GitHub context from environment variables -baseBranch=release/v1.8.0-RC5 -currentBranch=feature/CPLP-3400-framework-nuget -# Initialize a global arrays to store data -version_update_needed=() - -# get the directory.build files to check the updated versions -changed_versions=($(git diff --name-only $baseBranch..$currentBranch | grep 'Directory.Build.props')) - -check_version_update(){ - local project="$1" - local props_file="src/framework/"$project"/Directory.Build.props" - if ! git diff --diff-filter=D --quiet "$baseBranch..$currentBranch" -- "$props_file" || - ! [ -s "$props_file" ]; then - break; - else - if [[ " ${changed_versions[@]} " =~ " $props_file " ]]; then - if ! git diff $baseBranch..$currentBranch -- "$props_file" | grep -qE '^\+[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+' && - (! git diff $baseBranch..$currentBranch -- "$props_file" | grep -qE '^\+[[:space:]]*' && git diff $baseBranch..$currentBranch -- "$props_file" | grep -qE '^\+[[:space:]]*[^<]*'); then - version_update_needed+=($project) - fi - else - version_update_needed+=($project) - fi - fi -} - -for dir in ./src/framework/*/; do - if [ -d "$dir" ]; then - proj="$(basename "$dir")" - check_version_update $proj - fi -done - -# return all packages that still need a version update -for dir in "${version_update_needed[@]}"; do - echo "$dir" -done +. ./scripts/nuget_version_check.sh "$BASE_NAME..$HEAD_NAME" diff --git a/scripts/check_package_versions_local.sh b/scripts/check_package_versions_local.sh index b7cfff48a5..9ff0b9558a 100755 --- a/scripts/check_package_versions_local.sh +++ b/scripts/check_package_versions_local.sh @@ -19,38 +19,4 @@ #!/bin/bash -# Initialize a global arrays to store data -version_update_needed=() - -# get the directory.build files to check the updated versions -changed_versions=($(git diff --name-only HEAD~1 | grep 'Directory.Build.props')) - -check_version_update(){ - local project="$1" - local props_file="src/framework/"$project"/Directory.Build.props" - if ! git diff --diff-filter=D --quiet HEAD~1 -- "$props_file" || - ! [ -s "$props_file" ]; then - break; - else - if [[ " ${changed_versions[@]} " =~ " $props_file " ]]; then - if ! git diff HEAD~1 -- "$props_file" | grep -qE '^\+[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+' && - (! git diff HEAD~1 -- "$props_file" | grep -qE '^\+[[:space:]]*' && git diff HEAD~1 -- "$props_file" | grep -qE '^\+[[:space:]]*[^<]*'); then - version_update_needed+=($project) - fi - else - version_update_needed+=($project) - fi - fi -} - -for dir in ./src/framework/*/; do - if [ -d "$dir" ]; then - proj="$(basename "$dir")" - check_version_update $proj - fi -done - -# return all packages that still need a version update -for dir in "${version_update_needed[@]}"; do - echo "$dir" -done +. ./scripts/nuget_version_check.sh "" \ No newline at end of file diff --git a/scripts/nuget_version_check.sh b/scripts/nuget_version_check.sh new file mode 100755 index 0000000000..da06417a3e --- /dev/null +++ b/scripts/nuget_version_check.sh @@ -0,0 +1,90 @@ +############################################################### +# Copyright (c) 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +############################################################### + +#!/bin/bash + +# Get branch names +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Assign the arguments to variables +branchRange="$1" + +# Initialize a global arrays to store data +version_update_needed=() +first_version="" +unmatching_package=() + +is_integer() { + [[ $1 =~ ^[0-9]+$ ]] +} + +check_version_update(){ + local project="$1" + local props_file=$project"Directory.Build.props" + + if ! git diff --name-only $branchRange -- "$project" | grep -qE '\.cs$' || + ! [ -z $(git diff --name-only --diff-filter=D $branchRange -- "$props_file") ]; then + return + fi + + if [ -z $(git diff --name-only $branchRange -- "$props_file") ]; then + version_update_needed+=($project) + return + fi + + # version prefix change is mandatory + if ! git diff $branchRange -- "$props_file" | grep -qE '^\+[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+' || + # version suffix update not permitted + git diff $branchRange -- "$props_file" | grep -qE '^\+[[:space:]]*[^<]*'; then + version_update_needed+=($project) + return + fi + + version_before=$(git diff $branchRange -- "$props_file" | grep -E '^-.*' | sed -E 's/^-.*([^<]+)<\/VersionPrefix>/\1/') + version_after=$(git diff $branchRange -- "$props_file" | grep -E '^\+.*' | sed -E 's/^\+.*([^<]+)<\/VersionPrefix>/\1/') + + IFS='.' read -r major_before minor_before patch_before <<< "$version_before" + IFS='.' read -r major_after minor_after patch_after <<< "$version_after" + + if [ -n "$major_before" ] && [ -n "$major_after" ] && + [ -n "$minor_before" ] && [ -n "$minor_after" ] && + [ -n "$patch_before" ] && [ -n "$patch_after" ] && + ( [ "$major_after" -gt "$major_before" ] || + [ "$major_before" -eq "$major_after" -a "$minor_after" -gt "$minor_before" ] || + [ "$major_before" -eq "$major_after" -a "$minor_before" -eq "$minor_after" -a "$patch_after" -gt "$patch_before" ] ); then + return; + fi + + version_update_needed+=($project) +} + +# check version update was made for all framework packages which includes changes +for dir in ./src/framework/*/; do + if [ -d "$dir" ]; then + check_version_update $dir + fi +done + +# return all packages that still need a version update +for dir in "${version_update_needed[@]}"; do + echo "$dir" +done diff --git a/scripts/update_framework_versions.sh b/scripts/update_framework_versions.sh index 95d73073b0..cc7e65d8e4 100755 --- a/scripts/update_framework_versions.sh +++ b/scripts/update_framework_versions.sh @@ -1,5 +1,5 @@ ############################################################### -# Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation +# Copyright (c) 2024Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership.