Skip to content

Commit 44e6ddc

Browse files
committed
GH Actions: auto-label new PRs
Similar workflow as the one used in the main PHP_CodeSniffer repo to auto-apply some labels based on the contents of new PRs. Ref: https://github.com/srvaroa/labeler
1 parent 93f71d1 commit 44e6ddc

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

.github/labeler.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: 1
2+
appendOnly: true
3+
labels:
4+
- label: "Status: triage"
5+
draft: false
6+
author-can-merge: false
7+
8+
- label: "Component: Website"
9+
draft: false
10+
files:
11+
- "src/.*"
12+
13+
- label: "Component: Wiki"
14+
draft: false
15+
files:
16+
- "build/wiki-command-replacer.sh"
17+
- "build/wiki-code-samples/.*"
18+
- "wiki/.*"
19+
20+
- label: "Type: chores/QA/automation"
21+
draft: false
22+
files:
23+
- ".yamllint.yml"
24+
- ".github/.*"
25+
- "build/wiki-command-replacer.sh"

.github/workflows/label-new-prs.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Label new PRs
2+
3+
on:
4+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
5+
# The `pull_request_target` event is used for "normal" PRs to label them when they are opened.
6+
# This will use the `labeler.yml` file in the default (main) branch of the repo.
7+
pull_request_target:
8+
types:
9+
- opened
10+
- ready_for_review
11+
12+
# The `pull_request` event is used for PRs which change the files which handle the labeling to prevent a silently failing action.
13+
# This will use the `labeler.yml` file in the PR branch.
14+
pull_request:
15+
paths:
16+
- '.github/workflows/label-new-prs.yml'
17+
- '.github/labeler.yml'
18+
19+
jobs:
20+
label-new-prs:
21+
runs-on: ubuntu-latest
22+
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target'
23+
24+
name: Add labels to new PRs
25+
26+
steps:
27+
- name: Label new PRs
28+
uses: srvaroa/labeler@v1
29+
env:
30+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
31+
32+
validate-labeler-worflow:
33+
runs-on: ubuntu-latest
34+
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request' && github.event.pull_request.merged == false
35+
36+
name: Validate changes to Labeler logic
37+
38+
steps:
39+
# Checkout is needed to use the `use_local_config` option.
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
43+
- name: Verify changes to the labeling logic
44+
uses: srvaroa/labeler@v1
45+
with:
46+
use_local_config: true
47+
fail_on_error: true
48+
env:
49+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

0 commit comments

Comments
 (0)