-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·125 lines (111 loc) · 3.19 KB
/
script.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
check_uninstallable_packages () {
for branch in $(git branch --no-color | grep -v "main")
do
git show --pretty="" --name-only $branch | grep -q uninstallable
rc=$?
if [[ $rc = 0 ]]; then
echo $branch
fi
done
}
test_packages () {
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# If no argument, parse big json
if [ "$#" -eq 0 ]; then
packages=$(cat packages.json | jq .rows[].project)
fi
while getopts ":f:p:h" o; do
case "${o}" in
f)
packages=$(cat "$OPTARG" | jq .rows[].project)
;;
p)
packages="$OPTARG"
;;
h)
echo usage
;;
*)
echo fail
;;
esac
done
shift $((OPTIND-1))
for quoted_package in $packages
do
unquoted_package=${quoted_package//\"}
git rev-parse --quiet --verify $unquoted_package
rc=$?
if [[ $rc = 0 ]]; then
echo Package $unquoted_package is already handled
else
git checkout -b $unquoted_package
git push origin --delete $unquoted_package
poetry add $unquoted_package
rc=$?
if [[ $rc != 0 ]]; then
echo Package $unquoted_package failed to install with poetry
add_package_to_uninstallable_list $unquoted_package
git checkout main
git merge $unquoted_package
git branch -d $unquoted_package
else
git add --all
git commit -m $unquoted_package
git push
git checkout main
fi
fi
done
}
test_packages_simple () {
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# If no argument, parse big json
if [ "$#" -eq 0 ]; then
packages=$(cat packages.json | jq .rows[].project)
fi
while getopts ":f:p:h" o; do
case "${o}" in
f)
packages=$(cat "$OPTARG" | jq .rows[].project)
;;
p)
packages="$OPTARG"
;;
h)
echo usage
;;
*)
echo fail
;;
esac
done
shift $((OPTIND-1))
for quoted_package in $packages
do
unquoted_package=${quoted_package//\"}
git rev-parse --quiet --verify $unquoted_package
rc=$?
if [[ $rc = 0 ]]; then
echo Package $unquoted_package is already handled
else
git checkout -b $unquoted_package
git push -f
fi
done
}
add_package_to_uninstallable_list() {
uninstallable_package=$1
echo $uninstallable_package >> uninstallable_packages
git checkout -- poetry.lock
git add uninstallable_packages
git commit -m \""Uninstallable $uninstallable_package"\"
}
uninstall_poetry_packages() {
for branch in $(git branch --no-color | grep -v "main")
do
git checkout $branch
poetry remove $branch
git checkout -- .
done
}