-
Notifications
You must be signed in to change notification settings - Fork 4
/
nightlies_job.sh
executable file
·135 lines (113 loc) · 3.88 KB
/
nightlies_job.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
echo "Running nightlies job at $(date)"
GITHUB_API_HEADER="Accept: application/vnd.github.v3+json"
GITHUB_API_URI="https://api.github.com"
github_get() {
local -r api="$1"
body=$(curl -sSL -H "$GITHUB_API_HEADER" "$GITHUB_API_URI/$api")
echo "$body"
}
update_submodule() {
local plugin="$1"
local commit="$2"
cd "plugins/$plugin"
cd */
git fetch origin
git checkout "$commit"
cd ../../../
}
declare -a plugins_to_update=()
update_needed=1
for plugin in plugins/*/
do
plugin=${plugin%*/}
plugin=${plugin##*/}
echo "Checking update status for $plugin"
metadata="plugins/$plugin/metadata.json"
repo=$(jq -r '.repo' "$metadata")
hash=$(jq -r '.hash' "$metadata")
default_branch=$(jq -r '.branch' "$metadata")
IFS='/' # set delimiter
read -ra vals <<< "$repo" # split repo url on '/'
repo_owner=${vals[-2]}
repo_name=${vals[-1]}
IFS=' ' # reset delimiter
latest_commit=$(github_get "repos/$repo_owner/$repo_name/commits/$default_branch")
latest_commit_hash=$(echo "$latest_commit" | jq -r '.sha')
echo "Latest commit: $latest_commit_hash"
if [ -z "${latest_commit_hash}" ]; then
echo "Unable to find last commit hash"
continue
fi
if [[ "$hash" == "$latest_commit_hash" ]]; then
echo "$plugin is up to date!"
continue
fi
echo "$plugin requires nightly update!"
sed -i "s/$hash/$latest_commit_hash/g" "$metadata"
update_submodule $plugin $latest_commit_hash
plugins_to_update+=($plugin)
update_needed=0
done
if [[ "$update_needed" == "1" ]]; then
echo "All plugins up to date!"
exit 0
fi
git_commit_msg="Update Nightlies:"
for plugin in "${plugins_to_update[@]}"
do
git_commit_msg="$git_commit_msg $plugin"
done
echo "Pushing git commit to trigger update..."
pat=$(cat ~/git_pat)
git commit -am "$git_commit_msg"
git push -u https://jatinchowdhury18:[email protected]/Chowdhury-DSP/releases.git main
sleep 60m
password=$(cat ~/ccrma_pass)
ssh_cmd="sshpass -p $password ssh -q -o StrictHostKeyChecking=no [email protected]"
scp_cmd="sshpass -p $password scp -o StrictHostKeyChecking=no [email protected]:"
ssh_dir="~/Library/Web/chowdsp/nightly_plugins"
nightly_dir=~/web/chowdspweb/nightly_plugins
for p in "${plugins_to_update[@]}"; do
update=1
if $ssh_cmd stat $ssh_dir/$p*-Mac* \> /dev/null 2\>\&1
then
echo "Nightly update found for $p Mac"
rm -f $nightly_dir/$p*-Mac*
$scp_cmd$ssh_dir/$p*-Mac* $nightly_dir/
$ssh_cmd "rm $ssh_dir/$p*-Mac*"
update=0
else
echo "No Nightly update found for $p Mac"
fi
if $ssh_cmd stat $ssh_dir/$p*-Win* \> /dev/null 2\>\&1
then
echo "Nightly update found for $p Win"
rm -f $nightly_dir/$p*-Win*
$scp_cmd$ssh_dir/$p*-Win* $nightly_dir/
$ssh_cmd "rm $ssh_dir/$p*-Win*"
update=0
else
echo "No Nightly update found for $p Win"
fi
if $ssh_cmd stat $ssh_dir/$p*-Linux* \> /dev/null 2\>\&1
then
echo "Nightly update found for $p Linux"
rm -f $nightly_dir/$p*-Linux*
$scp_cmd$ssh_dir/$p*-Linux* $nightly_dir/
$ssh_cmd "rm $ssh_dir/$p*-Linux*"
update=0
else
echo "No Nightly update found for $p Linux"
fi
if [[ "$update" -eq 0 ]]; then
echo "Latest build created on $(date)" > $nightly_dir/${p}_Info.txt
win_exe=$(cd $nightly_dir && ls $p*-Win-64bit*)
mac_dmg=$(cd $nightly_dir && ls $p*-Mac*)
lin_deb=$(cd $nightly_dir && ls $p*-Linux*)
sed -i -e "s/${p}.*Win-64bit.*.exe/$win_exe/g" ~/web/chowdspweb/nightly.js
sed -i -e "s/${p}.*Mac.*.dmg/$mac_dmg/g" ~/web/chowdspweb/nightly.js
sed -i -e "s/${p}.*Linux.*.deb/$lin_deb/g" ~/web/chowdspweb/nightly.js
fi
done
echo "FINISHED"