From 4e92a46fb71cab92a23b0189dde4b9499fba071a Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 6 Sep 2024 11:05:42 +0200 Subject: [PATCH] Rebase the checkout on top of target branch This change will fail the action in case of rebase conflicts, but it seems acceptable (the PR can not be merged anyway). If needed, we may end-up some implementing some fallback in the future. --- action.yml | 3 +++ container/cmd | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 4f383e2..8fe7442 100644 --- a/action.yml +++ b/action.yml @@ -47,3 +47,6 @@ outputs: runs: using: docker image: docker://quay.io/copr/vcs-diff-lint:latest + env: + INPUT_PULL_REQUEST_ID: ${{ github.event.pull_request.number }} + INPUT_PULL_REQUEST_HEAD: ${{ github.event.pull_request.head.sha }} diff --git a/container/cmd b/container/cmd index 7173ad7..936d717 100755 --- a/container/cmd +++ b/container/cmd @@ -24,7 +24,7 @@ is_true() { } if is_true "$INPUT_DEBUG" || is_true "$RUNNER_DEBUG"; then - ( echo "== GitHub ENV VARS ==" ; env | grep ^GITHUB ) >&2 + ( echo "== GitHub ENV VARS ==" ; env | grep -e ^GITHUB -e ^INPUT_ ) >&2 set -x fi @@ -76,7 +76,14 @@ if test "$GITHUB_EVENT_NAME" = 'pull_request'; then git config --global advice.detachedHead false git config --global init.defaultBranch main - git fetch origin "$target_branch:$target_branch" &>/dev/null + ( + echo "## Rebasing $INPUT_PULL_REQUEST_HEAD onto $target_branch ##" + is_true "$INPUT_DEBUG" || exec &>/dev/null + git fetch origin "$target_branch:$target_branch" + git fetch origin "+$INPUT_PULL_REQUEST_HEAD:refs/remotes/pull-requests/pr-detached-$INPUT_PULL_REQUEST_ID" + git checkout "$INPUT_PULL_REQUEST_HEAD" + git rebase "origin/$target_branch" + ) test -z "$INPUT_SUBDIRECTORY" || INPUT_SUBDIRECTORIES=$INPUT_SUBDIRECTORY test -z "$INPUT_SUBDIRECTORIES" && INPUT_SUBDIRECTORIES=.