Reusable Workflows: Get the Ref inside the called workflow

This is similar to Ref Head in Reusable Workflows but not exactly the same issue.

Inside a Reusable Workflow (the called workflow) I want to have access to the ref used by the caller.

Example of caller: Here I want to get the value of my-ref (as environment variable for example) inside my reusable workflow.

name: Terraform Lint
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  terraform-lint:
    uses: org/repo/.github/workflows/my-reusable-workflow.yml@my-ref
    with:
      test: test

I know that I can pass it as inputs also but having it by default will be better to avoid duplicate values since we can’t use variables in the uses keyword yet.

My use case is that I want to download a file inside the repo org/repo using the same ref.

Example of the reusable workflow:

on:
  workflow_call:
  
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        name: Checkout source code

      - name: Downloading the default .tflint.hcl from the workflows repo
        uses: terraform-linters/tflint-load-config-action@v0
        with:
          source-repo: org/repo
          source-path: .github/workflows/files/.tflint.hcl
          # TODO: find a way to get the workflow version set by the caller workflow instead of adding a new input
          source-ref: TODO

Any idea?

1 Like

This is super important unless I want to be passing parameters full of repo’s and ref’s.

In the case of the reusable workflow grabbing code from another repo, I’m now working with far too many repos’. I should at least be able to get the REF used by the calling workflow, otherwise I need to pass these as parameters which will be a maintenance ache.

There’s reasons for not wanting to conflate everything into the same repo, and with the amount of variables accessible in the event object context already… what’s another 2? :wink:

@jenschelkopf

2 Likes

Hi @jenschelkopf , I’m just wondering if you can take a look at this :slight_smile: ?

Thanks

I’m also wondering about this as I’d like a called workflow to invoke a custom action that lives alongside it.

(Though this might also run afoul of not being able to interpolate ${{ … }} inside the uses: key of a job step? But I think I could work around this.)

2 Likes