-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
A lot of common tasks in a workflow triggered by a push
event involves comparing the states of the branch before and after the push event. For this, one needs to fetch the git history of all commits contained in the push event, plus the last commit before the push.
However, this action only provides the fetch-depth
parameter, which inputs the number of commits to fetch, but this information is not easily accessible. As far as I understand, the current solution is to fetch the entire history every time, using fetch-depth=0
, but that seems like a waste of bandwidth and run time.
The push event payload does contain the list of commits as an array, but there is no native function in GitHub Actions to count the length of an array, otherwise one could do something like:
on: push
steps:
- uses: actions/checkout@v3
with:
- fetch-depth: ${{ len(github.event.commits) + 1 }}
Alternatively, one could write an extra step before using checkout to count the number of commits in the payload, e.g. using Python or bash scripts, but that seems a bit too hacky for such a common task.
Wouldn't it be possible to provide the option to fetch the git history up to a certain commit hash?
In that case, in a push event one could do something like this:
on: push
steps:
- uses: actions/checkout@v3
with:
- fetch-depth-ref: ${{ github.event.before }}