0

I have two GitHub Actions workflows: infra and build. A successful infra run will trigger a build run by way of the following configuration:

name: infra

on:
  push:
    branches: [ main ]
name: build

on:
  workflow_run:
    workflows: [ infra ]
    types: [ completed ]
    branches: [ main ]

Each infra workflow run is named after the commit message that triggered it. However, each build run is just named "build".

Is it possible to propagate the name of one workflow run to downstream runs that are triggered in this way? If so, how?

Blair Nangle
  • 1,221
  • 12
  • 18
  • 1
    Maybe [`run-name`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#run-name) is useful here? – Benjamin W. Apr 10 '23 at 15:57

1 Answers1

0

infra has the commit data in the github context push event object. its commit message information can be passed as output to other jobs.

in general it works by setting the id and then the output.

the other job, e.g. build then can refer to it, for example as suggested by Benjamin W. via run-name.

run-name: Deploy to ${{ inputs.deploy_target }} by @${{ github.actor }}

(Example of run-name)

A recent example setting and obtaining output is in the answer to How can I trigger github actions on every 3rd Saturday of a month?. As this question requires output from jobs, it need to be extended with the job output bindings:

jobs:
  job1:
    runs-on: ubuntu-latest
    # Map a step output to a job output
    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}
    steps:
      - id: step1
        run: echo "test=hello" >> "$GITHUB_OUTPUT"
      - id: step2
        run: echo "test=world" >> "$GITHUB_OUTPUT"
  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:
      - env:
          OUTPUT1: ${{needs.job1.outputs.output1}}
          OUTPUT2: ${{needs.job1.outputs.output2}}
        run: echo "$OUTPUT1 $OUTPUT2"

(Example: Defining outputs for a job)

hakre
  • 193,403
  • 52
  • 435
  • 836