Split
- move pusher to separate script - add getopt
This commit is contained in:
parent
abff01a7fe
commit
ecfcb53fd3
36
pusher
Executable file
36
pusher
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
tmpfile=$(mktemp pusher.XXXXXX)
|
||||||
|
cleanup()
|
||||||
|
{
|
||||||
|
rm -f "$tmpfile"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
. .settings
|
||||||
|
|
||||||
|
needed=(PUSH_URL PR_SRC_USER PR_TARGET TOKEN)
|
||||||
|
for i in "${needed[@]}"; do
|
||||||
|
eval test -n "\$$i" || { echo "The following settings are mandatory: ${needed[*]}"; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
declare -A commits
|
||||||
|
|
||||||
|
for m in "${!commits[@]}"; do
|
||||||
|
if git send-pack --force "$PUSH_URL" "${commits[$m]}:refs/heads/update_$m"; then
|
||||||
|
#https://github.com/go-gitea/gitea/issues/18842
|
||||||
|
if curl -s -f "$PR_TARGET" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{ \"base\": \"main\", \"head\": \"$PR_SRC_USER:update_$m\", \"title\": \"Update $m\"}" > "$tmpfile"; then
|
||||||
|
prid=$(jq .id < "$tmpfile")
|
||||||
|
echo "filed pr #$prid for $m"
|
||||||
|
else
|
||||||
|
echo "failed to file pr for $m"
|
||||||
|
jq .message < "$tmpfile"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "failed to push $m update" >&2
|
||||||
|
jq .message < "$tmpfile"
|
||||||
|
fi
|
||||||
|
done
|
@ -1,15 +1,34 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
allatonce=
|
allatonce=
|
||||||
pushurl="gitea@gitea.opensuse.org:lnussel/core.git"
|
|
||||||
prsrcusr="lnussel"
|
|
||||||
prtarget="https://gitea.opensuse.org/api/v1/repos/mold/core/pulls"
|
|
||||||
|
|
||||||
if [ "$1" = '--allatonce' ]; then
|
helpandquit()
|
||||||
allatonce=1
|
{
|
||||||
shift
|
cat <<-EOF
|
||||||
fi
|
Usage: $0 [OPTIONS] [<module> ...]
|
||||||
|
OPTIONS:
|
||||||
|
-allatonce create dir from filename before extracting
|
||||||
|
-h help screen
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
modules=($@)
|
getopttmp=$(getopt -o h --long help,allatonce -n "${0##*/}" -- "$@")
|
||||||
|
eval set -- "$getopttmp"
|
||||||
|
|
||||||
|
while true ; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help) helpandquit; shift ;;
|
||||||
|
--allatonce) allatonce=1; shift ;;
|
||||||
|
--) shift ; break ;;
|
||||||
|
*) echo "Internal error!" ; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
. .settings
|
||||||
|
|
||||||
|
modules=("$@")
|
||||||
origin="$(git config --get remote.origin.url)"
|
origin="$(git config --get remote.origin.url)"
|
||||||
now="$(date "+%s %z")"
|
now="$(date "+%s %z")"
|
||||||
# FIXME: hardcoded to avoid changing commits for now
|
# FIXME: hardcoded to avoid changing commits for now
|
||||||
@ -20,6 +39,7 @@ export GIT_AUTHOR_DATE="$now"
|
|||||||
export GIT_COMMITTER_NAME="Auto"
|
export GIT_COMMITTER_NAME="Auto"
|
||||||
export GIT_COMMITTER_EMAIL="auto@suse.de"
|
export GIT_COMMITTER_EMAIL="auto@suse.de"
|
||||||
export GIT_COMMITTER_DATE="$now"
|
export GIT_COMMITTER_DATE="$now"
|
||||||
|
commit_base="origin/main"
|
||||||
|
|
||||||
tmpfile=$(mktemp updatemodules.XXXXXX)
|
tmpfile=$(mktemp updatemodules.XXXXXX)
|
||||||
cleanup()
|
cleanup()
|
||||||
@ -28,14 +48,12 @@ cleanup()
|
|||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
read -r token < token || exit 1
|
|
||||||
|
|
||||||
# read all submodules
|
# read all submodules
|
||||||
declare -A revs
|
declare -A revs
|
||||||
while read -r m t cid p; do
|
while read -r m t cid p; do
|
||||||
[ "$t" = "commit" ] || continue
|
[ "$t" = "commit" ] || continue
|
||||||
revs["$p"]="$cid"
|
revs["$p"]="$cid"
|
||||||
done < <(git cat-file -p "HEAD^{tree}")
|
done < <(git cat-file -p "$commit_base^{tree}")
|
||||||
|
|
||||||
if [ -z "$modules" ]; then
|
if [ -z "$modules" ]; then
|
||||||
modules=("${!revs[@]}")
|
modules=("${!revs[@]}")
|
||||||
@ -43,11 +61,12 @@ fi
|
|||||||
|
|
||||||
# check remotes for updates
|
# check remotes for updates
|
||||||
declare -A commits
|
declare -A commits
|
||||||
treetext=$(git cat-file -p "HEAD^{tree}")
|
treetext=$(git cat-file -p "$commit_base^{tree}")
|
||||||
|
gitmodules=$(git cat-file -p "$commit_base":.gitmodules)
|
||||||
for m in "${modules[@]}"; do
|
for m in "${modules[@]}"; do
|
||||||
path="$(git config -f .gitmodules --get "submodule.$m.path")"
|
path="$(echo "$gitmodules" | git config -f /dev/stdin --get "submodule.$m.path")"
|
||||||
url="$(git config -f .gitmodules --get "submodule.$m.url")"
|
url="$(echo "$gitmodules" | git config -f /dev/stdin --get "submodule.$m.url")"
|
||||||
branch="$(git config -f .gitmodules --get "submodule.$m.branch")"
|
branch="$(echo "$gitmodules" | git config -f /dev/stdin --get "submodule.$m.branch")"
|
||||||
if [ -z "$path" ] || [ -z "$url" ]; then
|
if [ -z "$path" ] || [ -z "$url" ]; then
|
||||||
echo "$m unknown" >&2
|
echo "$m unknown" >&2
|
||||||
continue
|
continue
|
||||||
@ -66,8 +85,8 @@ for m in "${modules[@]}"; do
|
|||||||
if [ "$allatonce" = 1 ]; then
|
if [ "$allatonce" = 1 ]; then
|
||||||
treetext="${treetext/${revs[$path]} $path/$cid $path}"
|
treetext="${treetext/${revs[$path]} $path/$cid $path}"
|
||||||
else
|
else
|
||||||
newtree="$(git cat-file -p "HEAD^{tree}" | sed -e "s/${revs[$path]}\t$path/$cid\t$path/" | git mktree)"
|
newtree="$(git cat-file -p "$commit_base^{tree}" | sed -e "s/${revs[$path]}\t$path/$cid\t$path/" | git mktree)"
|
||||||
newcid="$(git commit-tree -p HEAD -m "Update $m" "$newtree")"
|
newcid="$(git commit-tree -p "$commit_base" -m "Update $m" "$newtree")"
|
||||||
commits["$m"]="$newcid"
|
commits["$m"]="$newcid"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -75,26 +94,15 @@ done
|
|||||||
|
|
||||||
if [ "$allatonce" = 1 ]; then
|
if [ "$allatonce" = 1 ]; then
|
||||||
newtree="$(echo "$treetext" | git mktree)"
|
newtree="$(echo "$treetext" | git mktree)"
|
||||||
newcid="$(git commit-tree -p HEAD -m "Update all" "$newtree")"
|
newcid="$(git commit-tree -p "$commit_base" -m "Update all" "$newtree")"
|
||||||
commits["all"]="$newcid"
|
commits["all"]="$newcid"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for m in "${!commits[@]}"; do
|
for m in "${!commits[@]}"; do
|
||||||
if git send-pack --force "$pushurl" "${commits[$m]}:refs/heads/update_$m"; then
|
mkdir -p ".scripts/push"
|
||||||
#https://github.com/go-gitea/gitea/issues/18842
|
if [ -e ".scripts/push/$m" ]; then
|
||||||
if curl -s -f "$prtarget" \
|
read -r cid < ".scripts/push/$m"
|
||||||
-H "accept: application/json" \
|
[ "$cid" = "${commits[$m]}" ] || echo "Warning: previous commit $cid for $m" >&2
|
||||||
-H "Authorization: token $token" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{ \"base\": \"main\", \"head\": \"$prsrcusr:update_$m\", \"title\": \"Update $m\"}" > "$tmpfile"; then
|
|
||||||
prid=$(jq .id < "$tmpfile")
|
|
||||||
echo "filed pr #$prid for $m"
|
|
||||||
else
|
|
||||||
echo "failed to file pr for $m"
|
|
||||||
jq .message < "$tmpfile"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "failed to push $m update" >&2
|
|
||||||
jq .message < "$tmpfile"
|
|
||||||
fi
|
fi
|
||||||
|
echo "${commits[$m]}" > ".scripts/push/$m"
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user