Worflow with dispatch and branches setting suddenly not supported anymore

This doesn’t seem to be supported anymore:

on:
  workflow_dispatch:
    branches:
      - main  # Set a branch to deploy

What is the new correct approach?

Invalid workflow file: .github/workflows/main.yml#L5

The workflow is not valid. .github/workflows/main.yml (Line: 5, Col: 5): Unexpected value ‘branches’

About 22 hours ago it still worked like this.

16 Likes

I’m not sure that ever was supported, I suspect the parser got stricter and is now giving you an error instead of ignoring the unexpected element. There definitely isn’t a recent change in the documentation that removed a mention of branches there.

What are you trying to achieve?

1 Like

Trying to allow GitHub to run the workflow only on specific branches. Interestingly it worked before. There was also a (yellow) notification in the branch selection for the action, that it is not configured / allowed for other branches.

1 Like

Peculiar! If it worked before it might be worth a Bug report - GitHub Support.

Thanks, I’ve created a bug report.

3 Likes

Are bug reports linkable @DanielRuf ? I ran into a similar error with a workflow of mine today:

on:
  workflow_dispatch:
    branches: [main]

Hi, I’ve recently had the same problem with a workflow dispatch:

on:
  schedule:
    - cron: "30 5 * * *"
  workflow_dispatch:
    branches:
    - master

and received:

GitHub Actions
Invalid workflow file
The workflow is not valid. .github/workflows/update-image.yml (Line: 8, Col: 5): Unexpected value  'branches'

Could you please link the bug report?

Could you please share a link to the bug report?
I also got the same error today and am looking for a solution.

on:
  workflow_dispatch:
    branches: [ develop ]

Hi,
I am also facing the same error, please help what the solutions

on:
  workflow_dispatch:
    branches: [ release* ]

So far no update in the ticket, which I can share when I have received some feedback there. In general it contains exactly what I have written here and nothing more.

I will keep you updated when I receive an answer from GitHub.

this error cause stopper in my environment

I also had the same issue. I removed branches. Now it is mostly always checkout from main. The workflow looks something like the below.

on:
workflow_dispatch:

1 Like

Looks like GitHub completely broke workflow dispatch behavior with whatever changes they recently pushed. Now SECRETS are not supported…

Our workflow also started throwing a “Unexpected value ‘branches’” error today

on:
  workflow_dispatch:
    branches:
      - master

i solved this issue with this:

inputs:
      branch:
        default: "branch_name"

 - name: Setup branch to use
        uses: actions/checkout@v2
        with:
          repository: ${{ github.repository }}
          ref: '${{ github.event.inputs.branch }}' 

First feedback in my support ticket:

Thank you for contacting GitHub Support and sorry for the trouble.

I have raised this up with the engineering team to investigate.

I’ll provide an update as soon as I hear back from the team.

1 Like

The ability to specify branches was documented in a json-schema, which is loaded by GoLand so probably also by other Jetbrains IDEs.

https://json.schemastore.org/github-workflow.json

Edit: The json-schema does not mention branches for workflow_dispatch, only for pull_request. So based on that, it seems like the feature was undocumented.

If you change the workflow code from:

on:
  workflow_dispatch:
    branches:
      - master

to:

on:
  workflow_dispatch:

the workflow works again…

When you do this, with the ‘Run workflow’ button, you can select all branches to run the workflow against. In my understanding this additional branches parameter was a filter on the available branches you are able to select but I don’t see find it in the documentation.

Correct, I’ve resolved it by adding # at the start of the two lines for the branches. But I vaguely remember, that this solution with workflow_dispatch + branches was mentioned / documented somewhere.

Same error here! I’ve just reported the bug using the following link: Bug report - GitHub Support.
I also checked actions documentation and nothing seems changed: Workflow syntax for GitHub Actions - GitHub Docs