【问题标题】:Validate commit hash from the input (workflow_dispatch)验证来自输入的提交哈希 (workflow_dispatch)
【发布时间】:2021-07-16 20:05:47
【问题描述】:

我想验证来自输入 (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 github-actions git-commit


    【解决方案1】:

    我尝试运行git rev-list HEAD 来检查提交历史,结果发现它只显示了最新的提交。

    这是因为checkout action 默认情况下仅检索单个提交,用于触发工作流的 ref/SHA。我们可以设置fetch-depth: 0 来获取所有分支和标签的所有历史记录:

      - name: Checkout Project
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
    

    这样,我问题上的代码就可以工作了。

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多