Skip to content

Girhub bit branch determination is not reliable #363

@konclave

Description

@konclave

Bug

Currently, the working branch determination in the Github environment relies on the GITHUB_REF environment variable value.
But this works correctly only if the workflow was triggered by pretty limited number of events: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows

Only the ones that update the GITHUB_REF.

For instance, in my case I start semantic-release in the workflow that is triggered by the workflow_run event and I explicitly checkout the repository main branch in it:

name: Build 
on:
  workflow_run:
    workflows:
      - Run tests
    types:
      - completed
      - 
jobs:
  BuildApp:
    name: Build application
    runs-on: ubuntu-latest
    outputs:
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ github.event.workflow_run.head_branch }}
...

And in that case, GITHUB_REF points to the default repository branch (which is develop in my case), but I'm working with the main branch.

As we anyway in the environment that should have a git CLI, why not just get the current branch from the git branch output execution, if that is possible?

Environment:

  • CI: Github

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions