mirror of
https://github.com/tj-actions/changed-files
synced 2025-03-12 05:00:52 +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:
parent
0604c7fd87
commit
6d2a5c29e8
2 changed files with 12 additions and 6 deletions
|
@ -77,6 +77,10 @@ inputs:
|
||||||
description: "Output changed files in JSON format which can be used for matrix jobs"
|
description: "Output changed files in JSON format which can be used for matrix jobs"
|
||||||
required: false
|
required: false
|
||||||
default: "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:
|
outputs:
|
||||||
added_files:
|
added_files:
|
||||||
|
@ -184,14 +188,15 @@ runs:
|
||||||
GITHUB_BASE_REF: ${{ github.base_ref }}
|
GITHUB_BASE_REF: ${{ github.base_ref }}
|
||||||
GITHUB_HEAD_REF: ${{ github.head_ref }}
|
GITHUB_HEAD_REF: ${{ github.head_ref }}
|
||||||
GITHUB_WORKSPACE: ${{ github.workspace }}
|
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_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
|
# 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
|
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
|
||||||
INPUT_SHA: ${{ steps.sha.outputs.sha }}
|
INPUT_SHA: ${{ steps.sha.outputs.sha }}
|
||||||
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }}
|
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }}
|
||||||
INPUT_PATH: ${{ inputs.path }}
|
INPUT_PATH: ${{ inputs.path }}
|
||||||
|
INPUT_TARGET_BRANCH_FETCH_DEPTH: ${{ inputs.target_branch_fetch_depth }}
|
||||||
- name: Glob match
|
- name: Glob match
|
||||||
uses: tj-actions/glob@v14
|
uses: tj-actions/glob@v14
|
||||||
id: glob
|
id: glob
|
||||||
|
|
|
@ -62,7 +62,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then
|
||||||
CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$?
|
CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$?
|
||||||
|
|
||||||
if [[ -z $INPUT_BASE_SHA ]]; then
|
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=""
|
PREVIOUS_SHA=""
|
||||||
|
|
||||||
if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
|
if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
|
||||||
|
@ -105,12 +105,13 @@ else
|
||||||
|
|
||||||
echo "::debug::GITHUB_BASE_REF: $TARGET_BRANCH..."
|
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
|
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_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$?
|
||||||
PREVIOUS_SHA=$GITHUB_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$?
|
|
||||||
echo "::debug::Previous SHA: $PREVIOUS_SHA"
|
echo "::debug::Previous SHA: $PREVIOUS_SHA"
|
||||||
else
|
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
|
PREVIOUS_SHA=$INPUT_BASE_SHA
|
||||||
TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$?
|
TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$?
|
||||||
echo "::debug::Previous SHA: $PREVIOUS_SHA"
|
echo "::debug::Previous SHA: $PREVIOUS_SHA"
|
||||||
|
|
Loading…
Add table
Reference in a new issue