3

I am new to github action runners. I have created a test-master branch from the master and another feature branch also taken out of master test-feature. My test-master branch has a workflow related to terraform. However, I am getting error in the git checkout action PFB the code and error.

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

Whenever I am trying to raise a pull request from the test-feature to test-master It runs the workflow and generates the error. Error: Unable to resolve action actions/checkout@test-master, unable to find version test-master

Kindly guide me why is it not recognizing the test-maser branch.

knowledge20
  • 1,006
  • 3
  • 14
  • 25

1 Answers1

4

When you want to use an action, you specify the action name and the version of the action to run. This line:

    - uses: actions/checkout@test-master

indicates that you want to use the actions/checkout action at version test-master. There is no such version of the action.

You want actions/checkout@v2. If you want to check out your branch called test-master, specify it as an option to the action. For example:

    - name: Checkout
      uses: actions/checkout@v2
      with:
        ref: 'test-master'
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • do u have any idea what is difference between actions/checkout@v2 and actions/checkout@master – knowledge20 Feb 09 '21 at 12:45
  • `actions/checkout@master` will run the code in the master branch _instead_ of the code in the `v2` branch. The `v2` branch tracks the latest release - you should use that. – Edward Thomson Feb 09 '21 at 12:52
  • v2 branch tracks the latest release for which branch master or the test-master i.e. the branch present in ref tag – knowledge20 Feb 09 '21 at 13:19
  • 2
    `v2` is the latest release of the `actions/checkout` action. It was explicitly created by the GitHub Actions team. It has nothing to do with the branch present in the `ref` tag. – Edward Thomson Feb 09 '21 at 15:28
  • so the actions/checkout@master has nothing to do with the master branch of github repo. It is also created by Github Actions team – knowledge20 Feb 09 '21 at 15:30
  • 1
    It doesn't have anything to do with the master branch of _your_ GitHub repo, that's correct. It refers to the master branch of https://github.com/actions/checkout – Edward Thomson Feb 09 '21 at 16:24
  • Hi Edward Thomson, each time my master workflow is getting executed even after giving the above code in workflow in the test-master branch. I want the workflow present in my test-master branch gets executed instead of master – knowledge20 Feb 10 '21 at 09:09
  • You can't arbitrarily run a workflow out of a different branch. Actions will run the workflow in a branch, according to the configuration. See https://docs.github.com/en/actions/reference/events-that-trigger-workflows#configuring-workflow-events – Edward Thomson Feb 10 '21 at 09:39