git - 验证来自输入的提交哈希 (workflow_dispatch)
问题描述
我想验证来自输入(workflow_dispatch)的提交哈希:
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v2
- name: Run only if input exist (Validate input hash)
if: ${{ github.event.inputs.sha != '' }}
run: git cat-file -e ${{ github.event.inputs.sha }}^{commit}
问题是它只适用于最新的提交。
如果我使用任何其他提交,它会说:
fatal: Not a valid object name COMMIT_HASH^{commit}
Error: Process completed with exit code 128.
但它在本地工作。我也尝试过这种方式:
git cat-file -e ${{ github.event.inputs.sha }}
git cat-file commit ${{ github.event.inputs.sha }}
解决方案
我试图运行git rev-list HEAD
以检查提交历史,结果它只显示了最新的提交。
这是因为对于触发工作流的 ref/SHA, checkout 操作默认只检索一个提交。我们可以设置fetch-depth: 0
为获取所有分支和标签的所有历史记录:
- name: Checkout Project
uses: actions/checkout@v2
with:
fetch-depth: 0
这样,我的问题上的代码就可以工作了。
推荐阅读
- ios - Swift 构建错误:闭包捕获列表中的预期名称
- android - Xamarin.Android 如何在调用 OnActivityResult 之前拦截活动关闭/现有事件
- c# - 如何使用 UICollectionViewCompositionalLayout 和多种单元格类型创建自动调整大小的单元格?
- python-3.x - 如何在 jupyter 笔记本中显示压缩内容?
- python - 我想增加关于python类的增量
- r - R中带有附加值的热图
- vue.js - 如何删除 /.quasar/client-entry.js 中的新 Vue?
- java - H2O MOJO 运行时:找不到 MOJO 实现后端
- python-3.x - 图像未显示在 tkinter 窗口的画布中
- amazon-athena - AWS Athena 使用源字符串创建表