diff --git a/.github/actions/commit-range/action.yml b/.github/actions/commit-range/action.yml index 5dfdf876b..6105bbb0e 100644 --- a/.github/actions/commit-range/action.yml +++ b/.github/actions/commit-range/action.yml @@ -50,16 +50,26 @@ runs: --head ${{ github.ref_name }} \ --json number,baseRefName \ --limit 1) - if [[ -n "$pr_info" ]]; then + if [[ \ + -n "$pr_info" && \ + "$(echo "$pr_info" | jq '.[0].baseRefName')" != "null" \ + ]]; then base_branch=$(echo "$pr_info" | jq -r '.[0].baseRefName') - echo "Associated PR found." + echo "Associated PR found. Base branch: ${base_branch}" else - echo "No associated PR found. Using default branch as base." + echo "No associated PR found or base branch is null." + echo "Using default branch as base." base_branch=$(gh api repos/${{ github.repository }} --jq '.default_branch') + echo "Default branch: ${base_branch}" fi - echo "Base branch: ${base_branch}" - branch_point=$(git merge-base origin/${base_branch} ${{ github.sha }}) + echo "Fetching the branch point..." + if ! branch_point=$(git merge-base origin/${base_branch} ${{ github.sha }}) + then + echo "Failed to find merge-base." + echo "Using the first commit of the current branch." + branch_point=$(git rev-list --max-parents=0 HEAD) + fi echo "Branch point: ${branch_point}" range="${branch_point}...${{ github.sha }}"