Git 操作/签出“不明确的参数 'HEAD^'”

问题描述 投票:0回答:1

这是我第一次使用 git actions。我想使用 pandoc 创建相同文本的不同文件类型。由于我为此使用免费运行时(并且可能会有更多操作),因此我希望尽可能减少运行时。这是我的 git 操作:

name: conditional_convert_via_pandoc
on:
  push:
    branches:
      - 'main' # Do the work exclusively for the deploying branch

jobs:
  condition_check_files:
    runs-on: 'ubuntu-22.04'
    # Declare outputs for next jobs
    outputs:
      bool_files_changed: ${{ steps.check_file_changed.outputs.bool_files_changed }}
      list_changed_files: ${{ steps.check_file_changed.outputs.list_changed_files }}
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 1
    - shell: pwsh
      id: check_file_changed
      run: |
        # Look only for changed files (A - added, M - modified) and return their names (the specific changes are irrelevant)
        $diff = git diff --name-only --diff-filter=AM HEAD^ HEAD

        # Filter the files under content/ with the .md extension excluding the Hugo associated _index.md files
        $SourceDiff = $diff | Where-Object { $_ -match '^content/' -and $_ -match '.md$' -and -not ($_ -match '_index.md') }
        $HasDiff = $SourceDiff.Length -gt 0

        # Set the output named "bool_files_changed"
        echo "{bool_files_changed}={$HasDiff}" >> $GITHUB_OUTPUT
        echo "{list_changed_files}={$SourceDiff}" >> $GITHUB_OUTPUT

  # Run the job only with 'bool_files_changed' equals 'True'
  conditional_pandoc:
    runs-on: 'ubuntu-22.04'
    needs: [ condition_check_files ]
    if: needs.condition_check_files.outputs.bool_files_changed == 'True'
    steps:
    - uses: docker://pandoc/latex:3.5
    - shell: pwsh
      run: |
        # List types which will only use --standalone. You can easily add more extensions if you're fine with this setting
        $ONLY_STANDALONE_OUTPUT_TYPES = "latex pdf html docx odt"
        # Use as many cores as available to be as fast as possible
        parallel --jobs 0 \
          # Pandoc creates an AST (Abstract Syntax Tree); reuse this by saving to/reading from .ast
          pandoc --from markdown {} --to native -o {.}.ast ';'\
          for i in $ONLY_STANDALONE_OUTPUT_TYPES';' do \
            pandoc --from native {.}.ast --standalone -o '{.}.$i' ';' \
          done';' \
          # You can easily add individual conversion rules by using pandoc after the 'done' part. Keep in mind to finish all non-comment lines with backslash
          rm {.}.ast ::: needs.condition_changed_files.outputs.list_changed_files

但是这在

$diff = git diff --name-only --diff-filter=AM HEAD^ HEAD
上失败了(代码基于 Gérald Barré 的 example)和
ambiguous argument 'HEAD^'
。我不明白为什么这是一个问题,因为该操作只能在一个相当有效的回购协议中进行推送时起作用,所以应该有足够的历史记录

我尝试将 HEAD^ 放在双引号中(根据 this 帖子),但它仍然失败。

由于我无法克服这个错误,所以我不知道其余部分是否有效,因此欢迎任何评论

git github-actions pandoc git-checkout
1个回答
0
投票

感谢@mb21,检测到了问题:只需使用

fetch-depth: 2

© www.soinside.com 2019 - 2024. All rights reserved.