Skip to content

Commit 9caf9f1

Browse files
Add repo-specific condition to labeling workflows (#112169)
* Condition labeling workflows to only run on dotnet/runtime. * Improve readme * Add jeffhandley as explicit workflow owner Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
1 parent db172de commit 9caf9f1

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@
112112
/docs/area-owners.* @jeffhandley
113113
/docs/issue*.md @jeffhandley
114114
/.github/policies/ @jeffhandley @mkArtakMSFT
115-
/.github/workflows/ @dotnet/runtime-infrastructure
115+
/.github/workflows/ @jeffhandley @dotnet/runtime-infrastructure

.github/workflows/README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,21 @@
22

33
General guidance:
44

5-
- Please make sure to include the @dotnet/runtime-infrastructure group as a reviewer of your PRs.
6-
- Do not use the `pull_request` event. Use `pull_request_target` instead, as documented in [Workflows in forked repositories](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflows-in-forked-repositories) and [pull_request_target](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target).
5+
Please make sure to include the @dotnet/runtime-infrastructure group as a reviewer of your PRs.
6+
7+
For workflows that are triggered by pull requests, refer to GitHub's documentation for the `pull_request` and `pull_request_target` events. The `pull_request_target` event is the more common use case in this repository as it runs the workflow in the context of the target branch instead of in the context of the pull request's fork or branch. However, workflows that need to consume the contents of the pull request need to use the `pull_request` event. There are security considerations with each of the events though.
8+
9+
Most workflows are intended to run only in the `dotnet/runtime` repository and not in forks. To force workflow jobs to be skipped in forks, each job should apply an `if` statement that checks the repository name or owner. Either approach works, but checking only the repository owner allows the workflow to run in copies or forks withing the dotnet org.
10+
11+
```yaml
12+
jobs:
13+
job-1:
14+
# Do not run this job in forks
15+
if: github.repository == 'dotnet/runtime'
16+
17+
job-2:
18+
# Do not run this job in forks outside the dotnet org
19+
if: github.repository_owner == 'dotnet'
20+
```
21+
22+
Refer to GitHub's [Workflows in forked repositories](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflows-in-forked-repositories) and [pull_request_target](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target) documentation for more information.

.github/workflows/check-no-merge-label.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212

1313
jobs:
1414
check-labels:
15+
if: github.repository == 'dotnet/runtime'
1516
runs-on: ubuntu-latest
1617
steps:
1718
- name: Check 'NO-MERGE' label

.github/workflows/check-service-labels.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111

1212
jobs:
1313
check-labels:
14+
if: github.repository == 'dotnet/runtime'
1415
runs-on: ubuntu-latest
1516
steps:
1617
- name: Check 'Servicing-approved' label

0 commit comments

Comments
 (0)