github-actions

How to access the caller Workflow name in a Github Composite Action?


I created a Github Actions composite action and want to retrieve the caller Workflow's name.

I tried github.run-name but it resolved to an empty string. Example code is below. Also I considered an input instead but seemed it would add unnecessary complexity.

Callee Workflow

name: Build App
jobs:
  build_app:
    runs-on: [...]
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/post-to-slack

Composite Action

name: Post to Slack
description: Posts the results of a Workflow to the Slack channel
runs:
  using: "composite"
  steps:
    - uses: slackapi/slack-github-action@v1.24.0
      with:
        channel-id: 'build-results'
        slack-message: "${{ github.run-name }} completed. The status is ${{ job.status }}."

^ I expected github.run-name to return Build App


Solution

  • The run-name refers to the workflow syntax and is: "The name for workflow runs generated from the workflow.".

    With github.workflow you can refer to the GitHub context and get information about workflow runs, like this:

    name: Post to Slack
    description: Posts the results of a Workflow to the Slack channel
    runs:
      using: "composite"
      steps:
        - uses: slackapi/slack-github-action@v1.24.0
          with:
            channel-id: 'build-results'
            slack-message: "${{ github.workflow }} completed. The status is ${{ job.status }}."
    

    Workflow run log:

    GitHub workflow run log

    Note that I was copying your code without properly setting up the action, thus the error, but you can see the variable was resolved correctly to the Build App workflow in the slack-message.