From 41dc5a83c19da9c273056d518bf1125a9efbb0b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Riette?= <sebastien.riette@meteo.fr>
Date: Fri, 21 Oct 2022 10:28:47 +0200
Subject: [PATCH] S. Riette 21 oct 2022: change github repository, add
 ial_version.json file

Add env variables and script options to define the git repository on github

Choice of the IAL version to use is now define by the content of the src/arom/ial_version.json file
---
 src/arome/ial_version.json      |  5 +++++
 tools/INSTALL_pack_ial.md       |  2 +-
 tools/check_commit_ial.sh       | 31 ++++++++++++++++++++++++++-----
 tools/check_commit_mesonh.sh    |  7 ++++++-
 tools/check_commit_testprogs.sh |  6 ++++++
 tools/prep_code.sh              | 20 ++++++++++++++------
 6 files changed, 58 insertions(+), 13 deletions(-)
 create mode 100644 src/arome/ial_version.json

diff --git a/src/arome/ial_version.json b/src/arome/ial_version.json
new file mode 100644
index 000000000..655712265
--- /dev/null
+++ b/src/arome/ial_version.json
@@ -0,0 +1,5 @@
+{
+"cycle":"48t3",
+"branch":"main",
+"version":"01"
+}
diff --git a/tools/INSTALL_pack_ial.md b/tools/INSTALL_pack_ial.md
index c29f2ee3b..87f4c2564 100644
--- a/tools/INSTALL_pack_ial.md
+++ b/tools/INSTALL_pack_ial.md
@@ -226,7 +226,7 @@ commit=9ce8119430dd603d35308d8ae94cf18636157473 #exemple of commit to test again
 gmkpack -r ${cycle} -b phyex -v ${version} -l ${compiler} -o ${option} -p masterodb -f $TRUNK -u PHYEX/$commit
 
 cd $HOMEPACK/PHYEX/$commit/src/local/phyex
-git clone git@github.com:QuentinRodier/PHYEX.git
+git clone git@github.com:UMR-CNRM/PHYEX.git
 cd PHYEX
 git checkout $commit
 #The exact manipulation to perform depends on the commit to test. For a full description, please see the check\_commit\_ial.sh script
diff --git a/tools/check_commit_ial.sh b/tools/check_commit_ial.sh
index c08960720..44dc8955b 100755
--- a/tools/check_commit_ial.sh
+++ b/tools/check_commit_ial.sh
@@ -70,6 +70,10 @@ function usage {
   echo "--noexpand      do not use mnh_expand (code will be in array-syntax)"
   echo "-f              full compilation (do not use pre-compiled pack)"
   echo "--cycle CYCLE   to force using CYCLE"
+  echo "--repo-user     user hosting the PHYEX repository on github,"
+  echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
+  echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github,"
+  echo "                defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)"
   echo ""
   echo "If nothing is asked (compilation, running, check) everything is done"
   echo
@@ -106,6 +110,8 @@ while [ -n "$1" ]; do
     '--noexpand') useexpand=0;;
     '-f') fullcompilation=1;;
     '--cycle') cycle="$2"; shift;;
+    '--repo-user') export PHYEXREPOuser=$2; shift;;
+    '--repo-protocol') export PHYEXREPOprotocol=$2; shift;;
     #--) shift; break ;;
      *) if [ -z "${commit-}" ]; then
           commit=$1
@@ -159,7 +165,7 @@ if [ $check -eq 1 -a -z "${reference-}" ]; then
   exit 3
 fi
 
-function content2cycle {
+function apl_arome_content2cycle {
   # variable content_apl_arome must contain the source code of apl_arome.F90
   if grep CPG_DYN_TYPE <(echo $content_apl_arome) > /dev/null; then
     echo 48t3
@@ -168,13 +174,23 @@ function content2cycle {
   fi
 }
 
+function ial_version_content2cycle {
+  # variable content_ial_version must contain the source code of ial_version.json
+  content_ial_version=$content_ial_version python3 -c "import json; import os; print(json.loads(os.environ['content_ial_version'])['cycle'])"
+}
+
 #Name is choosen such as it can be produced with a main pack: PHYEX/${cycle}_XXXXXXXXX.01.${gmkpack_l}.${gmkpack_o}
 fromdir=''
 if echo $commit | grep '/' > /dev/null; then
   fromdir=$commit
   if [ "$cycle" == "" ]; then
-    content_apl_arome=$(scp $commit/src/arome/ext/apl_arome.F90 /dev/stdout)
-    cycle=$(content2cycle)
+    content_ial_version=$(scp $commit/src/arome/ial_version.json /dev/stdout 2>/dev/null || echo "")
+    if [ "$content_ial_version" == "" ]; then
+      content_apl_arome=$(scp $commit/src/arome/ext/apl_arome.F90 /dev/stdout)
+      cycle=$(apl_arome_content2cycle)
+    else
+      cycle=$(ial_version_content2cycle)
+    fi
   fi
   packBranch=$(echo $commit | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')
   name="PHYEX/${cycle}_${packBranch}.01.${gmkpack_l}.${gmkpack_o}"
@@ -189,8 +205,13 @@ elif echo $specialPack | grep -w $commit > /dev/null; then
 else
   packBranch="COMMIT$commit"
   if [ "$cycle" == "" ]; then
-    content_apl_arome=$(wget --no-check-certificate https://raw.githubusercontent.com/QuentinRodier/PHYEX/${commit}/src/arome/ext/apl_arome.F90 -O - 2>/dev/null)
-    cycle=$(content2cycle)
+    content_ial_version=$(wget --no-check-certificate https://raw.githubusercontent.com/$PHYEXREPOuser/PHYEX/${commit}/src/arome/ial_version.json -O - 2>/dev/null || echo "")
+    if [ "$content_ial_version" == "" ]; then
+      content_apl_arome=$(wget --no-check-certificate https://raw.githubusercontent.com/$PHYEXREPOuser/PHYEX/${commit}/src/arome/ext/apl_arome.F90 -O - 2>/dev/null)
+      cycle=$(apl_arome_content2cycle)
+    else
+      cycle=$(ial_version_content2cycle)
+    fi
   fi
   name="PHYEX/${cycle}_${packBranch}.01.${gmkpack_l}.${gmkpack_o}"
   [ $suppress -eq 1 -a -d $HOMEPACK/$name ] && rm -rf $HOMEPACK/$name
diff --git a/tools/check_commit_mesonh.sh b/tools/check_commit_mesonh.sh
index 73ee6a071..0e1fd6896 100755
--- a/tools/check_commit_mesonh.sh
+++ b/tools/check_commit_mesonh.sh
@@ -26,6 +26,10 @@ function usage {
   echo "-t              comma separated list of tests to execute"
   echo "                or ALL to execute all tests"
   echo "--expand        use mnh_expand (code will use do loops)"
+  echo "--repo-user     user hosting the PHYEX repository on github,"
+  echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
+  echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github,"
+  echo "                defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)"
   echo ""
   echo "If nothing is asked (compilation, running, check) everything is done"
   echo 
@@ -54,7 +58,8 @@ while [ -n "$1" ]; do
     '-C') check=1;;
     '-t') tests="$2"; shift;;
     '--expand') useexpand=1;;
-    #-b) param="$2"; shift ;;
+    '--repo-user') export PHYEXREPOuser=$2; shift;;
+    '--repo-protocol') export PHYEXREPOprotocol=$2; shift;;
     #--) shift; break ;;
      *) if [ -z "${commit-}" ]; then
           commit=$1
diff --git a/tools/check_commit_testprogs.sh b/tools/check_commit_testprogs.sh
index e62656864..782d0cb9f 100755
--- a/tools/check_commit_testprogs.sh
+++ b/tools/check_commit_testprogs.sh
@@ -39,6 +39,10 @@ function usage {
   echo "-t              comma separated list of tests to execute"
   echo "                or ALL to execute all tests"
   echo "--noexpand      do not use mnh_expand (code will be in array-syntax)"
+  echo "--repo-user     user hosting the PHYEX repository on github,"
+  echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
+  echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github,"
+  echo "                defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)"
   echo ""
   echo "If nothing is asked (compilation, running, check) everything is done"
   echo
@@ -69,6 +73,8 @@ while [ -n "$1" ]; do
     '-C') check=1;;
     '-t') tests="$2"; shift;;
     '--noexpand') useexpand=0;;
+    '--repo-user') export PHYEXREPOuser=$2; shift;;
+    '--repo-protocol') export PHYEXREPOprotocol=$2; shift;;
     #--) shift; break ;;
      *) if [ -z "${commit-}" ]; then
           commit=$1
diff --git a/tools/prep_code.sh b/tools/prep_code.sh
index 9d069e009..3e318344f 100755
--- a/tools/prep_code.sh
+++ b/tools/prep_code.sh
@@ -11,9 +11,6 @@ set -e
 
 
 ###### CONFIGURATION
-repository_https=https://github.com/QuentinRodier/PHYEX.git
-repository_ssh=git@github.com:QuentinRodier/PHYEX.git
-
 PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
 ###### COMMAND LINE ARGUMENTS
@@ -29,7 +26,8 @@ function usage {
   echo "-p                    push the result as a new branch"
   echo "-s SUB                subdiretory or file (under src) to consider when merging and applying mnh_expand"
   echo "--renameFf            rename .F90 into .f90"
-  echo "--ssh                 use ssh instead of https for git cloning"
+  echo "--repo                use this repository instead of the one derived (if any) from the env variables"
+  echo "                      PHYEXREPOuser (=$PHYEXREPOuser) and PHYEXREPOprotocol (=$PHYEXREPOprotocol)"
   echo "-v                    add verbosity (up to 3 -v)"
   echo ""
   echo "* If the -c option is not provided, DIRECTORY must already contain files and directory as if"
@@ -54,7 +52,17 @@ push=0
 subs=""
 renameFf=0
 verbose=0
-repository=$repository_https
+if [ -z "${PHYEXREPOprotocol-}" ]; then
+  repository=""
+else
+  if [ $PHYEXREPOprotocol == 'https' ]; then
+    repository=https://github.com/$PHYEXREPOuser/PHYEX.git
+  elif [ $PHYEXREPOprotocol == 'ssh' ]; then
+    repository=git@github.com:$PHYEXREPOuser/PHYEX.git
+  else
+    repository=""
+  fi
+fi
 
 while [ -n "$1" ]; do
   case "$1" in
@@ -65,7 +73,7 @@ while [ -n "$1" ]; do
     '-s') subs="$subs $2"; shift;;
     '-p') push=1;;
     '--renameFf') renameFf=1;;
-    '--ssh') repository=$repository_ssh;;
+    '--repo') repository=$2; shift;;
     '-v') verbose=$(($verbose+1));;
      *) directory="$1";;
   esac
-- 
GitLab