Atr*_*sis 3 git continuous-integration github-actions
我想在 Github Action 中记录 git 历史记录。但 Action 的环境似乎有所不同:
echo $(git log -5 --oneline)
Run Code Online (Sandbox Code Playgroud)
外壳:/bin/bash -e {0}
7c0faa6 将 c245982a87ef5538d42ab905706faa08f4d67ce9 合并到 8a939ef1f71eaecac0ae52d625dad3e3c9fa4c16
这不是 git 日志,并且这些哈希值都不与我的存储库中的内容匹配。
这是为什么?
如何从 Github Action 的环境访问提交历史记录?
pet*_*ans 16
您遇到这种情况是因为您的工作流程正在pull_request事件上运行。在这些事件期间,GITHUB_REF是从头分支到基础分支的合并提交。这样做的目的是针对合并提交运行 CI,以在实际合并之前检查其是否通过。
如果您不想合并提交并想签出头提交,则必须将 HEAD 的 sha 传递给ref签出。您可以按如下方式更改结账(取自本示例)。
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
Run Code Online (Sandbox Code Playgroud)
See the documentation here for the pull_request event.