GitHub Actions - 检出操作中的问题

3

我还不熟悉 Github Action Runners。 我从主分支创建了一个名为 test-master 的测试主分支,以及另一个名为 test-feature 的功能分支,也是从主分支中提取而来的。 我的 test-master 分支有一个与 Terraform 相关的工作流程。 但是,在 git checkout 行动中出现错误,请查看以下代码和错误:

name: 'Terraform'
on: [pull_request]

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest

    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    defaults:
      run:
        shell: bash

    steps:
    # Checkout the repository to the GitHub Actions runner
    - name: Checkout
      uses: actions/checkout@test-master

    # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
    - name: Setup Terraform
      uses: hashicorp/setup-terraform@v1
      with:
        cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

    # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
    - name: Terraform Init
      run: terraform init

    # Checks that all Terraform configuration files adhere to a canonical format
    - name: Terraform Format
      id: fmt
      run: terraform fmt --recursive

每当我尝试从test-feature分支合并到test-master分支时,它会运行工作流并生成错误。 错误信息:无法解析操作actions/checkout@test-master,找不到版本test-master
请指导我为什么它不能识别test-master分支。
1个回答

5

当您想要“使用”一个操作时,您需要指定要运行的操作名称和“操作版本”。这一行代码:

    - uses: actions/checkout@test-master

这段代码表示您想使用版本为test-masteractions/checkout操作,但是实际上并没有这个版本。

您需要使用actions/checkout@v2。如果您想要检出自己名为test-master的分支,可以将其作为该操作的选项指定。例如:

    - name: Checkout
      uses: actions/checkout@v2
      with:
        ref: 'test-master'

你知道 actions/checkout@v2 和 actions/checkout@master 有什么区别吗? - knowledge20
actions/checkout@master 将运行主分支中的代码,而不是 v2 分支中的代码。v2 分支跟踪最新版本 - 您应该使用它。 - Edward Thomson
2
v2actions/checkout 动作的最新版本。它是由 GitHub Actions 团队明确创建的,与 ref 标签中存在的分支无关。 - Edward Thomson
1
这与您的 GitHub 存储库的主分支无关,是正确的。它指的是 https://github.com/actions/checkout 的主分支。 - Edward Thomson
你不能随意地在不同的分支上运行工作流程。根据配置,操作将在一个分支中运行工作流程。请参阅 https://docs.github.com/en/actions/reference/events-that-trigger-workflows#configuring-workflow-events。 - Edward Thomson
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接