-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tested these scripts with github.com/cenamiller/samurai_test as the p…
…rivate repo duplicated from the public samurai repo
- Loading branch information
1 parent
b46153a
commit 2c357bf
Showing
2 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#!/usr/bin/env bash | ||
################################################################## | ||
# This script is intended to update our release version of | ||
# clubb (the one "publicly" visible). It should be ran nightly. | ||
# | ||
# Input options: | ||
# * source repo: URL for the original repo (the repo yours was forked from) | ||
# * destination repo: URL for your repo | ||
# * source branch: branch you want to pull updates from (defaults to master) | ||
# * destination branch: branch you want to push updates to (defaults to master) | ||
# * force update: adds the '-f' flag to the push command, thus force pushes | ||
# * mirror (-m): update all branches (as long as they have the same name) | ||
# | ||
# More usage info can be found here: | ||
# https://github.com/larson-group/sys_admin/wiki/GitUpdateScripts#updategitforksh | ||
# | ||
# Author: Nicolas Strike, 2018 | ||
################################################################## | ||
workdir=/tmp/temprepo | ||
srcbranch=main | ||
destbranch=main | ||
mirror="" | ||
forceupdate="" | ||
email=0 | ||
allbranches=0 | ||
tags="" | ||
maxNetworkAttempts=15 | ||
internetConnectivityTestUrl="github.com" | ||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-s | --source-repo ) shift | ||
srcrepo=$1 | ||
;; | ||
-d | --destination-repo ) shift | ||
destrepo=$1 | ||
;; | ||
--source-branch ) shift | ||
srcbranch=$1 | ||
;; | ||
--dest-branch ) shift | ||
destbranch=$1 | ||
;; | ||
-f | --force-update ) forceupdate="-f" | ||
;; | ||
-m | --mirror ) destbranch="--mirror" | ||
;; | ||
-a | --all-branches ) allbranches=1 | ||
;; | ||
-e | --enable-email ) email=1 | ||
;; | ||
-t | --tags ) tags="--tags" | ||
;; | ||
-h | --help ) usage | ||
exit | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
|
||
networkSafeOperation(){ | ||
#limited to 8 arguments, see below | ||
|
||
tryAgain="true" | ||
netAttempts=$maxNetworkAttempts | ||
# initial wait time before the second network attempt in seconds. | ||
# Sequential attempts get a x2 multiplier | ||
netWaitDelay=2 | ||
while [ $tryAgain == "true" -a $netAttempts -gt 0 ]; do | ||
|
||
#Run the given command with up to 8 arguments | ||
$1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
|
||
cloneCode=$? | ||
netAttempts=$((netAttempts-1)) | ||
#check if the repo successfully cloned | ||
if [ $cloneCode == 0 ] | ||
then | ||
tryAgain="false" | ||
else | ||
echo "Testing network connectivity." | ||
ping -c 4 $internetConnectivityTestUrl | ||
pingCode=$? | ||
if [ $pingCode != 0 ] | ||
then | ||
echo "Failed to perform network operation '$1 $2 $3 $4 $5 $6 $7' due to a network issue. $netAttempts attempts left, waiting $netWaitDelay seconds." | ||
sleep $netWaitDelay | ||
netWaitDelay=$((netWaitDelay*2)) | ||
else | ||
echo "Failed to perform operation '$1 $2 $3 $4 $5 $6 $7', but no network issue was detected. This must be handeled manually and is likely a git conflict." | ||
tryAgain="false" | ||
#pingCode | ||
fi | ||
#cloneCode | ||
fi | ||
done | ||
} | ||
|
||
rm -rf $workdir | ||
networkSafeOperation git clone $srcrepo $workdir --mirror | ||
|
||
cd $workdir | ||
git remote add destination_repo $destrepo | ||
|
||
networkSafeOperation git fetch $tags | ||
echo "Pushing updates from $srcrepo:$srcbranch to $destrepo:$destbranch" | ||
if [ $allbranches != 0 ] | ||
then | ||
# Alert user a parameter will be ignored # | ||
if [ $destbranch == "--mirror" ] | ||
then | ||
echo "The mirror is not compatible with the allbranches parameter, it will be ignored. All branches will still be pushed using a for-each branch loop instead of using git mirror. The difference is branches on the destination repo will not be deleted, whereas the would've been if --mirror was used." | ||
fi | ||
if [ $srcbranch != "master" ] | ||
then | ||
echo "The source branch parameter is being ignored because --all-branches was passed. All branches on the source repo will be pushed to the same branch on the destination repo." | ||
fi | ||
# ---------------------------------------- | ||
# Finally push the updates | ||
for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do | ||
networkSafeOperation git push $forceupdate -u destination_repo $branch $tags | ||
done | ||
else | ||
networkSafeOperation git push $forceupdate -u destination_repo refs/heads/$srcbranch:refs/heads/$destbranch $tags | ||
fi | ||
errorsDetected=$? | ||
wait | ||
|
||
|
||
cd - | ||
rm -rf $workdir | ||
|
||
##################################################################################################### | ||
#This sends out an email notification to system admins if any errors were detected during runtime. | ||
# The content of the email can be found in $emailMessage | ||
##################################################################################################### | ||
sendEmailNotification(){ | ||
|
||
if [ $errorsDetected != 0 ] | ||
then | ||
echo "Errors during run detected. Sending email notification." | ||
#Set the email | ||
[email protected] | ||
echo -e "Hello,\nWhen attempting to automatically update $destrepo:$destbranch from $srcrepo:$srcbranch there was an issue. Please run the updateGitFork.sh script manually. Additional troubleshooting info can be found here: https://github.com/larson-group/sys_admin/wiki/GitUpdateScripts \n\n`date +%Y-%m-%d` fork autoupdate script `hostname`\n\nThank you,\n Team Nightly" | mail -s "Fork autoupdate script errors: `hostname`" $EMAIL | ||
exit 1 | ||
else | ||
echo "No errors detected. Run successful." | ||
fi | ||
} | ||
if [ $email -eq 1 ] | ||
then | ||
sendEmailNotification | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################## | ||
# This script is intended to update our release version of | ||
# clubb (the one "publicly" visible). It should be ran nightly. | ||
# | ||
# Author: Nicolas Strike, 2019 | ||
################################################################## | ||
|
||
# To add a new branch from clubb to clubb_release, simply add it to the array here and it will be added overnight and updated automatically. Note that there must be a space between items and the parethesis. | ||
branches=( main thermo_asap) | ||
|
||
# List of patterns describing lfs files to untrack in git-lfs. This prevents them from being automatically downloaded when a client clones the repo, but leaves them available to download if desired (with `git lfs pull`) | ||
undesiredLfsPatterns=( ) | ||
|
||
|
||
maxNetworkAttempts=15 | ||
internetConnectivityTestUrl="github.com" | ||
|
||
# Need to fill in name of private development samurai repo (Probably [email protected]:NCAR/samurai.git) | ||
updateSrc= | ||
[email protected]:mmbell/samurai.git | ||
|
||
updateBranch() { | ||
bash updateGitFork.sh --source-repo $updateSrc --destination-repo $updateDest --source-branch $1 --dest-branch $1 -f -t | ||
} | ||
|
||
networkSafeOperation (){ | ||
#limited to 8 arguments, see below | ||
|
||
tryAgain="true" | ||
netAttempts=$maxNetworkAttempts | ||
# initial wait time before the second network attempt in seconds. | ||
# Sequential attempts get a x2 multiplier | ||
netWaitDelay=2 | ||
while [ $tryAgain == "true" -a $netAttempts -gt 0 ]; do | ||
|
||
#Run the given command with up to 8 arguments | ||
$1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
|
||
cloneCode=$? | ||
netAttempts=$((netAttempts-1)) | ||
#check if the repo successfully cloned | ||
if [ $cloneCode == 0 ] | ||
then | ||
tryAgain="false" | ||
else | ||
echo "Testing network connectivity." | ||
ping -c 4 $internetConnectivityTestUrl | ||
pingCode=$? | ||
if [ $pingCode != 0 ] | ||
then | ||
echo "Failed to perform network operation '$1 $2 $3 $4 $5 $6 $7' due to a network issue. $netAttempts attempts left, waiting $netWaitDelay seconds." | ||
sleep $netWaitDelay | ||
netWaitDelay=$((netWaitDelay*2)) | ||
else | ||
echo "Failed to perform operation '$1 $2 $3 $4 $5 $6 $7', but no network issue was detected. This must be handeled manually and is likely a git conflict." | ||
tryAgain="false" | ||
#pingCode | ||
fi | ||
#cloneCode | ||
fi | ||
done | ||
} | ||
|
||
updateVersionFiles(){ | ||
rm -rf /tmp/temp_release_repo | ||
networkSafeOperation git clone $updateDest /tmp/temp_release_repo | ||
cd /tmp/temp_release_repo | ||
git log -10 > src/CLUBB_core/version_clubb_core.txt | ||
git log -10 > src/SILHS/version_silhs.txt | ||
git add src/CLUBB_core/version_clubb_core.txt src/SILHS/version_silhs.txt | ||
git commit -a -m "Updating the clubb core and silhs version files" | ||
networkSafeOperation git push | ||
cd - | ||
rm -rf /tmp/temp_release_repo | ||
} | ||
|
||
untrackLfs(){ | ||
for i in "${undesiredLfsPatterns[@]}" | ||
do | ||
git lfs untrack $i | ||
done | ||
} | ||
|
||
updateAllBranches(){ | ||
for i in "${branches[@]}" | ||
do | ||
updateBranch $i | ||
done | ||
} | ||
|
||
printf "\n\n######################################\nUpdating repo at $updateDest from $updateSrc\n######################################\n" | ||
|
||
printf "\n###### Updating all branches ######\n" | ||
updateAllBranches | ||
printf "Done updating branches.\n" | ||
|
||
#printf "\n###### Updating untracking lfs files ######\n" | ||
# untrackLfs | ||
#printf "Done untracking lfs files.\n" | ||
|
||
#printf "\n###### Updating version files ######\n" | ||
# updateVersionFiles | ||
#printf "Done updating version files\n" | ||
|
||
printf "\n###### DONE ######\n" |