github-actions

Get GitHub Action version inside the action


Consider a GitHub Action that:

  1. Downloads a binary
  2. Untars and runs the binary

The binary version depends on the version of the action. When the action is used like

uses: action_x@v3

I am trying to get the v3 inside the action, so that I can map it to the corresponding binary version.

Is there a way to do this without having to hard-code the binary version on the YAML file (and remember to bump it on release)?


Solution

  • Looking at GitHub Contexts, it seems that github.action_ref should contain what you are looking for:

    For a step executing an action, this is the ref of the action being executed. For example, v2.

    jobs:
      show_checkout_version:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - run: echo '${{ github.action_ref }}'