Add release script, fix sed for MacOS
[policy/parent.git] / integration / src / release_scripts / getReleaseData.sh
index 19a41ea..3d3bad9 100755 (executable)
@@ -4,7 +4,7 @@
 # ============LICENSE_START================================================
 # ONAP
 # =========================================================================
-# Copyright (C) 2021 Nordix Foundation.
+# Copyright (C) 2021-2022 Nordix Foundation.
 # =========================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # ============LICENSE_END==================================================
 #
 
+set -e
+
 SCRIPT_NAME=`basename $0`
 repo_location="./"
 release_data_file="./pf_release_data.csv"
 
+# Use the bash internal OSTYPE variable to check for MacOS
+if [[ "$OSTYPE" == "darwin"* ]]
+then
+    SED="gsed"
+else
+    SED="sed"
+fi
+
 declare -a pf_repos=(
     "policy/parent"
     "policy/docker"
@@ -124,8 +134,8 @@ update_repos() {
 
 
 get_tags() {
-    echo "Last Tag version,Master Snapshot Version,Changed Files,Docker images"
-    echo "Last Tag version,Master Snapshot Version,Changed Files,Docker images" > $release_data_file
+    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
     for repo in "${pf_repos[@]}"
     do
         latest_released_tag=`git -C $repo_location/$repo tag | \
@@ -136,7 +146,7 @@ get_tags() {
         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/'`
 
         changed_files=`git -C $repo_location/$repo diff --name-only $latest_released_tag origin/master | \
             grep -v 'pom.xml$' | \
@@ -144,14 +154,14 @@ get_tags() {
             grep -v "^releases/$latest_released_tag.yaml$" | \
             grep -v "^releases/$latest_released_tag-container.yaml$" | \
             wc -l | \
-            sed 's/^[[:space:]]*//g'`
+            $SED 's/^[[:space:]]*//g'`
 
         if [ -f $repo_location/$repo/releases/$latest_released_tag-container.yaml ]
         then
             docker_images=`grep '\- name:' $repo_location/$repo/releases/$latest_released_tag-container.yaml | \
-            sed -e 's/\- //g' -e 's/\://g' -e "s/\'//g" -e 's/^[[:space:]]*//g' -e 's/^name //' | \
+            $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