Skip to content

Commit 7805e20

Browse files
authored
.github/workflows: validate that the directories exist (#33289)
A new pointless fad appeared recently where people just create a fairly low information tag at the beginning of their github PR titles. Something like `feat` or other keywords. This seems to originate from the angular community and to be used for automation scripts over there. We do not use any of those scripts and if we did we would be using the github labels, which offer strictly equivalent functionalities without wasting useful PR title space. In order for these keywords to fail the validation, I am adding a check that these directories listed indeed exist in the repository.
1 parent 3bbf5f5 commit 7805e20

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

.github/workflows/validate_pr.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,37 @@ jobs:
88
validate-pr:
99
runs-on: ubuntu-latest
1010
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
1114
- name: Check PR Title Format
1215
uses: actions/github-script@v7
1316
with:
1417
script: |
18+
const fs = require('fs');
19+
const path = require('path');
1520
const prTitle = context.payload.pull_request.title;
1621
const titleRegex = /^([\w\s,{}/.]+): .+/;
1722
1823
if (!titleRegex.test(prTitle)) {
1924
core.setFailed(`PR title "${prTitle}" does not match required format: directory, ...: description`);
2025
return;
2126
}
27+
28+
const match = prTitle.match(titleRegex);
29+
const dirPart = match[1];
30+
const directories = dirPart.split(',').map(d => d.trim());
31+
const missingDirs = [];
32+
for (const dir of directories) {
33+
const fullPath = path.join(process.env.GITHUB_WORKSPACE, dir);
34+
if (!fs.existsSync(fullPath)) {
35+
missingDirs.push(dir);
36+
}
37+
}
38+
39+
if (missingDirs.length > 0) {
40+
core.setFailed(`The following directories in the PR title do not exist: ${missingDirs.join(', ')}`);
41+
return;
42+
}
2243
2344
console.log('✅ PR title format is valid');

0 commit comments

Comments
 (0)