Check pushed file changes with git diff-tree in GitHub Actions #25950
-
My goal is to fetch a list of files that were modified between 2 commits (or in 1 commit) using the The problem is that the My actions workflow configuration is basic:
Is GitHub preventing me from using the Here is a snippet of the bash script I want to execute.
Here is an example of what I see in the workflow console. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
Please remove/reset the ‘fetch-depth’ for ‘actions/checkout’, output works fine then for the command ‘git diff-tree’. You can get/pipe the changed files via command below:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick response and making the extra effort of looking inside one of my repositories. A fetch-depth of |
Beta Was this translation helpful? Give feedback.
-
Hi @weide-zhou, thanks for your response. This however does not work for workflow where 3 coommits were added, you will only get the latest information. Is there a way to get the global changes of the commits you uploaded to the branch? |
Beta Was this translation helpful? Give feedback.
-
Solved with:
|
Beta Was this translation helpful? Give feedback.
-
I am trying to compare against the target branch instead of previous commit. Is there something that would work like this?
I want to always check the diff in absolute terms against the target branch, not just between commits. Thanks. |
Beta Was this translation helpful? Give feedback.
-
This almost works for me. I’m trying to find occurences of a string. Maybe you can help.
This works fine locally but in the builds I get an error (with dots):
And without dots:
|
Beta Was this translation helpful? Give feedback.
-
Can you send link to repo/yaml? |
Beta Was this translation helpful? Give feedback.
-
In case you’re still looking for answer @shotor or if someone has the same issue, this “bad object” error is happening because of the default config for actions/checkout@v2:
This means that you need do something like this:
|
Beta Was this translation helpful? Give feedback.
-
Previous answer (by @pozil) fetches full repository and it may be slow on big repositories. My solution is to fetch with depth 1 by using
CPython uses similar way to run tests only if changed files are not in Docs directory (for Pull Requests). For pushes to master they always run tests. Update:
|
Beta Was this translation helpful? Give feedback.
-
Due to some issue I had on PR's I want to share my solution for the PR part (PUSH is CP from a solution above). 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 }}" )
LATEST_COMMIT_IN_PR=${{ github.event.pull_request.head.sha }}
CHANGED_FILES=$( git diff --name-only $FORK_POINT $LATEST_COMMIT_IN_PR )
echo "Changes for PR"
echo "Diff between $FORK_POINT and $LATEST_COMMIT_IN_PR"
else
# Push
# 'github.event.before' and 'after' are including all commits of the current push event
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
echo "Changes for PUSH"
echo "Diff between ${{ github.event.before }} and ${{ github.event.after }}"
fi
# Print result for verification
echo Changed files:
echo "$CHANGED_FILES" |
Beta Was this translation helpful? Give feedback.
Please remove/reset the ‘fetch-depth’ for ‘actions/checkout’, output works fine then for the command ‘git diff-tree’.
You can get/pipe the changed files via command below: