Skip to content

Commit

Permalink
Merge branch 'develop' into feature/gw-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidNew-NOAA committed Nov 19, 2024
2 parents e1c16f8 + 2bcedf2 commit bad9b7d
Show file tree
Hide file tree
Showing 31 changed files with 729 additions and 225 deletions.
139 changes: 82 additions & 57 deletions ci/driver.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash --login

echo "Start at $(date)"

my_dir="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
echo "Set my_dir ${my_dir}"

# ==============================================================================
usage() {
Expand Down Expand Up @@ -51,79 +54,101 @@ esac
cd $GDAS_CI_ROOT/repo
CI_LABEL="${GDAS_CI_HOST}-RT"
gh pr list --label "$CI_LABEL" --state "open" | awk '{print $1;}' > $GDAS_CI_ROOT/open_pr_list

open_pr=`cat $GDAS_CI_ROOT/open_pr_list | wc -l`
if (( $open_pr == 0 )); then
echo "No open PRs with ${CI_LABEL}, exit."
echo "Finish at $(date)"
exit
fi

open_pr_list=$(cat $GDAS_CI_ROOT/open_pr_list)

# ==============================================================================
# clone, checkout, build, test, etc.
repo_url="https://github.com/NOAA-EMC/GDASApp.git"
# loop through all open PRs
for pr in $open_pr_list; do
gh pr edit $pr --remove-label $CI_LABEL --add-label ${CI_LABEL}-Running
echo "Processing Pull Request #${pr}"
echo " "
echo "Start processing Pull Request #${pr} at $(date)"

# get the branch name used for the PR
gdasapp_branch=$(gh pr view $pr --json headRefName -q ".headRefName")

# get the fork information
pr_details=$(gh pr view $pr --repo ${repo_url} --json headRepository,headRepositoryOwner,headRefName)

# extract the necessary info
fork_owner=$(gh pr view $pr --repo ${repo_url} --json headRepositoryOwner --jq '.headRepositoryOwner.login')
fork_name=$(gh pr view $pr --repo ${repo_url} --json headRepository --jq '.headRepository.name')

# construct the fork URL
gdasapp_url="https://github.com/$fork_owner/${fork_name}.git"
# get additional branch information
branch_owner=$(gh pr view $pr --repo ${repo_url} --json headRepositoryOwner --jq '.headRepositoryOwner.login')
branch_name=$(gh pr view $pr --repo ${repo_url} --json headRepository --jq '.headRepository.name')
pr_assignees=$(gh pr view $pr --repo ${repo_url} --json assignees --jq '.assignees[].login')

# check if any assignee is authorized to run CI
authorized_by=""
for str in ${pr_assignees[@]}; do
grep $str /scratch1/NCEPDEV/da/role.jedipara/CI/GDASApp/authorized_users
rc=$?
if (( rc == 0 )); then
authorized_by=${str}
echo "FOUND MATCH $str, rc $rc"
break
fi
done

# Authorized to run CI
if (( rc == 0 )); then
echo "Run CI"

# update PR label
gh pr edit $pr --remove-label $CI_LABEL --add-label ${CI_LABEL}-Running

# construct the fork URL
gdasapp_url="https://github.com/$branch_owner/${branch_name}.git"

echo "Fork URL: $gdasapp_url"
echo "Branch Name: $gdasapp_branch"

# create PR specific directory
if [ -d $GDAS_CI_ROOT/PR/$pr ]; then
rm -rf $GDAS_CI_ROOT/PR/$pr
fi
mkdir -p $GDAS_CI_ROOT/PR/$pr
cd $GDAS_CI_ROOT/PR/$pr

# clone copy of repo
git clone --recursive --jobs 8 --branch $gdasapp_branch $gdasapp_url
cd GDASApp

# checkout pull request
git pull
gh pr checkout $pr
git submodule update --init --recursive

# get commit hash
commit=$(git log --pretty=format:'%h' -n 1)
echo "$commit" > $GDAS_CI_ROOT/PR/$pr/commit

# load modules
case ${TARGET} in
hera | orion)
echo "Loading modules on $TARGET"
module purge
module use $GDAS_CI_ROOT/PR/$pr/GDASApp/modulefiles
module load GDAS/$TARGET
module list
;;
*)
echo "Unsupported platform. Exiting with error."
exit 1
;;
esac

# run build and testing command
$my_dir/run_ci.sh -d $GDAS_CI_ROOT/PR/$pr/GDASApp -o $GDAS_CI_ROOT/PR/$pr/output_${commit}
ci_status=$?
gh pr comment $pr --repo ${repo_url} --body-file $GDAS_CI_ROOT/PR/$pr/output_${commit}
if [ $ci_status -eq 0 ]; then
gh pr edit $pr --repo ${repo_url} --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Passed
echo "GDASApp URL: $gdasapp_url"
echo "GDASApp branch Name: $gdasapp_branch"
echo "CI authorized by $authorized_by at $(date)"

# create PR specific directory
if [ -d $GDAS_CI_ROOT/PR/$pr ]; then
rm -rf $GDAS_CI_ROOT/PR/$pr
fi
mkdir -p $GDAS_CI_ROOT/PR/$pr
cd $GDAS_CI_ROOT/PR/$pr
pwd

# clone copy of repo
git clone --recursive --jobs 8 --branch $gdasapp_branch $gdasapp_url
cd GDASApp
pwd

# checkout GDASApp pull request
git pull
gh pr checkout $pr
git submodule update --init --recursive

# get commit hash
commit=$(git log --pretty=format:'%h' -n 1)
echo "$commit" > $GDAS_CI_ROOT/PR/$pr/commit

# run build and testing command
echo "Execute $my_dir/run_ci.sh for $GDAS_CI_ROOT/PR/$pr/GDASApp at $(date)"
$my_dir/run_ci.sh -d $GDAS_CI_ROOT/PR/$pr/GDASApp -o $GDAS_CI_ROOT/PR/$pr/output_${commit}
ci_status=$?
echo "After run_ci.sh with ci_status ${ci_status} at $(date)"
gh pr comment $pr --repo ${repo_url} --body-file $GDAS_CI_ROOT/PR/$pr/output_${commit}
if [ $ci_status -eq 0 ]; then
gh pr edit $pr --repo ${repo_url} --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Passed
else
gh pr edit $pr --repo ${repo_url} --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Failed
fi

# Not authorized to run CI
else
gh pr edit $pr --repo ${repo_url} --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Failed
echo "Do NOT run CI"
fi

echo "Finish processing Pull Request #{pr} at $(date)"
done

# ==============================================================================
# scrub working directory for older files
find $GDAS_CI_ROOT/PR/* -maxdepth 1 -mtime +3 -exec rm -rf {} \;

echo "Finish at $(date)"
144 changes: 97 additions & 47 deletions ci/gw_driver.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash --login

echo "Start at $(date)"

my_dir="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
echo "Set my_dir ${my_dir}"

# ==============================================================================
usage() {
Expand Down Expand Up @@ -32,7 +35,7 @@ done

case ${TARGET} in
hera | orion)
echo "Running automated testing with workflow on $TARGET"
echo "Running Automated GW Testing on $TARGET"
source $MODULESHOME/init/sh
source $my_dir/${TARGET}.sh
module purge
Expand All @@ -51,69 +54,116 @@ esac
cd $GDAS_CI_ROOT/repo
CI_LABEL="${GDAS_CI_HOST}-GW-RT"
gh pr list --label "$CI_LABEL" --state "open" | awk '{print $1;}' > $GDAS_CI_ROOT/open_pr_list_gw

open_pr=`cat $GDAS_CI_ROOT/open_pr_list_gw | wc -l`
if (( $open_pr == 0 )); then
echo "No open PRs with ${CI_LABEL}, exit."
echo "Finish at $(date)"
exit
fi

open_pr_list=$(cat $GDAS_CI_ROOT/open_pr_list_gw)

# ==============================================================================
# clone, checkout, build, test, etc.
repo_url="https://github.com/NOAA-EMC/GDASApp.git"
workflow_url="https://github.com/NOAA-EMC/global-workflow.git"
workflow_branch="develop"
# loop through all open PRs
for pr in $open_pr_list; do
gh pr edit $pr --remove-label $CI_LABEL --add-label ${CI_LABEL}-Running
echo "Processing Pull Request #${pr}"
echo " "
echo "Start processing Pull Request #${pr} at $(date)"

# get the branch name used for the PR
gdasapp_branch=$(gh pr view $pr --json headRefName -q ".headRefName")

# check for a companion PR in the global-workflow
companion_pr_exists=$(gh pr list --repo ${workflow_url} --head ${gdasapp_branch} --state open)
if [ -n "$companion_pr_exists" ]; then
# get the PR number
companion_pr=$(echo "$companion_pr_exists" | awk '{print $1;}')

# extract the necessary info
fork_owner=$(gh pr view $companion_pr --repo $workflow_url --json headRepositoryOwner --jq '.headRepositoryOwner.login')
fork_name=$(gh pr view $companion_pr --repo $workflow_url --json headRepository --jq '.headRepository.name')

# Construct the fork URL
workflow_url="https://github.com/$fork_owner/$fork_name.git"

echo "Fork URL: $workflow_url"
echo "Branch Name: $gdasapp_branch"
fi

# create PR specific directory
if [ -d $GDAS_CI_ROOT/workflow/PR/$pr ]; then
rm -rf $GDAS_CI_ROOT/workflow/PR/$pr
fi
mkdir -p $GDAS_CI_ROOT/workflow/PR/$pr
cd $GDAS_CI_ROOT/workflow/PR/$pr
# get additional branch information
branch_owner=$(gh pr view $pr --repo ${repo_url} --json headRepositoryOwner --jq '.headRepositoryOwner.login')
branch_name=$(gh pr view $pr --repo ${repo_url} --json headRepository --jq '.headRepository.name')
pr_assignees=$(gh pr view $pr --repo ${repo_url} --json assignees --jq '.assignees[].login')

# check if any assignee is authorized to run CI
authorized_by=""
for str in ${pr_assignees[@]}; do
grep $str /scratch1/NCEPDEV/da/role.jedipara/CI/GDASApp/authorized_users
rc=$?
if (( rc == 0 )); then
authorized_by=${str}
echo "FOUND MATCH $str, rc $rc"
break
fi
done

# Authorized to run CI
if (( rc == 0 )); then
echo "Run CI"

# update PR label
gh pr edit $pr --remove-label $CI_LABEL --add-label ${CI_LABEL}-Running

# check for a companion PR in the global-workflow
companion_pr_exists=$(gh pr list --repo ${workflow_url} --head ${gdasapp_branch} --state open)
if [ -n "$companion_pr_exists" ]; then
# get the PR number
companion_pr=$(echo "$companion_pr_exists" | awk '{print $1;}')

# extract the necessary info
branch_owner=$(gh pr view $companion_pr --repo $workflow_url --json headRepositoryOwner --jq '.headRepositoryOwner.login')
branch_name=$(gh pr view $companion_pr --repo $workflow_url --json headRepository --jq '.headRepository.name')

# Construct fork URL. Update workflow branch name
workflow_url="https://github.com/$branch_owner/$branch_name.git"
workflow_branch=$gdasapp_branch

fi

echo "Workflow URL: $workflow_url"
echo "Workflow branch name: $workflow_branch"
echo "GDASApp branch name: $gdasapp_branch"
echo "CI authorized by $authorized_by at $(date)"

# create PR specific directory
if [ -d $GDAS_CI_ROOT/workflow/PR/$pr ]; then
rm -rf $GDAS_CI_ROOT/workflow/PR/$pr
fi
mkdir -p $GDAS_CI_ROOT/workflow/PR/$pr
cd $GDAS_CI_ROOT/workflow/PR/$pr
pwd

# clone global workflow develop branch
git clone --recursive --jobs 8 --branch dev/gdasapp $workflow_url

# checkout pull request
cd $GDAS_CI_ROOT/workflow/PR/$pr/global-workflow/sorc/gdas.cd
git checkout develop
git pull
gh pr checkout $pr
git submodule update --init --recursive

# get commit hash
commit=$(git log --pretty=format:'%h' -n 1)
echo "$commit" > $GDAS_CI_ROOT/workflow/PR/$pr/commit

$my_dir/run_gw_ci.sh -d $GDAS_CI_ROOT/workflow/PR/$pr/global-workflow -o $GDAS_CI_ROOT/workflow/PR/$pr/output_${commit}
ci_status=$?
gh pr comment $pr --body-file $GDAS_CI_ROOT/workflow/PR/$pr/output_${commit}
if [ $ci_status -eq 0 ]; then
gh pr edit $pr --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Passed
# clone global workflow develop branch
git clone --recursive --jobs 8 --branch $workflow_branch $workflow_url

# checkout GDASApp pull request
cd $GDAS_CI_ROOT/workflow/PR/$pr/global-workflow/sorc/gdas.cd
git pull
gh pr checkout $pr
git submodule update --init --recursive

# get commit hash
commit=$(git log --pretty=format:'%h' -n 1)
echo "$commit" > $GDAS_CI_ROOT/workflow/PR/$pr/commit

# run build and testing command
echo "Execute $my_dir/run_gw_ci.sh for $GDAS_CI_ROOT/PR/workflow/PR/$pr/global-workflow at $(date)"
$my_dir/run_gw_ci.sh -d $GDAS_CI_ROOT/workflow/PR/$pr/global-workflow -o $GDAS_CI_ROOT/workflow/PR/$pr/output_${commit}
ci_status=$?
echo "After run_gw_ci.sh with ci_status ${ci_status} at $(date)"
gh pr comment $pr --body-file $GDAS_CI_ROOT/workflow/PR/$pr/output_${commit}
if [ $ci_status -eq 0 ]; then
gh pr edit $pr --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Passed
else
gh pr edit $pr --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Failed
fi

# Not authorized to run CI
else
gh pr edit $pr --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Failed
echo "Do NOT run CI"
fi

echo "Finish processing Pull Request #{pr} at $(date)"
done

# ==============================================================================
# scrub working directory for older files
find $GDAS_CI_ROOT/workflow/PR/* -maxdepth 1 -mtime +3 -exec rm -rf {} \;

echo "Finish at $(date)"
4 changes: 2 additions & 2 deletions ci/run_ci.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
#set -eu
set -u

# ==============================================================================
usage() {
Expand Down Expand Up @@ -61,7 +61,7 @@ module use $GDAS_MODULE_USE
module load GDAS/$TARGET
echo "---------------------------------------------------" >> $outfile
rm -rf log.ctest
ctest -E "manual" -R gdasapp --output-on-failure &>> log.ctest
ctest -R gdasapp --output-on-failure &>> log.ctest
ctest_status=$?
npassed=$(cat log.ctest | grep "tests passed")
if [ $ctest_status -eq 0 ]; then
Expand Down
4 changes: 2 additions & 2 deletions ci/run_gw_ci.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
#set -eu
set -u

# ==============================================================================
usage() {
Expand Down Expand Up @@ -31,7 +31,7 @@ done

# ==============================================================================
# start output file
echo "Automated Global-Workflow GDASApp Testing Results:" > $outfile
echo "Automated GW GDASApp Testing Results:" > $outfile
echo "Machine: ${TARGET}" >> $outfile
echo '```' >> $outfile
echo "Start: $(date) on $(hostname)" >> $outfile
Expand Down
2 changes: 1 addition & 1 deletion parm/io/fv3jedi_fieldmetadata_fv3inc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ field metadata:
- long name: air_temperature
io name: T_inc

- long name: specific_humidity
- long name: water_vapor_mixing_ratio_wrt_moist_air
io name: sphum_inc

- long name: cloud_liquid_water
Expand Down
Loading

0 comments on commit bad9b7d

Please sign in to comment.