From fd440c3a44194a9dc0e506696d5956652bc691c6 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Sun, 8 Sep 2024 16:25:57 -0700 Subject: [PATCH] wip Signed-off-by: Tamal Saha --- restic-refresh.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 restic-refresh.sh diff --git a/restic-refresh.sh b/restic-refresh.sh new file mode 100755 index 0000000..39b3c7a --- /dev/null +++ b/restic-refresh.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# set -eou pipefail + +SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")) +SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}") + +OLD_VER=0.16.4 +NEW_VER=0.17.1 + +GITHUB_USER=${GITHUB_USER:-1gtm} +PR_BRANCH=restic_${NEW_VER} # -$(date +%s) +COMMIT_MSG="Use restic ${NEW_VER}" + +REPO_ROOT=/tmp/kubedb-repo-refresher + +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 git@github.com:$1.git + name=$(ls -b1) + cd $name + git checkout -b $PR_BRANCH + + sed -i "s|RESTIC_VER\([[:space:]]*\):= ${OLD_VER}|RESTIC_VER\1:= ${NEW_VER}|g" Makefile + + 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 HEAD -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 " + 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