I was trying to implement github actions when PR is merged. It also had a part of workflow dispatch.
name: Deploy to DEV
on:
push:
branches:
- dev
paths-ignore:
- '.github/**'
workflow_dispatch:
jobs:
Deploy-to-Dev:
if: github.event.pull_request.merged == true
runs-on: ubuntu-22.04
So what i wanted to know was will Deploy-t0-Dev run or skips? If i trigger from workflow dispatch? I currently couldn’t test it due to client requirements. Thanks
2
Answers
For readability and semantics sake, you can use pull_request event trigger instead of push.
Among others, pull_request event has
closed
activity type:And to check if the action is triggered by workflow_dispatch event, you can use
GITHUB_EVENT_NAME
environment variable.reference
Your code would like this:
Example code snippet reference
Above workflow runs either when pull request is merged or when workflow is triggered manually via
workflow_dispatch
event.In the workflow you defined, the Deploy-to-Dev job will be skipped when triggered via workflow dispatch because its condition
github.event.pull_request.merged == true
does not apply to workflow dispatch events.To allow the job to run on both pull request merges and workflow dispatches, you can modify the if condition like this:
This condition will enable the job to run for both merged pull requests and manual triggers via workflow dispatch.