1
0
Fork 0
mirror of https://code.forgejo.org/actions/cascading-pr synced 2025-03-14 22:36:58 +01:00

always push what has been changed at destination

This commit is contained in:
Earl Warren 2023-12-23 21:09:43 +01:00
parent 18b334170a
commit 109016e50d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -33,11 +33,15 @@ function default_branch() {
jq --raw-output .default_branch < $TMPDIR/$direction.json
}
function updated_at() {
local direction=$1
function destination_updated_at() {
local api
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json
jq --raw-output .updated_at < $TMPDIR/$direction.json
if ${options[destination_is_fork]} ; then
repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} > $TMPDIR/updated_at.json
else
repo_curl ${options[destination_repo]} api_json ${options[destination_api]} > $TMPDIR/updated_at.json
fi
jq --raw-output .updated_at < $TMPDIR/updated_at.json
}
function exists_branch() {
@ -218,17 +222,25 @@ function sha_pushed() {
fi
}
function destination_updated_at_changed() {
local before="$1"
local after="$(destination_updated_at)"
test "$before" != "$after"
}
function push() {
local direction=$1 remote=$2 branch=$3
local remote=$1 branch=$2
(
cd $TMPDIR/$direction
cd $TMPDIR/destination
git add .
if git commit -m 'cascading-pr update'; then
local updated_at=$(updated_at $direction)
local before=$(destination_updated_at)
sleep 1 # the resolution of the update time is one second
git push --force ${remote} prbranch:$branch
git rev-parse HEAD > ../$direction.sha
retry test "$updated_at" != "$(updated_at $direction)"
git rev-parse HEAD > ../destination.sha
retry destination_updated_at_changed "$before"
local after=$(destination_updated_at)
log_info "pushed"
else
log_info "nothing to push"
@ -310,7 +322,7 @@ function update() {
if ${options[destination_is_fork]} ; then
remote_head=fork
fi
push destination $remote_head ${options[destination_head]}
push $remote_head ${options[destination_head]}
}
function set_git_url() {