In addition to push events, workflows can be triggered off of a variety of other events as well. In the examples below we will see some in action and understand their caveats. One main caveat of many events is that they must be in the default branch to function.
See event trigger documentation for more details information.
We will start by creating a workflow triggered by opening an issue and see first-hand one of the most important details of non-push event workflows.
- From the default branch of your repository, create a new branch of code called
feature/issue-workflow
- Create a new file named
.github/workflows/issue-workflow.yaml
- Copy the contents below to the newly created file:
name: Issue Events
on:
issues:
types: [opened]
jobs:
doing-more-things:
name: Doing Things From Issues
runs-on: ubuntu-latest
steps:
- name: Output Issue Information
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_ACTION: ${{ github.event.action }}
run: echo "The action '${EVENT_ACTION}' was performed against '${EVENT_NAME}'."
- Add & commit your changes, then publish your branch.
- Go to your repository, and create an issue.
The result will be that nothing happens because this event requires the workflow to be defined in the default branch. In our case, we must push this to default branch.
- Open a pull request to merge
feature/issue-workflow
into your default branch. - Merge the pull request and delete the branch
- Go to your repository, and create an issue.
The result will be an execution of the Issue Event Workflow that outputs "The action 'opened' was performed against 'issues'".
- Checkout to the default branch on your local repository and pull down the changes.