Skip to content

Commit d8b5261

Browse files
committed
aasdkljalksdjalkjwdlkajskldjasldkjaiwldjasldkjasdlkajsd
1 parent 9d2e904 commit d8b5261

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.github/workflows/lint.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Lint and Biome Check
2+
3+
# Run the workflow when code is pushed or when a pull request is created
4+
on:
5+
push:
6+
branches:
7+
- '**'
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
biome:
14+
name: Run Biome
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# Checkout the repository so the workflow has access to the code
19+
- name: Checkout code
20+
uses: actions/checkout@v3
21+
22+
# Run the run-biome.sh script
23+
- name: Run run-biome.sh
24+
run: scripts/run-biome.sh
25+
26+
commit-lint:
27+
name: Run Lint Commit
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Check Commit Messages
31+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
32+
with:
33+
script: |
34+
const excludedBotIds = [
35+
49699333, // dependabot[bot]
36+
];
37+
const rules = [
38+
{
39+
pattern: /^[^\r]*$/,
40+
error: "Commit message contains CRLF line breaks (only unix-style LF linebreaks are allowed)",
41+
},
42+
{
43+
pattern: /^.+(\r?\n(\r?\n.*)*)?$/,
44+
error: "Empty line between commit title and body is missing",
45+
},
46+
{
47+
pattern: /^.{0,72}(?:\r?\n(?:(.{0,72})|(.*?([a-z]+:\/\/)?(([a-zA-Z0-9_]|-)+\.)+[a-z]{2,}(:\d+)?([a-zA-Z_0-9@:%\+.~\?&/=]|-)+).*?))*$/,
48+
error: "Commit message lines are too long (maximum allowed is 72 characters, except for URLs)",
49+
},
50+
{
51+
pattern: /^((?!^Merge branch )[\s\S])*$/,
52+
error: "Commit is a git merge commit, use the rebase command instead",
53+
},
54+
{
55+
pattern: /^\S.*?\S: .+/,
56+
error: "Missing category in commit title (if this is a fix up of a previous commit, it should be squashed)",
57+
},
58+
{
59+
pattern: /^\S.*?: [A-Z0-9]/,
60+
error: "First word of commit after the subsystem is not capitalized",
61+
},
62+
{
63+
pattern: /^.+[^.\n](\r?\n.*)*$/,
64+
error: "Commit title ends in a period",
65+
},
66+
{
67+
pattern: /^((?!Signed-off-by: )[\s\S])*$/,
68+
error: "Commit body contains a Signed-off-by tag",
69+
},
70+
];
71+
72+
console.log(JSON.stringify(context.payload));
73+
74+
const { repository, pull_request } = context.payload;
75+
76+
// NOTE: This maxes out at 250 commits. If this becomes a problem, see:
77+
// https://octokit.github.io/rest.js/v18#pulls-list-commits
78+
const opts = github.rest.pulls.listCommits.endpoint.merge({
79+
owner: repository.owner.login,
80+
repo: repository.name,
81+
pull_number: pull_request.number,
82+
});
83+
const commits = await github.paginate(opts);
84+
85+
const errors = [];
86+
for (const { sha, commit: { message }, author } of commits) {
87+
if (author !== null && excludedBotIds.includes(author.id)) {
88+
continue;
89+
}
90+
const commitErrors = [];
91+
for (const { pattern, error } of rules) {
92+
if (!pattern.test(message)) {
93+
commitErrors.push(error);
94+
}
95+
}
96+
if (commitErrors.length > 0) {
97+
const title = message.split("\n")[0];
98+
errors.push([`${title} (${sha}):`, ...commitErrors].join("\n "));
99+
}
100+
}
101+
102+
if (errors.length > 0) {
103+
core.setFailed(`One or more of the commits in this PR do not match the code submission policy:\n\n${errors.join("\n")}`);
104+
}
105+

0 commit comments

Comments
 (0)