Skip to content

Commit 76760e7

Browse files
authored
Merge branch 'main' into verify-artifact-attestations
2 parents 4c9e668 + e0cc9e5 commit 76760e7

File tree

8 files changed

+107
-37
lines changed

8 files changed

+107
-37
lines changed

.commit-check.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ checks:
2323
regex: ^.+@.+$
2424
error: The committer email seems invalid
2525
suggest: run command `git config user.email yourname@example.com`
26+
27+
- check: merge_base
28+
regex: main # it can be master, develop, devel etc based on your project.
29+
error: Current branch is not rebased onto target branch
30+
suggest: please ensure your branch is rebased with the target branch

.github/workflows/commit-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- uses: actions/checkout@v4
1616
with:
1717
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
18+
fetch-depth: 0 # fetch all history for all branches and tags
1819
- uses: ./ # self test
1920
env:
2021
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
@@ -24,5 +25,6 @@ jobs:
2425
author-name: true
2526
author-email: true
2627
commit-signoff: true
28+
merge-base: true
2729
job-summary: true
2830
pr-comments: ${{ github.event_name == 'pull_request' }}

.github/workflows/pre-commit.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Run pre-commit
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: opened
7+
8+
jobs:
9+
pre-commit:
10+
uses: commit-check/.github/.github/workflows/pre-commit.yml@main

.pre-commit-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ repos:
1717
rev: 24.10.0
1818
hooks:
1919
- id: black
20-
# FIXME: main.py:109: error: Item "None" of "str | None" has no attribute "split" [union-attr]
21-
# - repo: https://github.com/pre-commit/mirrors-mypy
22-
# rev: v1.12.0
23-
# hooks:
24-
# - id: mypy
20+
- repo: https://github.com/pre-commit/mirrors-mypy
21+
rev: v1.12.0
22+
hooks:
23+
- id: mypy
2524
- repo: https://github.com/codespell-project/codespell
2625
rev: v2.3.0
2726
hooks:

README.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
[![Main](https://github.com/commit-check/commit-check-action/actions/workflows/main.yaml/badge.svg)](https://github.com/commit-check/commit-check-action/actions/workflows/main.yaml)
44
[![Commit Check](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml/badge.svg)](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml)
55
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/commit-check/commit-check-action)
6-
[![Used by](https://img.shields.io/static/v1?label=Used%20by&message=37&color=informational&logo=slickpic)](https://github.com/commit-check/commit-check-action/network/dependents)<!-- used by badge -->
6+
[![Used by](https://img.shields.io/static/v1?label=Used%20by&message=43&color=informational&logo=slickpic)](https://github.com/commit-check/commit-check-action/network/dependents)<!-- used by badge -->
77
[![GitHub marketplace](https://img.shields.io/badge/Marketplace-commit--check--action-blue)](https://github.com/marketplace/actions/commit-check-action)
88

99
A Github Action for checking commit message formatting, branch naming, committer name, email, commit signoff and more.
1010

11+
## Table of Contents
12+
13+
* [Usage](#usage)
14+
* [Optional Inputs](#optional-inputs)
15+
* [GitHub Action Job Summary](#github-action-job-summary)
16+
* [GitHub Pull Request Comments](#github-pull-request-comments)
17+
* [Badging Your Repository](#badging-your-repository)
18+
* [Versioning](#versioning)
19+
1120
## Usage
1221

1322
Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/commit-check.yml](.github/workflows/commit-check.yml)
@@ -30,6 +39,7 @@ jobs:
3039
- uses: actions/checkout@v4
3140
with:
3241
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
42+
fetch-depth: 0 # required for merge-base check
3343
- uses: commit-check/commit-check-action@v1
3444
env:
3545
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
@@ -39,6 +49,7 @@ jobs:
3949
author-name: true
4050
author-email: true
4151
commit-signoff: true
52+
merge-base: false
4253
job-summary: true
4354
pr-comments: ${{ github.event_name == 'pull_request' }}
4455
```
@@ -49,75 +60,86 @@ jobs:
4960

5061
- **Description**: check commit message formatting convention.
5162
- By default the rule follows [conventional commits](https://www.conventionalcommits.org/).
52-
- Default: 'true'
63+
- Default: `true`
5364

5465
### `branch`
5566

5667
- **Description**: check git branch naming convention.
5768
- By default follow bitbucket [conventional branch](https://conventional-branch.github.io/).
58-
- Default: 'true'
69+
- Default: `true`
5970

6071
### `author-name`
6172

62-
- **Description**: check committer author name
63-
- Default: 'true'
73+
- **Description**: check committer author name.
74+
- Default: `true`
6475

6576
### `author-email`
6677

67-
- **Description**: check committer author email
68-
- Default: 'true'
78+
- **Description**: check committer author email.
79+
- Default: `true`
6980

7081
### `commit-signoff`
7182

72-
- **Description**: check committer commit signature
73-
- Default: 'true'
83+
- **Description**: check committer commit signature.
84+
- Default: `true`
85+
86+
### `merge-base`
87+
88+
- **Description**: check current branch is rebased onto target branch.
89+
- Default: `false`
90+
91+
> [!IMPORTANT]
92+
> `merge-base` is an experimental feature. by default it's disable.
93+
>
94+
> To use this feature, you need fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`.
7495

7596
### `dry-run`
7697

7798
- **Description**: run checks without failing. exit code is 0 otherwise is 1.
78-
- Default: 'false'
99+
- Default: `false`
79100

80101
### `job-summary`
81102

82-
- **Description**: display job summary to the workflow run
83-
- Default: 'true'
103+
- **Description**: display job summary to the workflow run.
104+
- Default: `true`
84105

85106
### `pr-comments`
86107

87-
- **Description**: post results to the pull request comments
88-
- Default: 'true'
108+
- **Description**: post results to the pull request comments.
109+
- Default: `false`
89110

90111
> [!IMPORTANT]
91-
> This is a experimental feature
92-
> use it you need to set `GITHUB_TOKEN` in the GitHub Action.
112+
> `pr-comments` is an experimental feature. by default it's disable. To use it you need to set `GITHUB_TOKEN` in the GitHub Action.
113+
>
114+
> This feature currently doesn’t work with forked repositories. For more details, refer to issue [#77](https://github.com/commit-check/commit-check-action/issues/77).
93115

94116
Note: the default rule of above inputs is following [this configuration](https://github.com/commit-check/commit-check/blob/main/.commit-check.yml), if you want to customize just add your `.commit-check.yml` config file under your repository root directory.
95117

96-
## GitHub Action job summary
118+
## GitHub Action Job Summary
97119

98120
By default, commit-check-action results are shown on the job summary page of the workflow.
99121

100-
### Success job summary
122+
### Success Job Summary
101123

102124
![Success job summary](https://github.com/commit-check/.github/blob/main/screenshot/success-job-summary.png)
103125

104-
### Failure job summary
126+
### Failure Job Summary
105127

106128
![Failure job summary](https://github.com/commit-check/.github/blob/main/screenshot/failure-job-summary.png)
107129

108-
## GitHub Pull Request comments
130+
## GitHub Pull Request Comments
109131

110-
### Success pull request comment
132+
### Success Pull Request Comment
111133

112134
![Success pull request comment](https://github.com/commit-check/.github/blob/main/screenshot/success-pr-comments.png)
113135

114-
### Failure pull request comment
136+
### Failure Pull Request Comment
115137

116138
![Failure pull request comment](https://github.com/commit-check/.github/blob/main/screenshot/failure-pr-comments.png)
117139

118-
## Badging your repository
140+
## Badging Your Repository
119141

120-
You can add a badge to your repository to show your contributors / users that you use commit-check!
142+
You can add a badge to your repository to show your contributors/users that you use commit-check!
121143

122144
[![Commit Check](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml/badge.svg)](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml)
123145

@@ -140,6 +162,6 @@ reStructuredText
140162
141163
Versioning follows [Semantic Versioning](https://semver.org/).
142164
143-
## Have question or feedback?
165+
## Have questions or feedback?
144166
145167
To provide feedback (requesting a feature or reporting a bug) please post to [issues](https://github.com/commit-check/commit-check/issues).

action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ inputs:
2525
description: check committer commit signature
2626
required: false
2727
default: true
28+
merge-base:
29+
description: check current branch is rebased onto target branch
30+
required: false
31+
default: false
2832
dry-run:
2933
description: run checks without failing
3034
required: false
@@ -36,7 +40,7 @@ inputs:
3640
pr-comments:
3741
description: post results to the pull request comments
3842
required: false
39-
default: true
43+
default: false
4044
runs:
4145
using: "composite"
4246
steps:
@@ -64,6 +68,7 @@ runs:
6468
AUTHOR_NAME: ${{ inputs.author-name }}
6569
AUTHOR_EMAIL: ${{ inputs.author-email }}
6670
COMMIT_SIGNOFF: ${{ inputs.commit-signoff }}
71+
MERGE_BASE: ${{ inputs.merge-base }}
6772
DRY_RUN: ${{ inputs.dry-run }}
6873
JOB_SUMMARY: ${{ inputs.job-summary }}
6974
PR_COMMENTS: ${{ inputs.pr-comments }}

main.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import subprocess
55
import re
6-
from github import Github
6+
from github import Github # type: ignore
77

88

99
# Constants for message titles
@@ -16,6 +16,7 @@
1616
AUTHOR_NAME = os.getenv("AUTHOR_NAME", "false")
1717
AUTHOR_EMAIL = os.getenv("AUTHOR_EMAIL", "false")
1818
COMMIT_SIGNOFF = os.getenv("COMMIT_SIGNOFF", "false")
19+
MERGE_BASE = os.getenv("MERGE_BASE", "false")
1920
DRY_RUN = os.getenv("DRY_RUN", "false")
2021
JOB_SUMMARY = os.getenv("JOB_SUMMARY", "false")
2122
PR_COMMENTS = os.getenv("PR_COMMENTS", "false")
@@ -32,6 +33,7 @@ def log_env_vars():
3233
print(f"AUTHOR_NAME = {AUTHOR_NAME}")
3334
print(f"AUTHOR_EMAIL = {AUTHOR_EMAIL}")
3435
print(f"COMMIT_SIGNOFF = {COMMIT_SIGNOFF}")
36+
print(f"MERGE_BASE = {MERGE_BASE}")
3537
print(f"DRY_RUN = {DRY_RUN}")
3638
print(f"JOB_SUMMARY = {JOB_SUMMARY}")
3739
print(f"PR_COMMENTS = {PR_COMMENTS}\n")
@@ -45,11 +47,13 @@ def run_commit_check() -> int:
4547
"--author-name",
4648
"--author-email",
4749
"--commit-signoff",
50+
"--merge-base",
4851
]
4952
args = [
5053
arg
5154
for arg, value in zip(
52-
args, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF]
55+
args,
56+
[MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF, MERGE_BASE],
5357
)
5458
if value == "true"
5559
]
@@ -101,7 +105,12 @@ def add_pr_comments() -> int:
101105
try:
102106
token = os.getenv("GITHUB_TOKEN")
103107
repo_name = os.getenv("GITHUB_REPOSITORY")
104-
pr_number = os.getenv("GITHUB_REF").split("/")[-2]
108+
pr_number = os.getenv("GITHUB_REF")
109+
if pr_number is not None:
110+
pr_number = pr_number.split("/")[-2]
111+
else:
112+
# Handle the case where GITHUB_REF is not set
113+
raise ValueError("GITHUB_REF environment variable is not set")
105114

106115
# Initialize GitHub client
107116
g = Github(token)
@@ -154,6 +163,23 @@ def add_pr_comments() -> int:
154163
return 1
155164

156165

166+
def log_error_and_exit(
167+
failure_title: str, result_text: str | None, ret_code: int
168+
) -> None:
169+
"""
170+
Logs an error message to GitHub Actions and exits with the specified return code.
171+
172+
Args:
173+
failure_title (str): The title of the failure message.
174+
result_text (str): The detailed result text to include in the error message.
175+
ret_code (int): The return code to exit with.
176+
"""
177+
if result_text:
178+
error_message = f"{failure_title}\n```\n{result_text}\n```"
179+
print(f"::error::{error_message}")
180+
sys.exit(ret_code)
181+
182+
157183
def main():
158184
"""Main function to run commit-check, add job summary and post PR comments."""
159185
log_env_vars()
@@ -166,7 +192,8 @@ def main():
166192
if DRY_RUN == "true":
167193
ret_code = 0
168194

169-
sys.exit(ret_code)
195+
result_text = read_result_file()
196+
log_error_and_exit(FAILURE_TITLE, result_text, ret_code)
170197

171198

172199
if __name__ == "__main__":

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Install commit-check CLI
22
# For details please see: https://github.com/commit-check/commit-check
3-
commit-check==0.8.5
3+
commit-check==0.9.2
44
# Interact with the GitHub API.
5-
PyGithub==2.4.0
5+
PyGithub==2.5.0

0 commit comments

Comments
 (0)