如何解决从输入验证提交哈希 (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
以检查提交历史记录,结果它只显示最新提交。
这是因为 checkout action 在默认情况下仅检索单个提交,用于触发工作流的 ref/SHA。我们可以设置 fetch-depth: 0
来获取所有分支和标签的所有历史记录:
- name: Checkout Project
uses: actions/checkout@v2
with:
fetch-depth: 0
这样,我的问题中的代码就会起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。