Github Action uses action on branch

Viewed 593

Anyone know how to dynamically pass the name of the branch that triggered the workflow into the uses key?

Example

# my workflow
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Run on branch
      - uses: {org}/{repo}@{branch-name}

My repo is a Github Action. When I create a new branch to make changes to the action I have tests that run the action. But without specifying the branch name they run on the master branch, with the old code, instead of the branch that triggered the workflow.

1 Answers

While this does not answer how to pass dynamic values to the uses key, it does seem to have solved my problem.


The checkout action has a ref key you can provide to specify which branch of the repo is checked out.

Once I specified the branch and passed uses a relative path, commits made by the test workflow are being committed to the specified branch, and not master.

# my workflow
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
          with:
            ref: ${{ github.ref }}
      - name: Make Test Changes
      - uses: ./
Related