Skip to content

Commit

Permalink
build-test-recipe.yml: fix getting changed recipes from a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-roos committed Dec 17, 2024
1 parent 6ace1dd commit f250eb5
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/build-test-recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,34 @@ jobs:
- name: Diff files and set variables
id: diff
run: |
# See https://github.community/t/check-pushed-file-changes-with-git-diff-tree-in-github-actions/17220/10
if [ $GITHUB_BASE_REF ]; then
# Pull Request
# 'github.event.before/after' and 'github.event.pull_request.base.sha' are inconsistent for PRs
# Find the commit where the PR branch was forked from the base branch
git fetch origin ${{ github.base_ref }} ${{ github.event.pull_request.head.ref }}
FORK_POINT=$( git show-branch --merge-base "origin/${{ github.base_ref }}" "origin/${{ github.event.pull_request.head.ref }}" )
# 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
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }}
fi
# 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 }}
export DIFF=$( git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR )
# 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
Expand Down

0 comments on commit f250eb5

Please sign in to comment.