-
Notifications
You must be signed in to change notification settings - Fork 21
/
publish
executable file
·51 lines (42 loc) · 1.37 KB
/
publish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -e
function finish {
kill $KEEPALIVE_PID
}
trap finish EXIT
DEPLOY_TO_BRANCH=$1
TARGET=$RANDOM
mkdir -p ~/uploading/$TARGET
cd ~/uploading/$TARGET
while true; do sleep 10; du -hs .; done &
KEEPALIVE_PID=$!
tar xzf - && date --iso-8601 > ~/uploading/$TARGET/done.txt
if [ ! -z "$DEPLOY_TO_BRANCH" ]
then
mv ~/uploading/www/branches/$DEPLOY_TO_BRANCH ~/uploading/branch.$TARGET.old || true
mkdir -p ~/uploading/www/branches
mv ~/uploading/$TARGET/ ~/uploading/www/branches/$DEPLOY_TO_BRANCH
rm -rf ~/uploading/branch.$TARGET.old || true
else
mv ~/uploading/www/fhir ~/uploading/fhir.$TARGET.old || true
mkdir -p ~/uploading/www
mv ~/uploading/$TARGET/ ~/uploading/www/fhir
rm -rf ~/uploading/fhir.$TARGET.old || true
fi
# Delete old branches
cd ~/uploading/www/branches
find . -maxdepth 1 -path ./master -prune -o -type d -ctime +21 -path './*' -exec rm -rf {} \;
# Delete branches that are no longer active
#NAMES=$(curl -s https://api.github.com/repos/HL7/fhir/branches | jq '.[].name')
#if [ ! -z "$NAMES" ] && [[ $NAMES = *"\"master\""* ]] # Ensure GH response present and sane
#then
# for i in $(ls -d */); do
# DIR_TO_CHECK=${i%%/}
# if [[ ! $NAMES = *\"$DIR_TO_CHECK\"* ]]
# then
# echo "Remove deleted branch: $DIR_TO_CHECK"
# rm -rf $DIR_TO_CHECK
# fi
# done
#fi
echo "fin"