Skip to content

Commit 9fd01be

Browse files
committed
aasdkljalksdjalkjwdlkajskldjasldkjaiwldjasldkjasdlkajsd
1 parent 9d2e904 commit 9fd01be

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

.github/workflows/biome-lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

.github/workflows/commit-lint.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: commit lint
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
7+
commit-lint:
8+
name: Run Lint Commit
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check Commit Messages
12+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
13+
with:
14+
script: |
15+
const excludedBotIds = [
16+
49699333, // dependabot[bot]
17+
];
18+
const rules = [
19+
{
20+
pattern: /^[^\r]*$/,
21+
error: "Commit message contains CRLF line breaks (only unix-style LF linebreaks are allowed)",
22+
},
23+
{
24+
pattern: /^.+(\r?\n(\r?\n.*)*)?$/,
25+
error: "Empty line between commit title and body is missing",
26+
},
27+
{
28+
pattern: /^.{0,72}(?:\r?\n(?:(.{0,72})|(.*?([a-z]+:\/\/)?(([a-zA-Z0-9_]|-)+\.)+[a-z]{2,}(:\d+)?([a-zA-Z_0-9@:%\+.~\?&/=]|-)+).*?))*$/,
29+
error: "Commit message lines are too long (maximum allowed is 72 characters, except for URLs)",
30+
},
31+
{
32+
pattern: /^((?!^Merge branch )[\s\S])*$/,
33+
error: "Commit is a git merge commit, use the rebase command instead",
34+
},
35+
{
36+
pattern: /^\S.*?\S: .+/,
37+
error: "Missing category in commit title (if this is a fix up of a previous commit, it should be squashed)",
38+
},
39+
{
40+
pattern: /^\S.*?: [A-Z0-9]/,
41+
error: "First word of commit after the subsystem is not capitalized",
42+
},
43+
{
44+
pattern: /^.+[^.\n](\r?\n.*)*$/,
45+
error: "Commit title ends in a period",
46+
},
47+
{
48+
pattern: /^((?!Signed-off-by: )[\s\S])*$/,
49+
error: "Commit body contains a Signed-off-by tag",
50+
},
51+
];
52+
53+
console.log(JSON.stringify(context.payload));
54+
55+
const { repository, pull_request } = context.payload;
56+
57+
// NOTE: This maxes out at 250 commits. If this becomes a problem, see:
58+
// https://octokit.github.io/rest.js/v18#pulls-list-commits
59+
const opts = github.rest.pulls.listCommits.endpoint.merge({
60+
owner: repository.owner.login,
61+
repo: repository.name,
62+
pull_number: pull_request.number,
63+
});
64+
const commits = await github.paginate(opts);
65+
66+
const errors = [];
67+
for (const { sha, commit: { message }, author } of commits) {
68+
if (author !== null && excludedBotIds.includes(author.id)) {
69+
continue;
70+
}
71+
const commitErrors = [];
72+
for (const { pattern, error } of rules) {
73+
if (!pattern.test(message)) {
74+
commitErrors.push(error);
75+
}
76+
}
77+
if (commitErrors.length > 0) {
78+
const title = message.split("\n")[0];
79+
errors.push([`${title} (${sha}):`, ...commitErrors].join("\n "));
80+
}
81+
}
82+
83+
if (errors.length > 0) {
84+
core.setFailed(`One or more of the commits in this PR do not match the code submission policy:\n\n${errors.join("\n")}`);
85+
}
86+
87+
- name: Create PR comment on bad commit message
88+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
89+
if: ${{ failure() && !github.event.pull_request.draft }}
90+
with:
91+
script: |
92+
// If a comment already exists, skip
93+
const { data: comments } = await github.rest.issues.listComments({
94+
issue_number: context.issue.number,
95+
owner: context.repo.owner,
96+
repo: context.repo.repo,
97+
});
98+
99+
const existingComment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('commit messages in this PR'));
100+
101+
if (existingComment) {
102+
core.info('Preview comment already exists. Skipping...');
103+
return;
104+
}
105+
106+
const body = `### <span aria-hidden="true">❌</span>
107+
Hello!\n\nOne or more of the commit messages in this PR do not match the nginx-hugo-theme [git guidelines](https://github.com/nginxinc/nginx-hugo-theme/blob/main/CONTRIBUTING.md#git-guidelines), please check the `lint_commits` CI job for more details on which commits were flagged and why.\nPlease do not close this PR and open another, instead modify your commit message(s) with [git commit --amend](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message) and force push those changes to update this PR.
108+
`;
109+
110+
await github.rest.issues.createComment({
111+
issue_number: context.issue.number,
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
body: body,
115+
});

0 commit comments

Comments
 (0)