From 63ee81daaf7ff729eeca03d7f593733755242a20 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 6 Sep 2024 12:16:16 +0200 Subject: [PATCH] Do not rebase on top of origin/main The previous version would report shifted line numbers. --- action.yml | 9 +++++++-- container/cmd | 15 +++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index 781a379..98b0525 100644 --- a/action.yml +++ b/action.yml @@ -41,15 +41,20 @@ inputs: required: false pull_request_number_id: - description: "The pull requires ID (internal)" + description: "The pull request ID (internal)" default: ${{ github.event.pull_request.number }} required: false pull_request_head: - description: "The pull requirest SHA1 without merge commit (internal)" + description: "The pull request SHA1 without the merge commit (internal)" default: ${{ github.event.pull_request.head.sha }} required: false + pull_request_base: + description: "The commit right before the pull-request commits (intenral)" + default: ${{ github.event.pull_request.base.sha }} + required: true + outputs: sarif: description: 'The SARIF file containing defects' diff --git a/container/cmd b/container/cmd index b4b4d39..df7f29e 100755 --- a/container/cmd +++ b/container/cmd @@ -7,8 +7,6 @@ result=true error() { echo "DIFF_LINT_ERROR: $*" >&2 ; } -target_branch=${GITHUB_BASE_REF-main} - is_true() { [[ $# -le 0 ]] && return 1 @@ -39,9 +37,7 @@ set_linter_options() for tag in $INPUT_LINTER_TAGS; do linter_options+=( --linter-tag "$tag" ) done - if test "$target_branch" != main; then - linter_options+=( --compare-against "origin/$target_branch" ) - fi + linter_options+=( --compare-against "$INPUT_PULL_REQUEST_BASE" ) } populate_sarif_data() @@ -77,18 +73,17 @@ if test "$GITHUB_EVENT_NAME" = 'pull_request'; then git config --global --add safe.directory '*' git config --global advice.detachedHead false git config --global init.defaultBranch main - git config --global user.email "vcs-diff-lint@example.com" - git config --global user.name "VCS Diff Lint automation" ( - echo "## Rebasing $INPUT_PULL_REQUEST_HEAD onto $target_branch ##" + echo "## Checking out $INPUT_PULL_REQUEST_HEAD ##" $debug_mode || 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" ) + # We don't want to rebase on top of the current upstream's head; the line + # numbers would be shifted and the provided output would be misleading. + test -z "$INPUT_SUBDIRECTORY" || INPUT_SUBDIRECTORIES=$INPUT_SUBDIRECTORY test -z "$INPUT_SUBDIRECTORIES" && INPUT_SUBDIRECTORIES=.