Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support providing commit hash for fetch-depth #1444

Open
AAriam opened this issue Sep 1, 2023 · 1 comment
Open

Support providing commit hash for fetch-depth #1444

AAriam opened this issue Sep 1, 2023 · 1 comment

Comments

@AAriam
Copy link

AAriam commented Sep 1, 2023

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 }}
@AAriam AAriam changed the title Support providing fetch-depth as commit hash Support providing commit hash for fetch-depth Sep 1, 2023
@odrotbohm
Copy link

I guess another common reference would be the commit of the last successful build. Third-party solutions exist to obtain that hash so that subsequent steps can make use of it, but the checkout step would still have to fetch all commit in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants