diff --git a/action.yml b/action.yml index bdac475d..3e35809f 100644 --- a/action.yml +++ b/action.yml @@ -77,6 +77,10 @@ inputs: description: "Output changed files in JSON format which can be used for matrix jobs" required: false default: "false" + target_branch_fetch_depth: + description: "Fetch depth for target branch. NOTE: This can be adjusted to resolve errors with insufficient history. See: #668." + required: false + default: "20" outputs: added_files: @@ -184,14 +188,15 @@ runs: GITHUB_BASE_REF: ${{ github.base_ref }} GITHUB_HEAD_REF: ${{ github.head_ref }} GITHUB_WORKSPACE: ${{ github.workspace }} - GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }} + GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }} GITHUB_EVENT_BEFORE: ${{ github.event.before }} - GITHUB_EVENT_FORCED : ${{ github.event.forced }} + GITHUB_EVENT_FORCED: ${{ github.event.forced }} # INPUT_ is not available in Composite run steps # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs INPUT_SHA: ${{ steps.sha.outputs.sha }} INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }} INPUT_PATH: ${{ inputs.path }} + INPUT_TARGET_BRANCH_FETCH_DEPTH: ${{ inputs.target_branch_fetch_depth }} - name: Glob match uses: tj-actions/glob@v14 id: glob diff --git a/diff-sha.sh b/diff-sha.sh index 551b5d13..6c610cd8 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -62,7 +62,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$? if [[ -z $INPUT_BASE_SHA ]]; then - git fetch --no-tags -u --progress origin --depth=2 "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$? + git fetch --no-tags -u --progress origin --depth="$INPUT_TARGET_BRANCH_FETCH_DEPTH" "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$? PREVIOUS_SHA="" if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then @@ -105,12 +105,13 @@ else echo "::debug::GITHUB_BASE_REF: $TARGET_BRANCH..." + git fetch --no-tags -u --progress origin --depth="$INPUT_TARGET_BRANCH_FETCH_DEPTH" "${TARGET_BRANCH}":"${TARGET_BRANCH}" && + exit_status=$? || exit_status=$? + if [[ -z $INPUT_BASE_SHA ]]; then - git fetch --no-tags -u --progress origin --depth=1 "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$? - PREVIOUS_SHA=$GITHUB_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? echo "::debug::Previous SHA: $PREVIOUS_SHA" else - git fetch --no-tags -u --progress origin --depth=1 "$(git rev-parse --verify "$INPUT_BASE_SHA")" && exit_status=$? || exit_status=$? PREVIOUS_SHA=$INPUT_BASE_SHA TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$? echo "::debug::Previous SHA: $PREVIOUS_SHA"