Git history in a Github Action

ε祈祈猫儿з 提交于 2020-06-17 09:33:10

问题


I would like to log the git history in a Github Action. But it seems that the Action's environment has a different one:

echo $(git log -5 --oneline)

shell: /bin/bash -e {0}

7c0faa6 Merge c245982a87ef5538d42ab905706faa08f4d67ce9 into 8a939ef1f71eaecac0ae52d625dad3e3c9fa4c16

This is not a git log and none of these hashes matches what I have in my repo.

Why is that?

How to access the commit history from the environment of a Github Action?


回答1:


You are experiencing this because your workflow is running on pull_request events. During those events, GITHUB_REF is a merge commit from the head branch to the base. The intention of this is to run CI against the merge commit to check it passes before it's actually merged.

If you don't want the merge commit and want to checkout the head commit instead, you have to pass the HEAD's sha as ref to the checkout. You can change the checkout as follows (taken from this example).

Also, that checkout is shallow by default, meaning it only has the last commit. To read more than the last commit, pass a non zero number to fetch-depth, or zero as well, which will fetch the entire history (default is 1):

- uses: actions/checkout@v2
  with:
    ref: ${{ github.event.pull_request.head.sha }}
    fetch-depth: 0

See the documentation here for the pull_request event.



来源:https://stackoverflow.com/questions/62334460/git-history-in-a-github-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!