From d7d9a664cb6d45b1019f8ac897feac512e5b37e8 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 1 Mar 2022 21:01:03 +0000 Subject: Update release scripts for branches Release scripts are updated: - Can now handle releasing on a branch for a maintenance release - startPhase.sh script updated to handle all 13 phases of the release process - Various corrections and bug fixes found during the release - scripts updated to comply with IntelliJ shekkcheck suggestions Issue-ID: POLICY-3835 Change-Id: Ibfa49e4132ca61ae0541600fae5f6814cdf7a409 Signed-off-by: liamfallon --- integration/src/release_scripts/bumpSnapshots.sh | 43 ++-- integration/src/release_scripts/generateCommit.sh | 41 ++-- integration/src/release_scripts/getReleaseData.sh | 79 +++--- integration/src/release_scripts/mkart.sh | 20 +- integration/src/release_scripts/mkdock.sh | 23 +- integration/src/release_scripts/releasePhase.sh | 270 +++++++++++++++++++-- integration/src/release_scripts/releaseRepo.sh | 39 +-- .../src/release_scripts/releaseRepoImages.sh | 31 ++- integration/src/release_scripts/updateOomImages.sh | 16 +- integration/src/release_scripts/updateParentRef.sh | 30 +-- integration/src/release_scripts/updateRefs.sh | 115 +++++---- 11 files changed, 494 insertions(+), 213 deletions(-) (limited to 'integration/src') diff --git a/integration/src/release_scripts/bumpSnapshots.sh b/integration/src/release_scripts/bumpSnapshots.sh index ced6453c..d7d22df7 100755 --- a/integration/src/release_scripts/bumpSnapshots.sh +++ b/integration/src/release_scripts/bumpSnapshots.sh @@ -22,7 +22,7 @@ set -e -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") repo_location="./" release_data_file="./pf_release_data.csv" @@ -138,11 +138,14 @@ fi for specified_repo in "${pf_repos[@]}" do - read repo \ + # shellcheck disable=SC2034 + # shellcheck disable=SC2046 + read -r repo \ latest_released_tag \ latest_snapshot_tag \ - changed_files docker_images \ - <<< $( grep $specified_repo $release_data_file | tr ',' ' ' ) + changed_files \ + docker_images \ + <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' ) if [ ! "$repo" = "$specified_repo" ] then @@ -154,28 +157,30 @@ do if [ "$latest_released_tag" = "$next_release_version" ] then - declare -i major_version=`echo $next_release_version | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/'` - declare -i minor_version=`echo $next_release_version | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/'` - declare -i patch_version=`echo $next_release_version | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/'` - declare -i new_patch_version=$(($patch_version+1)) + major_version=$(echo "$next_release_version" | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/') + minor_version=$(echo "$next_release_version" | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/') + patch_version=$(echo "$next_release_version" | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/') + # shellcheck disable=SC2004 + new_patch_version=$(($patch_version+1)) new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT - echo updating snapshot version and references of repo $repo to $new_snapshot_tag . . . - mvn -f $repo_location/$repo \ - -DnewVersion=$new_snapshot_tag versions:set \ + echo "updating snapshot version and references of repo $repo to $new_snapshot_tag . . ." + mvn -f "$repo_location/$repo" \ + "-DnewVersion=$new_snapshot_tag" versions:set \ versions:update-child-modules versions:commit temp_file=$(mktemp) - echo updating snapshot version of repo $repo in $repo_location/$repo/version.properties - $SED -e "s/patch=$patch_version/patch=$new_patch_version/" $repo_location/$repo/version.properties > $temp_file - mv $temp_file $repo_location/$repo/version.properties + echo "updating snapshot version of repo $repo in $repo_location/$repo/version.properties" + $SED -e "s/patch=$patch_version/patch=$new_patch_version/" \ + "$repo_location/$repo/version.properties" > "$temp_file" + mv "$temp_file" "$repo_location/$repo/version.properties" fi - updateRefs.sh -pcmos -d $release_data_file -l $repo_location -r $repo + updateRefs.sh -pcmos -d "$release_data_file" -l "$repo_location" -r "$repo" - if [ "$(git -C $repo_location/$specified_repo status | grep '^[ \t]*modified:[ \t]*pom.xml' > /dev/null 2>&1)" = 0 ] + if [ "$(git -C "$repo_location/$specified_repo" status | grep '^[ \t]*modified:[ \t]*pom.xml' > /dev/null 2>&1)" = 0 ] then references_updated=0 else @@ -190,9 +195,9 @@ do echo "generating commit to update snapshot version and/or references of repo $repo . . ." generateCommit.sh \ - -l $repo_location \ - -r $repo \ - -i $issue_id \ + -l "$repo_location" \ + -r "$repo" \ + -i "$issue_id" \ -e "Update snapshot and/or references of $repo to latest snapshots" \ -m "$repo updated to its latest own and reference snapshots" diff --git a/integration/src/release_scripts/generateCommit.sh b/integration/src/release_scripts/generateCommit.sh index 8c21c308..29e600a2 100755 --- a/integration/src/release_scripts/generateCommit.sh +++ b/integration/src/release_scripts/generateCommit.sh @@ -22,7 +22,7 @@ set -e -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") repo_location="./" usage() @@ -47,13 +47,6 @@ usage() exit 255; } -update_parent=false -update_common=false -update_models=false -update_drools_pdp=false -update_snapshot=false -update_docker=false - while getopts "hl:r:i:e:m:" opt do case $opt in @@ -129,7 +122,7 @@ then exit 1 fi -git -C $repo_location/$specified_repo status | grep '^Your branch is up to date' > /dev/null 2>&1 +git -C "$repo_location/$specified_repo" status | grep '^Your branch is up to date' > /dev/null 2>&1 return_code=$? if [ $return_code -eq 0 ] @@ -137,30 +130,32 @@ then echo "generating commit '$commit_header' . . ." commit_msg_temp_file=$(mktemp) - echo "$commit_header" > $commit_msg_temp_file - echo "" >> $commit_msg_temp_file - echo "$commit_message" >> $commit_msg_temp_file - echo "" >> $commit_msg_temp_file - echo "*** This commit is generated by a PF release script ***" >> $commit_msg_temp_file - echo "" >> $commit_msg_temp_file - echo "Issue-ID: $issue_id" >> $commit_msg_temp_file - - git -C $repo_location/$specified_repo add . - git -C $repo_location/$specified_repo commit -s -F "$commit_msg_temp_file" - rm $commit_msg_temp_file + { + echo "$commit_header" + echo "" + echo "$commit_message" + echo "" + echo "*** This commit is generated by a PF release script ***" + echo "" + echo "Issue-ID: $issue_id" + } > "$commit_msg_temp_file" + + git -C "$repo_location/$specified_repo" add . + git -C "$repo_location/$specified_repo" commit -s -F "$commit_msg_temp_file" + rm "$commit_msg_temp_file" echo "commit '$commit_header' generated" else echo "updating commit '$commit_header' . . ." - git -C $repo_location/$specified_repo add . - git -C $repo_location/$specified_repo commit -as --amend --no-edit + git -C "$repo_location/$specified_repo" add . + git -C "$repo_location/$specified_repo" commit -as --amend --no-edit echo "commit '$commit_header' updated" fi echo "sending commit '$commit_header' to gerrit . . ." -git -C $repo_location/$specified_repo review +git -C "$repo_location/$specified_repo" review echo "commit '$commit_header' sent to gerrit . . ." diff --git a/integration/src/release_scripts/getReleaseData.sh b/integration/src/release_scripts/getReleaseData.sh index 3d3bad9d..4afd1bd9 100755 --- a/integration/src/release_scripts/getReleaseData.sh +++ b/integration/src/release_scripts/getReleaseData.sh @@ -22,9 +22,10 @@ set -e -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") repo_location="./" release_data_file="./pf_release_data.csv" +branch="master" # Use the bash internal OSTYPE variable to check for MacOS if [[ "$OSTYPE" == "darwin"* ]] @@ -59,18 +60,22 @@ usage() echo "" echo " options" echo " -h - this help message" + echo " -b branch - the branch to release on, defaults to '$branch'" echo " -d data_file - the policy release data file to create, defaults to '$release_data_file'" echo " -l location - the location of the policy framework repos on the file system," echo " defaults to '$repo_location'" exit 255; } -while getopts "hd:l:" opt +while getopts "hb:d:l:" opt do case $opt in h) usage ;; + b) + branch=$OPTARG + ;; d) release_data_file=$OPTARG ;; @@ -84,15 +89,15 @@ do esac done -if [ $OPTIND -eq 1 ] +if [[ -z "$repo_location" ]] then - echo "no arguments were specified" - usage + echo "policy repo location not specified on -l flag" + exit 1 fi -if [[ -z "$repo_location" ]] +if [[ -z "$branch" ]] then - echo "policy repo location not specified on -l flag" + echo "policy branch not specified on -b flag" exit 1 fi @@ -113,15 +118,16 @@ update_repos() { for repo in "${pf_repos[@]}" do - echo "updating data from repo $repo to data file '$release_data_file' . . ." + echo "updating data from repo $repo branch $branch to data file '$release_data_file' . . ." - if [ -d $repo_location/$repo ] + if [ -d "$repo_location/$repo" ] then echo "updating repository '$repo' . . ." - git -C $repo_location/$repo checkout master - git -C $repo_location/$repo pull - git -C $repo_location/$repo rebase - git -C $repo_location/$repo fetch --tags + git -C "$repo_location/$repo" checkout -- . + git -C "$repo_location/$repo" checkout "$branch" + git -C "$repo_location/$repo" pull + git -C "$repo_location/$repo" rebase + git -C "$repo_location/$repo" fetch --tags else echo "repo $repo does not exist" exit 1 @@ -132,45 +138,54 @@ update_repos() { echo "policy framework data from '$repo_location' updated to data file '$release_data_file' . . ." } - get_tags() { - echo "Repo, Last Tag Version,Master Snapshot Version,Changed Files,Docker Images" - echo "repo, Last Tag Version,Master Snapshot Version,Changed Files,Docker Images" > $release_data_file + echo "Repo, Last Tag Version,Snapshot Version,Changed Files,Docker Images" + echo "repo, Last Tag Version,Snapshot Version,Changed Files,Docker Images" > "$release_data_file" for repo in "${pf_repos[@]}" do - latest_released_tag=`git -C $repo_location/$repo tag | \ - grep '^[0-9]*\.[0-9]*\.[0-9]*$' | \ - sort -V | \ - tail -1` - - latest_snapshot_tag=`mvn -f $repo_location/$repo clean | \ + latest_snapshot_tag=$(mvn -f "$repo_location/$repo" clean | \ grep "SNAPSHOT" | \ tail -1 | \ - $SED -r 's/^.* ([0-9]*\.[0-9]*\.[0-9]*-SNAPSHOT).*$/\1/'` + $SED -r 's/^.* ([0-9]*\.[0-9]*\.[0-9]*-SNAPSHOT).*$/\1/') + + if [[ $branch == *master ]] + then + latest_released_tag=$(git -C "$repo_location/$repo" tag | \ + grep '^[0-9]*\.[0-9]*\.[0-9]*$' | \ + sort -V | \ + tail -1) + else + # shellcheck disable=SC2001 + latest_snapshot_major_minor=$(echo "$latest_snapshot_tag" | sed 's/\.[0-9]*-SNAPSHOT$//') + latest_released_tag=$(git -C "$repo_location/$repo" tag | \ + grep '^[0-9]*\.[0-9]*\.[0-9]*$' | \ + grep "$latest_snapshot_major_minor" | \ + sort -V | \ + tail -1) + fi - changed_files=`git -C $repo_location/$repo diff --name-only $latest_released_tag origin/master | \ + changed_files=$(git -C "$repo_location/$repo" diff --name-only "$latest_released_tag" "$branch" | \ grep -v 'pom.xml$' | \ grep -v '^version.properties$' | \ grep -v "^releases/$latest_released_tag.yaml$" | \ - grep -v "^releases/$latest_released_tag-container.yaml$" | \ - wc -l | \ - $SED 's/^[[:space:]]*//g'` + grep -cv "^releases/$latest_released_tag-container.yaml$" | \ + $SED 's/^[[:space:]]*//g') - if [ -f $repo_location/$repo/releases/$latest_released_tag-container.yaml ] + latest_container_yaml=$(find "$repo_location/$repo/releases" -name "*container.yaml" | sort | tail -1) + if [ "$latest_container_yaml" != "" ] then - docker_images=`grep '\- name:' $repo_location/$repo/releases/$latest_released_tag-container.yaml | \ + docker_images=$(grep '\- name:' "$latest_container_yaml" | \ $SED -e 's/\- //g' -e 's/\://g' -e "s/\'//g" -e 's/^[[:space:]]*//g' -e 's/^name //' | \ tr '\n' ':' | \ - $SED 's/:$//'` + $SED 's/:$//') else docker_images="" fi echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images" - echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images" >> $release_data_file + echo "$repo,$latest_released_tag,$latest_snapshot_tag,$changed_files,$docker_images" >> "$release_data_file" done } update_repos get_tags - diff --git a/integration/src/release_scripts/mkart.sh b/integration/src/release_scripts/mkart.sh index 62ec0302..2243e293 100755 --- a/integration/src/release_scripts/mkart.sh +++ b/integration/src/release_scripts/mkart.sh @@ -65,7 +65,7 @@ if [ -z "${BRANCH}" ]; then echo "cannot extract default branch from ${TOPDIR}/.gitreview" >&2 exit 1 fi -echo Branch: ${BRANCH} +echo Branch: "${BRANCH}" PROJECT=$(awk -F= '$1 == "project" { print $2 }' "${TOPDIR}/.gitreview" | $SED 's/.git$//') @@ -73,9 +73,8 @@ if [ -z "${PROJECT}" ]; then echo "cannot extract project from ${TOPDIR}/.gitreview" >&2 exit 1 fi -echo Project: ${PROJECT} -TPROJ=$(echo ${PROJECT} | $SED 's!/!%2F!') -DPROJ=$(echo ${PROJECT} | $SED 's!/!-!') +echo Project: "${PROJECT}" +DPROJ=$(echo "${PROJECT}" | $SED 's!/!-!') VERSION=$( xmllint --xpath \ @@ -87,11 +86,11 @@ if [ -z "${VERSION}" ]; then echo "cannot extract version from ${TOPDIR}/pom.xml" >&2 exit 1 fi -echo Version: ${VERSION} +echo "Version: ${VERSION}" prefix='https://jenkins.onap.org/view/policy/job/' STAGE_ID=$( - curl --silent ${prefix}${DPROJ}-maven-stage-${BRANCH}/ | + curl --silent "${prefix}${DPROJ}-maven-stage-${BRANCH}/" | grep "Last completed build" | $SED -e 's!.*Last completed build .#!!' -e 's!).*!!' | head -1 @@ -100,18 +99,19 @@ if [ -z "${STAGE_ID}" ]; then echo "cannot extract last maven stage ID from jenkins" >&2 exit 1 fi -STAGE_ID=${DPROJ}-maven-stage-${BRANCH}/${STAGE_ID}/ -echo Stage ID: ${STAGE_ID} +STAGE_ID="${DPROJ}-maven-stage-${BRANCH}/${STAGE_ID}/" +echo Stage ID: "${STAGE_ID}" prefix='https://jenkins.onap.org/view/policy/job/' -JOB_OUT=$(curl --silent ${prefix}${STAGE_ID}/console) +JOB_OUT=$(curl --silent "${prefix}${STAGE_ID}/consoleFull") echo "${JOB_OUT}" | grep -q "Finished: SUCCESS" +# shellcheck disable=SC2181 if [ $? -ne 0 ]; then echo "last jenkins build has not completed successfully" >&2 exit 1 fi -echo Creating ${TOPDIR}/releases/${VERSION}.yaml +echo Creating "${TOPDIR}/releases/${VERSION}.yaml" echo "distribution_type: 'maven'" > "${TOPDIR}/releases/${VERSION}.yaml" echo "version: '${VERSION}'" >> "${TOPDIR}/releases/${VERSION}.yaml" diff --git a/integration/src/release_scripts/mkdock.sh b/integration/src/release_scripts/mkdock.sh index 4f1b3e2c..0df4abad 100755 --- a/integration/src/release_scripts/mkdock.sh +++ b/integration/src/release_scripts/mkdock.sh @@ -47,6 +47,7 @@ else SED="sed" fi +# shellcheck disable=SC2166 if [ $# -lt 1 -o "$1" = "-?" ] then echo "arg(s): docker-container-name1 docker-container-name2 ..." >&2 @@ -64,7 +65,7 @@ if [ -z "${BRANCH}" ]; then echo "cannot extract default branch from ${TOPDIR}/.gitreview" >&2 exit 1 fi -echo Branch: ${BRANCH} +echo "Branch: ${BRANCH}" PROJECT=$(awk -F= '$1 == "project" { print $2 }' "${TOPDIR}/.gitreview" | $SED 's/.git$//') @@ -72,9 +73,8 @@ if [ -z "${PROJECT}" ]; then echo "cannot extract project from ${TOPDIR}/.gitreview" >&2 exit 1 fi -echo Project: ${PROJECT} -TPROJ=$(echo ${PROJECT} | $SED 's!/!%2F!') -DPROJ=$(echo ${PROJECT} | $SED 's!/!-!') +echo "Project: ${PROJECT}" +DPROJ=$(echo "${PROJECT}" | $SED 's!/!-!') RELEASE=$( xmllint --xpath \ @@ -86,18 +86,18 @@ if [ -z "${RELEASE}" ]; then echo "cannot extract release from ${TOPDIR}/pom.xml" >&2 exit 1 fi -echo Release: ${RELEASE} +echo "Release: ${RELEASE}" REF_ID=$(git log | grep commit | head -1 | awk '{ print $2 }') if [ -z "${REF_ID}" ]; then echo "cannot extract ref from 'git log'" >&2 exit 1 fi -echo Ref: ${REF_ID} +echo "Ref: ${REF_ID}" prefix='https://jenkins.onap.org/view/policy/job/' STAGE_ID=$( - curl --silent ${prefix}${DPROJ}-maven-docker-stage-${BRANCH}/ | + curl --silent "${prefix}${DPROJ}-maven-docker-stage-${BRANCH}/" | grep "Last completed build" | $SED -e 's!.*Last completed build .#!!' -e 's!).*!!' | head -1 @@ -107,17 +107,18 @@ if [ -z "${STAGE_ID}" ]; then exit 1 fi STAGE_ID=${DPROJ}-maven-docker-stage-${BRANCH}/${STAGE_ID} -echo Stage ID: ${STAGE_ID} +echo "Stage ID: ${STAGE_ID}" prefix='https://jenkins.onap.org/view/policy/job/' -JOB_OUT=$(curl --silent ${prefix}${STAGE_ID}/console) +JOB_OUT=$(curl --silent "${prefix}${STAGE_ID}/consoleFull") echo "${JOB_OUT}" | grep -q "Finished: SUCCESS" +# shellcheck disable=SC2181 if [ $? -ne 0 ]; then echo "last docker build has not completed successfully" >&2 exit 1 fi -echo Creating ${TOPDIR}/releases/${RELEASE}-container.yaml +echo "Creating ${TOPDIR}/releases/${RELEASE}-container.yaml" cat >"${TOPDIR}/releases/${RELEASE}-container.yaml" <&2 exit 1 fi - echo ${CONT_NAME} version: ${VERSION} + echo "${CONT_NAME} version: ${VERSION}" cat >>"${TOPDIR}/releases/${RELEASE}-container.yaml" <$next_release_version . . ." generateCommit.sh \ - -l $repo_location \ - -r $repo \ - -i $issue_id \ + -l "$repo_location" \ + -r "$repo" \ + -i "$issue_id" \ -e "Release $repo: $next_release_version" \ -m "This commit releases repo $repo." diff --git a/integration/src/release_scripts/releaseRepoImages.sh b/integration/src/release_scripts/releaseRepoImages.sh index d7c5bea3..0bcae6a4 100755 --- a/integration/src/release_scripts/releaseRepoImages.sh +++ b/integration/src/release_scripts/releaseRepoImages.sh @@ -20,9 +20,7 @@ # ============LICENSE_END================================================== # -set -e - -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") repo_location="./" release_data_file="./pf_release_data.csv" @@ -121,12 +119,13 @@ then exit 1 fi -read repo \ +# shellcheck disable=SC2034 +read -r repo \ latest_released_tag \ latest_snapshot_tag \ changed_files \ docker_images \ - <<< $( grep $specified_repo $release_data_file | tr ',' ' ' ) + <<< "$(grep "$specified_repo" "$release_data_file" | tr ',' ' ' )" if [ ! "$repo" = "$specified_repo" ] then @@ -138,7 +137,7 @@ next_release_version=${latest_snapshot_tag%-*} while true do - read -p "have you run 'stage_release' on the '$repo' repo? " yes_no + read -r -p "have you run 'stage_release' on the '$repo' repo? " yes_no case $yes_no in [Yy]* ) break ;; @@ -153,10 +152,16 @@ done if [ "$docker_images" != "" ] then - saved_current_dir=`pwd` - cd $repo_location/$repo - mkdock.sh `echo "$docker_images" | tr ':' " "` - cd $saved_current_dir + saved_current_dir=$(pwd) + cd "$repo_location/$repo" || exit 1 + # shellcheck disable=SC2046 + if ! mkdock.sh $(echo "$docker_images" | sed -e "s/'//g" -e "s/:/ /g") + then + echo "generation of docker image release container yaml file failed" + cd "$saved_current_dir" || exit 1 + exit 1 + fi + cd "$saved_current_dir" || exit 1 else echo "repo '$repo' does not have any docker images" exit 1 @@ -165,9 +170,9 @@ fi echo "generating commit for $repo docker image release: $latest_released_tag-->$next_release_version . . ." generateCommit.sh \ - -l $repo_location \ - -r $repo \ - -i $issue_id \ + -l "$repo_location" \ + -r "$repo" \ + -i "$issue_id" \ -e "Release docker images for $repo: $next_release_version" \ -m "This commit releases docker images for repo $repo." diff --git a/integration/src/release_scripts/updateOomImages.sh b/integration/src/release_scripts/updateOomImages.sh index e5a7d39c..ad337a8c 100755 --- a/integration/src/release_scripts/updateOomImages.sh +++ b/integration/src/release_scripts/updateOomImages.sh @@ -22,7 +22,7 @@ set -e -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") repo_location="./" release_data_file="./pf_release_data.csv" @@ -137,11 +137,13 @@ fi for specified_repo in "${pf_repos[@]}" do - read repo \ + # shellcheck disable=SC2034 + # shellcheck disable=SC2046 + read -r repo \ latest_released_tag \ latest_snapshot_tag \ changed_files docker_images \ - <<< $( grep $specified_repo $release_data_file | tr ',' ' ' ) + <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' ) if [ ! "$repo" = "$specified_repo" ] then @@ -154,12 +156,12 @@ do continue fi - for docker_image in `echo $docker_images | tr ':' ' '` + for docker_image in $(echo "$docker_images" | tr ':' ' ') do new_image="$docker_image:$latest_released_tag" echo "updating OOM image $new_image . . ." - find $repo_location/oom/kubernetes/policy/components \ + find "$repo_location/oom/kubernetes/policy/components" \ -name values.yaml \ -exec \ $SED -i \ @@ -172,9 +174,9 @@ done echo "generating OOM commit to update policy framework docker image versions . . ." generateCommit.sh \ - -l $repo_location \ + -l "$repo_location" \ -r oom \ - -i $issue_id \ + -i "$issue_id" \ -e "[POLICY] Update docker images to latest versions" \ -m "The image versions in policy values.yaml files have been updated" diff --git a/integration/src/release_scripts/updateParentRef.sh b/integration/src/release_scripts/updateParentRef.sh index 0f10cfbb..0f72aa53 100755 --- a/integration/src/release_scripts/updateParentRef.sh +++ b/integration/src/release_scripts/updateParentRef.sh @@ -22,7 +22,7 @@ set -e -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") # Use the bash internal OSTYPE variable to check for MacOS if [[ "$OSTYPE" == "darwin"* ]] @@ -107,22 +107,24 @@ then exit 1 fi -pom_lines=`wc -l $pom_file | $SED 's/^[ \t]*//' | cut -f1 -d' '` -parent_start_line=`grep -n '^[\t ]*[\t ]*$' $pom_file | cut -f1 -d':'` -parent_end_line=`grep -n '^[\t ]*[\t ]*$' $pom_file | cut -f1 -d':'` +pom_lines=$(wc -l "$pom_file" | $SED 's/^[ \t]*//' | cut -f1 -d' ') +parent_start_line=$(grep -n '^[\t ]*[\t ]*$' "$pom_file" | cut -f1 -d':') +parent_end_line=$(grep -n '^[\t ]*[\t ]*$' "$pom_file" | cut -f1 -d':') pom_head_lines=$((parent_start_line-1)) pom_tail_lines=$((pom_lines-parent_end_line)) pom_temp_file=$(mktemp) -head -$pom_head_lines $pom_file > $pom_temp_file -echo " " >> $pom_temp_file -echo " $group_id" >> $pom_temp_file -echo " $artifact_id" >> $pom_temp_file -echo " $version" >> $pom_temp_file -echo " " >> $pom_temp_file -echo " " >> $pom_temp_file -tail -$pom_tail_lines $pom_file >> $pom_temp_file - -mv $pom_temp_file $pom_file +{ + head -$pom_head_lines "$pom_file" + echo " " + echo " $group_id" + echo " $artifact_id" + echo " $version" + echo " " + echo " " + tail -$pom_tail_lines "$pom_file" +} > "$pom_temp_file" + +mv "$pom_temp_file" "$pom_file" diff --git a/integration/src/release_scripts/updateRefs.sh b/integration/src/release_scripts/updateRefs.sh index ea677487..01ea31a0 100755 --- a/integration/src/release_scripts/updateRefs.sh +++ b/integration/src/release_scripts/updateRefs.sh @@ -22,7 +22,7 @@ set -e -SCRIPT_NAME=`basename $0` +SCRIPT_NAME=$(basename "$0") repo_location="./" release_data_file="./pf_release_data.csv" @@ -150,47 +150,59 @@ then exit 1 fi -read parent_repo \ +# shellcheck disable=SC2034 +# shellcheck disable=SC2046 +read -r parent_repo \ parent_latest_released_tag \ parent_latest_snapshot_tag \ parent_changed_files \ parent_docker_images \ - <<< $( grep policy/parent $release_data_file | tr ',' ' ' ) + <<< $(grep policy/parent "$release_data_file" | tr ',' ' ' ) -read common_repo \ +# shellcheck disable=SC2034 +# shellcheck disable=SC2046 +read -r common_repo \ common_latest_released_tag \ common_latest_snapshot_tag \ common_changed_files \ common_docker_images \ - <<< $( grep policy/common $release_data_file | tr ',' ' ' ) + <<< $(grep policy/common "$release_data_file" | tr ',' ' ' ) -read docker_repo \ +# shellcheck disable=SC2034 +# shellcheck disable=SC2046 +read -r docker_repo \ docker_latest_released_tag \ docker_latest_snapshot_tag \ docker_changed_files \ docker_docker_images \ - <<< $( grep policy/docker $release_data_file | tr ',' ' ' ) + <<< $(grep policy/docker "$release_data_file" | tr ',' ' ' ) -read models_repo \ +# shellcheck disable=SC2034 +# shellcheck disable=SC2046 +read -r models_repo \ models_latest_released_tag \ models_latest_snapshot_tag \ models_changed_files \ models_docker_images \ - <<< $( grep policy/models $release_data_file | tr ',' ' ' ) + <<< $(grep policy/models "$release_data_file" | tr ',' ' ' ) -read drools_pdp_repo \ +# shellcheck disable=SC2034 +# shellcheck disable=SC2046 +read -r drools_pdp_repo \ drools_pdp_latest_released_tag \ drools_pdp_latest_snapshot_tag \ drools_pdp_changed_files \ drools_pdp_docker_images \ - <<< $( grep policy/drools-pdp $release_data_file | tr ',' ' ' ) + <<< $(grep policy/drools-pdp "$release_data_file" | tr ',' ' ' ) -read target_repo \ +# shellcheck disable=SC2034 +# shellcheck disable=SC2046 +read -r target_repo \ target_latest_released_tag \ target_latest_snapshot_tag \ target_changed_files \ target_docker_images \ - <<< $( grep $specified_repo $release_data_file | tr ',' ' ' ) + <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' ) if [ -z "$target_repo" ] then @@ -210,45 +222,52 @@ then then if [ "$update_snapshot" = true ] then - echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . . + major_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^([0-9]*)\.[0-9]*\.[0-9]*$/\1/') + minor_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.([0-9]*)\.[0-9]*$/\1/') + patch_version=$(echo "$parent_latest_released_tag" | $SED -E 's/^[0-9]*\.[0-9]*\.([0-9]*)$/\1/') + new_patch_version=$(("$patch_version"+1)) + + new_snapshot_tag="$major_version"."$minor_version"."$new_patch_version"-SNAPSHOT + + echo updating policy parent reference to "$new_snapshot_tag" on "$repo_location/$target_repo" . . . $SED -i \ - "s/.*<\/version.parent.resources>/$parent_latest_snapshot_tag<\/version.parent.resources>/" \ - $repo_location/policy/parent/integration/pom.xml + "s/.*<\/version.parent.resources>/$new_snapshot_tag<\/version.parent.resources>/" \ + "$repo_location/policy/parent/integration/pom.xml" result_code=$? else next_release_version=${parent_latest_snapshot_tag%-*} - echo updating policy parent reference to $next_release_version on $repo_location/$target_repo . . . + echo "updating policy parent reference to $next_release_version on $repo_location/$target_repo . . ." $SED -i \ "s/.*<\/version.parent.resources>/$next_release_version<\/version.parent.resources>/" \ - $repo_location/policy/parent/integration/pom.xml + "$repo_location/policy/parent/integration/pom.xml" result_code=$? fi else if [ "$update_snapshot" = true ] then - echo updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . . + echo "updating policy parent reference to $parent_latest_snapshot_tag on $repo_location/$target_repo . . ." updateParentRef.sh \ - -f $repo_location/$target_repo/pom.xml \ + -f "$repo_location/$target_repo/pom.xml" \ -g org.onap.policy.parent \ -a integration \ - -v $parent_latest_snapshot_tag + -v "$parent_latest_snapshot_tag" result_code=$? else - echo updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . . + echo "updating policy parent reference to $parent_latest_released_tag on $repo_location/$target_repo . . ." updateParentRef.sh \ - -f $repo_location/$target_repo/pom.xml \ + -f "$repo_location/$target_repo/pom.xml" \ -g org.onap.policy.parent \ -a integration \ - -v $parent_latest_released_tag + -v "$parent_latest_released_tag" result_code=$? fi fi if [[ "$result_code" -eq 0 ]] then - echo policy parent reference updated on $repo_location/$target_repo + echo "policy parent reference updated on $repo_location/$target_repo" else - echo policy parent reference update failed on $repo_location/$target_repo + echo "policy parent reference update failed on $repo_location/$target_repo" exit 1 fi fi @@ -257,25 +276,25 @@ if [ "$update_common" = true ] then if [ "$update_snapshot" = true ] then - echo updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . . + echo "updating policy common reference to $common_latest_snapshot_tag on $repo_location/$target_repo . . ." $SED -i \ -e "s/.*<\/policy.common.version>/$common_latest_snapshot_tag<\/policy.common.version>/" \ -e "s/.*<\/version.policy.common>/$common_latest_snapshot_tag<\/version.policy.common>/" \ - $repo_location/$target_repo/pom.xml + "$repo_location/$target_repo/pom.xml" result_code=$? else - echo updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . . + echo "updating policy common reference to $common_latest_released_tag on $repo_location/$target_repo . . ." $SED -i \ -e "s/.*<\/policy.common.version>/$common_latest_released_tag<\/policy.common.version>/" \ -e "s/.*<\/version.policy.common>/$common_latest_released_tag<\/version.policy.common>/" \ - $repo_location/$target_repo/pom.xml + "$repo_location/$target_repo/pom.xml" result_code=$? fi if [[ "$result_code" -eq 0 ]] then - echo policy common reference updated on $repo_location/$target_repo + echo "policy common reference updated on $repo_location/$target_repo" else - echo policy common reference update failed on $repo_location/$target_repo + echo "policy common reference update failed on $repo_location/$target_repo" exit 1 fi fi @@ -284,25 +303,25 @@ if [ "$update_models" = true ] then if [ "$update_snapshot" = true ] then - echo updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . . + echo "updating policy models reference to $models_latest_snapshot_tag on $repo_location/$target_repo . . ." $SED -i \ -e "s/.*<\/policy.models.version>/$models_latest_snapshot_tag<\/policy.models.version>/" \ -e "s/.*<\/version.policy.models>/$models_latest_snapshot_tag<\/version.policy.models>/" \ - $repo_location/$target_repo/pom.xml + "$repo_location/$target_repo/pom.xml" result_code=$? else - echo updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . . + echo "updating policy models reference to $models_latest_released_tag on $repo_location/$target_repo . . ." $SED -i \ -e "s/.*<\/policy.models.version>/$models_latest_released_tag<\/policy.models.version>/" \ -e "s/.*<\/version.policy.models>/$models_latest_released_tag<\/version.policy.models>/" \ - $repo_location/$target_repo/pom.xml + "$repo_location/$target_repo/pom.xml" result_code=$? fi if [[ "$result_code" -eq 0 ]] then - echo policy models reference updated on $repo_location/$target_repo + echo "policy models reference updated on $repo_location/$target_repo" else - echo policy models reference update failed on $repo_location/$target_repo + echo "policy models reference update failed on $repo_location/$target_repo" exit 1 fi fi @@ -311,41 +330,41 @@ if [ "$update_drools_pdp" = true ] then if [ "$update_snapshot" = true ] then - echo updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . . + echo "updating policy drools-pdp reference to $drools_pdp_latest_snapshot_tag on $repo_location/$target_repo . . ." $SED -i \ -e "s/.*<\/policy.drools-pdp.version>/$drools_pdp_latest_snapshot_tag<\/policy.drools-pdp.version>/" \ -e "s/.*<\/version.policy.drools-pdp>/$drools_pdp_latest_snapshot_tag<\/version.policy.drools-pdp>/" \ - $repo_location/$target_repo/pom.xml + "$repo_location/$target_repo/pom.xml" result_code=$? else - echo updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . . + echo "updating policy drools-pdp reference to $drools_pdp_latest_released_tag on $repo_location/$target_repo . . ." $SED -i \ -e "s/.*<\/policy.drools-pdp.version>/$drools_pdp_latest_released_tag<\/policy.drools-pdp.version>/" \ -e "s/.*<\/version.policy.drools-pdp>/$drools_pdp_latest_released_tag<\/version.policy.drools-pdp>/" \ - $repo_location/$target_repo/pom.xml + "$repo_location/$target_repo/pom.xml" result_code=$? fi if [[ "$result_code" -eq 0 ]] then - echo policy drools-pdp reference updated on $repo_location/$target_repo + echo "policy drools-pdp reference updated on $repo_location/$target_repo" else - echo policy drools-pdp reference update failed on $repo_location/$target_repo + echo "policy drools-pdp reference update failed on $repo_location/$target_repo" exit 1 fi fi if [ "$update_docker" = true ] && [ "$target_docker_images" != "" ] then - echo updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo - find $repo_location/$target_repo \ + echo "updating docker base images to version $docker_latest_released_tag on repo $repo_location/$target_repo . . ." + find "$repo_location/$target_repo" \ -name '*Docker*' \ -exec $SED -r -i "s/^(FROM onap\/policy-j[d|r][k|e]-alpine:)2.3.1$/\1$docker_latest_released_tag/" {} \; result_code=$? if [[ "$result_code" -eq 0 ]] then - echo docker base images updated on $repo_location/$target_repo + echo "docker base images updated on $repo_location/$target_repo" else - echo docker base images update failed on $repo_location/$target_repo + echo "docker base images update failed on $repo_location/$target_repo" exit 1 fi fi -- cgit 1.2.3-korg