3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-03-10 23:18:49 +00:00

fix: bug with new commits pushed to the base branch that result in errors when shallow history is used

This commit is contained in:
Tonye Jack 2022-10-12 12:39:24 -06:00
parent 0604c7fd87
commit 6d2a5c29e8
2 changed files with 12 additions and 6 deletions

View file

@ -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_<VARIABLE_NAME> 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

View file

@ -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"