Skip to content

Commit 0bab26c

Browse files
authored
Updating template example for pull_request(-target) flow (#632)
1 parent 8c49058 commit 0bab26c

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

templates/pull-request/example-workflow.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
# Example workflow that runs on pull_request and can also be called from pull_request_target
3-
# This workflow skips execution on external forks since it won't have access to secrets when invoked via pull_request
2+
# Example workflow that runs with various triggers.
3+
# This workflow skips execution on external fork PRs since they won't have access to secrets when invoked via pull_request
44
#
5-
# Key patterns:
5+
# Example trigger patterns:
66
# 1. Triggered by pull_request (for internal PRs)
7-
# 2. Can be called via workflow_call (from pull_request_target workflow for external PRs)
8-
# 3. Skips execution on forks using condition when triggered with pull_request
9-
# 4. Explicit permissions at workflow level
7+
# 2. Triggered by push to main and workflow_dispatch (for post-merge and manual runs)
8+
# 3. Can be called via workflow_call (from pull_request_target workflow for external PRs)
9+
# 4. Skips execution on fork PRs using condition — all other event types are always allowed
1010

1111
name: Example Workflow
1212

@@ -18,6 +18,13 @@ on:
1818
paths:
1919
- "example/**"
2020
- ".github/workflows/example-workflow.yml"
21+
push:
22+
branches:
23+
- main
24+
paths:
25+
- "example/**"
26+
- ".github/workflows/example-workflow.yml"
27+
workflow_dispatch:
2128
workflow_call:
2229
inputs:
2330
custom_parameter:
@@ -33,12 +40,13 @@ jobs:
3340
check-event-source:
3441
name: Check event and source
3542
runs-on: ubuntu-24.04
36-
# Only run this job if the event is workflow_call or the PR is from the same repository (not a fork)
37-
# This avoid running it twice: once for pull_request from fork and once from pull_request_target
38-
if: github.event_name == 'workflow_call' || github.event.pull_request.head.repo.full_name == github.repository
43+
# Skip only when a pull_request event comes from a fork — all other events always run
44+
# This avoids running twice: once for the fork pull_request and once via pull_request_target → workflow_call
45+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
3946
steps:
4047
- name: Check PR event and source
41-
run: echo "This PR is from the same repository (Not a fork) or called via workflow_call."
48+
run: echo "This PR is from the same repository (Not a fork) or not triggered via pull_request"
49+
4250
example-job:
4351
name: Run example job
4452
runs-on: ubuntu-24.04

0 commit comments

Comments
 (0)