From 53e3e599526d7cdc7ec1394563ce0f895fd91d0f Mon Sep 17 00:00:00 2001 From: Thomas Roos Date: Tue, 17 Dec 2024 09:35:42 +0000 Subject: [PATCH] build-test-recipe.yml: fix getting changed recipes from a fork --- .github/workflows/build-test-recipe.yml | 45 +++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-test-recipe.yml b/.github/workflows/build-test-recipe.yml index 95e2d223e..7bdc78876 100644 --- a/.github/workflows/build-test-recipe.yml +++ b/.github/workflows/build-test-recipe.yml @@ -15,25 +15,36 @@ jobs: - name: Diff files and set variables id: diff run: | - if [ $GITHUB_BASE_REF ]; then - # Pull Request - # Fetch both the base and head of the pull request - git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} ${{ github.head_ref }}:${{ github.head_ref }} - # Determine the merge base - FORK_POINT=$(git merge-base ${{ github.base_ref }} ${{ github.head_ref }}) - LATEST_COMMIT_IN_PR=${{ github.event.pull_request.head.sha }} - # Get the diff - DIFF=$(git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR) - echo "Diff between $FORK_POINT and $LATEST_COMMIT_IN_PR" + if [ $GITHUB_BASE_REF ]; then + # Pull Request + # Fetch the base ref + git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} + + # For forks, we need to fetch from the head repository + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then + git remote add fork ${{ github.event.pull_request.head.repo.clone_url }} + git fetch fork ${{ github.head_ref }} else - # Push to a branch - BEFORE_SHA=${{ github.event.before }} - AFTER_SHA=${{ github.event.after }} - DIFF=$(git diff --name-only $BEFORE_SHA $AFTER_SHA) - echo "Diff between $BEFORE_SHA and $AFTER_SHA" + git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} fi - echo "$DIFF" - echo "diff=$( echo "$DIFF" | tr '\n' ' ' )" >> $GITHUB_OUTPUT + + # Determine the merge base + FORK_POINT=$(git merge-base ${{ github.base_ref }} ${{ github.event.pull_request.head.sha }}) + LATEST_COMMIT_IN_PR=${{ github.event.pull_request.head.sha }} + + # Get the diff + DIFF=$(git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR) + echo "Diff between $FORK_POINT and $LATEST_COMMIT_IN_PR" + else + # Push to a branch + BEFORE_SHA=${{ github.event.before }} + AFTER_SHA=${{ github.event.after }} + DIFF=$(git diff --name-only $BEFORE_SHA $AFTER_SHA) + echo "Diff between $BEFORE_SHA and $AFTER_SHA" + fi + + echo "$DIFF" + echo "diff=$( echo "$DIFF" | tr '\n' ' ' )" >> $GITHUB_OUTPUT - name: Get Yocto release name id: get-yocto-release-name run: |