'use selected branch on workflow_dispatch in github actions

enter image description here

Hi everyone, I am building Github actions workflow to use master and develop branches. I know that i can check out branch by reusing actions like below, but how do i actually pass variable form the manual workflow_dispatch dropdown?

   uses: actions/checkout@v2
   with:
     ref: develop

Since workflows can be created only in default branch, the only workaround is to create trigger workflow that is reusing core workflow and passing branch as parameter.

UPDATE Here is the code for master (production) branch

name: Trigger ECR deploy


on:
  release:
      types: [published]
  workflow_dispatch:
  
jobs:
  deploy-terraform:
    uses: <reusable-workflow-path>
    with:
      AWS_REGION: "ap-south-1"                  
      ECR_REPOSITORY: "repo-name-here"
      BRANCH: "master"
    secrets:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

This is another file for staging env

name: Trigger ECR deploy


on:
  release:
      types: [published]
  workflow_dispatch:
  
jobs:
  deploy-terraform:
    uses: <reusable-workflow-url>
    with:
      AWS_REGION: "ap-south-1"                  
      ECR_REPOSITORY: "repo-name-here"
      BRANCH: "develop"
      ENVIRONMENT: "staging"
    secrets:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Both these files are in master branch at the moment. I recreated staging file in develop branch (i kept the name of the file the same). However, when i go to trigger workflow i still get this error as seen on screenshot. The parameters that I pass to reusable workflow is like a workaround.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source