Workflow_run doen't preserve github.ref?

Hello,

I have 2 workflows linked by the workflow_run feature.
When creating a release (= when pushing a git tag) :

  • on the main workflow my github.ref is "ref": "refs/tags/v0.2.0"
  • but on the “workflow_run” one, my github.ref is still "ref": "refs/heads/master"

Both ref are on the same sha.

My goal is to keep the “release” part of my workflows isolated, and trigger the “workflow_run” one only when tags are pushed AND the primary workflow completes successfully.

first one :

name: .NET Core
on:
  push:
    tags:
      - '**'
    branches:
      - master
  pull_request:

second one :

name: Upload Release Asset
on:
  workflow_run:
    workflows: [".NET Core"]
    types:
      - completed

Is this a known bug ? a known limitation ? is there a workaround ?

I created a simple repro :

I think this is just a limitation of how this feature works with respect to the way you’re using it. The second workflow is completely independent of the first and will receive a brand new webhook event to trigger it meaning it will just be triggered using the “default” git ref.

Is there a specific reason you’re wanting keep this in a completely separate file? For this situation I’d probably recommend just using a separate job inside the same workflow file. You can use the needs key to prevent your release job from running until your first job completes, and this should preserve the git ref too as it will still be the same webhook event that triggered the workflow.

The second workflow is completely independent of the first

I disagree, the second workflow depends of the first, that’s the intention of the "workflow_run’ feature: let workflows depends on others. Or I completely miss the point.

In my specific case, I need to know there’s a git tag. (More precisely, I want to know the workflow is running because of a tag.). So the git ref is mandatory.

The specific reason I would like to have two separates workflow is just CI structure : having smaller workflow files, and let run specific workflows (like a “publish/release artifact” run only when needed).
I know I can “just put everything in one workflow”, but it seems really more convenient to have distinct workflow, and just run what’s needed when needed.

Moreover, it would allow us to re-use previous parts of the the build. Ex : if I have 5 workflows, and each one need to build and test the whole repository before doing the “remaining part of the job”, it looks like a major resource waste as I could have just build and test the commit once, and then run the “other things” in the 4 or 5 dependent workflows…

That’s why I’m convinced git ref should be propagated from “main” workflows to “dependent workflows”.

Thanks to the GH support, the answer is here : Workflow_run not working as expected - #4 by brightran

We can access the original ref with

github.event.workflow_run.head_branch

Problem solved ! :rocket: