-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefresh-repo.sh
executable file
·97 lines (88 loc) · 3.23 KB
/
refresh-repo.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
#!/bin/bash
# set -eou pipefail
SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}"))
SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
GITHUB_USER=${GITHUB_USER:-1gtm}
PR_BRANCH=kubeops-repo-refresher # -$(date +%s)
COMMIT_MSG="Update dependencies"
REPO_ROOT=/tmp/kubeops-repo-refresher
KUBEDB_API_REF=${KUBEDB_API_REF:-master}
repo_uptodate() {
# gomodfiles=(go.mod go.sum vendor/modules.txt)
gomodfiles=(go.sum vendor/modules.txt)
changed=($(git diff --name-only))
changed+=("${gomodfiles[@]}")
# https://stackoverflow.com/a/28161520
diff=($(echo ${changed[@]} ${gomodfiles[@]} | tr ' ' '\n' | sort | uniq -u))
return ${#diff[@]}
}
refresh() {
echo "refreshing repository: $1"
rm -rf $REPO_ROOT
mkdir -p $REPO_ROOT
pushd $REPO_ROOT
git clone --no-tags --no-recurse-submodules --depth=1 https://${GITHUB_USER}:${GITHUB_TOKEN}@$1.git
cd $(ls -b1)
git checkout -b $PR_BRANCH
if [ -f go.mod ]; then
# if [ "$1" != "github.com/kubeops/apimachinery" ]; then
# go mod edit \
# -require kubeops.dev/apimachinery@${KUBEDB_API_REF}
# go mod tidy
# fi
go mod edit \
-require=kmodules.xyz/client-go@dd0503cf99cf3b6abb635d8945a8d7d8fed901d9 \
-require=kmodules.xyz/webhook-runtime@e489faf01981d2f3afa671989388c7b6f22b6baa \
-require=kmodules.xyz/resource-metadata@dcc1abc08aa00646b9474f7702b45c798b3ce66c \
-require=kmodules.xyz/custom-resources@83db827677cf5651491478fa85707d62416cf679 \
-replace=github.com/satori/go.uuid=github.com/gofrs/uuid@v4.0.0+incompatible \
-replace=helm.sh/helm/v3=github.com/kubepack/helm/v3@v3.6.1-0.20210518225915-c3e0ce48dd1b \
-replace=k8s.io/apiserver=github.com/kmodules/apiserver@v0.21.2-0.20210716212718-83e5493ac170
go mod tidy
go mod vendor
fi
[ -z "$2" ] || (
echo "$2"
$2 || true
# run an extra make fmt because when make gen fails, make fmt is not run
make fmt || true
)
if repo_uptodate; then
echo "Repository $1 is up-to-date."
else
git add --all
if [[ "$1" == *"stashed"* ]]; then
git commit -a -s -m "$COMMIT_MSG" -m "/cherry-pick"
else
git commit -a -s -m "$COMMIT_MSG"
fi
git push -u origin $PR_BRANCH -f
hub pull-request \
--labels automerge \
--message "$COMMIT_MSG" \
--message "Signed-off-by: $(git config --get user.name) <$(git config --get user.email)>" || true
# gh pr create \
# --base master \
# --fill \
# --label automerge \
# --reviewer tamalsaha
fi
popd
}
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
echo "Correct usage: $SCRIPT_NAME <path_to_repos_list>"
exit 1
fi
if [ -x $GITHUB_TOKEN ]; then
echo "Missing env variable GITHUB_TOKEN"
exit 1
fi
# ref: https://linuxize.com/post/how-to-read-a-file-line-by-line-in-bash/#using-file-descriptor
while IFS=, read -r -u9 repo cmd; do
if [ -z "$repo" ]; then
continue
fi
refresh "$repo" "$cmd"
echo "################################################################################"
done 9<$1