UPDATE: @hayesgm answer may be better choice since using push
/pull_request
workflow trigger will register new workflow in GitHub and then you can just remove unneeded push
/pull_request
events trigger and run workflow using gh
command. It works without merging anything to default branch.
UPDATE 2: Seems like using @hayesgm way may not work for you if you expect to see "Run workflow" dropdown in GitHub UI for your not yet merged workflow. It will be available to see on workflow list in Actions tab and will be available to run using gh
but not by using GitHub UI.
UPDATE 3: I could not find it documented anywhere but I think workflow is registered only if it exist on default branch or if it was run at least once on non-default branch. In case of non default branch, GitHub knows about workflow existence only when it has workflow run logs available. If you remove all workflow logs for it, then it will get unregistered and you cannot run it any more. This is not the case for workflows that exist on default branch. Those are always available even without any workflow run logs.
- Seems like it works as you described
- Text seems to change when you run workflow on non main branch and on this branch workflow name changed to something new...
This workflow name change is really strange. I couldn't find any docs describing this behavior.
Testing workflows
One thing that needs to be done before testing is to actually add dummy workflow with same filename to main
/master
. Without this workflow won't appear in actions tab.
How to test:
- Create dummy Readme.md and some dummy
.github/workflows/workflow.yml
to test:
name: Test run v1
on:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-18.04
steps:
- name: Show environment v1
run: env | grep ^GITHUB
- name: Show ref v1
run: echo "===============> Version from $GITHUB_REF"
- Push to your default branch (probably
main
or master
)
- New action should appear there
- You can now run dummy workflow
Testing branch run:
- Create new branch
test-branch
from default repo branch
- Modify workflow file
.github/workflows/workflow.yml
name: Test run v2
on:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-18.04
steps:
- name: Show environment v2
run: env | grep ^GITHUB
- name: Show ref v2
run: echo "===============> Version from $GITHUB_REF"
- Commit and push to
test-branch
- Go to
Actions
- Click
Test run v1
and set Use workflow from
to test-branch
.
- Click run workflow button
You should see different step names than in default repo branch workflow version and different GITHUB_REF
.
The weird thing is that after running workflow on test-branch
somehow without merging anything, my previous workflow (from default repo branch) changed name to new version.