From 1b22582c910c6f3db989d4b1361da17e4ae51509 Mon Sep 17 00:00:00 2001 From: Sarah Edwards Date: Thu, 24 Feb 2022 08:18:29 -0800 Subject: [PATCH] add example for PR merged workflow (#25594) --- .../events-that-trigger-workflows.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/content/actions/using-workflows/events-that-trigger-workflows.md b/content/actions/using-workflows/events-that-trigger-workflows.md index 1ab3cac12511..29899baf0572 100644 --- a/content/actions/using-workflows/events-that-trigger-workflows.md +++ b/content/actions/using-workflows/events-that-trigger-workflows.md @@ -685,6 +685,25 @@ on: {% endnote %} +#### Running your workflow when a pull request merges + +When a pull request merges, the pull request is automatically closed. To run a workflow when a pull request merges, use the `pull_request` `closed` event type along with a conditional that checks the `merged` value of the event. For example, the following workflow will run whenever a pull request closes. The `if_merged` job will only run if the pull request was also merged. + +```yaml +on: + pull_request: + types: + - closed + +jobs: + if_merged: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - run: | + echo The PR was merged +``` + {% data reusables.developer-site.pull_request_forked_repos_link %} ### `pull_request_comment` (use `issue_comment`) @@ -869,6 +888,25 @@ on: {% endnote %} +#### Running your workflow when a pull request merges + +When a pull request merges, the pull request is automatically closed. To run a workflow when a pull request merges, use the `pull_request_target` `closed` event type along with a conditional that checks the `merged` value of the event. For example, the following workflow will run whenever a pull request closes. The `if_merged` job will only run if the pull request was also merged. + +```yaml +on: + pull_request_target: + types: + - closed + +jobs: + if_merged: + if: github.event.pull_request_target.merged == true + runs-on: ubuntu-latest + steps: + - run: | + echo The PR was merged +``` + ### `push` | Webhook event payload | Activity types | `GITHUB_SHA` | `GITHUB_REF` |