Search code examples
githubgithub-actions

workflow_run use files from current branch


I have two branches, main and devel.

And then I have two GitHub action files, test.yml and deploy.yml. The deployment action runs after testing is done:

name: Deploy

on:
  workflow_run:
    workflows: [ 'Tests' ]
    types: [ completed ]
    branches: [ devel, main ]

This deployment action is either run on the devel or main branch, and depending on where it is run it does different things.

I expected that when the deploy action is triggered by the test action on the devel branch, the runner looks at the files from this specific branch tree, but instead the current filetree is always the one from the main branch, no matter what branch the workflow ran on.

Is there any way to change this behavior? I could not figure it out so far.


Solution

  • In the actions/checkout@v4 step you can refer to the workflow branch:

      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.workflow_run.head_branch }}