Skip to content

Commit 8d507e1

Browse files
authored
feat: support merge-base input (#86)
* feat: add a empty commit to main for testing * feat: support merge-base option #85 * test: update commit-check.yml to debug * test: checkout all branches and tags * feat: add a empty commit to main for testing * docs: update readme * test: update merge_base regex * fix: update .commit-check.yml * docs: update README.md
1 parent cedb118 commit 8d507e1

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
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' }}

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- uses: actions/checkout@v4
3131
with:
3232
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
33+
fetch-depth: 0 # required for merge-base check
3334
- uses: commit-check/commit-check-action@v1
3435
env:
3536
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
@@ -39,6 +40,7 @@ jobs:
3940
author-name: true
4041
author-email: true
4142
commit-signoff: true
43+
merge-base: false
4244
job-summary: true
4345
pr-comments: ${{ github.event_name == 'pull_request' }}
4446
```
@@ -59,38 +61,48 @@ jobs:
5961

6062
### `author-name`
6163

62-
- **Description**: check committer author name
64+
- **Description**: check committer author name.
6365
- Default: 'true'
6466

6567
### `author-email`
6668

67-
- **Description**: check committer author email
69+
- **Description**: check committer author email.
6870
- Default: 'true'
6971

7072
### `commit-signoff`
7173

72-
- **Description**: check committer commit signature
74+
- **Description**: check committer commit signature.
7375
- Default: 'true'
7476

77+
### `merge-base`
78+
79+
- **Description**: check current branch is rebased onto target branch.
80+
- Default: 'false'
81+
82+
> [!IMPORTANT]
83+
> `merge-base` is an experimental feature. by default it's disable.
84+
>
85+
> To use this feature, you need fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`.
86+
7587
### `dry-run`
7688

7789
- **Description**: run checks without failing. exit code is 0 otherwise is 1.
7890
- Default: 'false'
7991

8092
### `job-summary`
8193

82-
- **Description**: display job summary to the workflow run
94+
- **Description**: display job summary to the workflow run.
8395
- Default: 'true'
8496

8597
### `pr-comments`
8698

87-
- **Description**: post results to the pull request comments
99+
- **Description**: post results to the pull request comments.
88100
- Default: 'false'
89101

90102
> [!IMPORTANT]
91-
> `pr-comments` is an experimental feature. To use it you need to set `GITHUB_TOKEN` in the GitHub Action.
103+
> `pr-comments` is an experimental feature. by default it's disable. To use it you need to set `GITHUB_TOKEN` in the GitHub Action.
92104
>
93-
> 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)
105+
> 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).
94106

95107
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.
96108

action.yml

Lines changed: 5 additions & 0 deletions
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
@@ -57,6 +61,7 @@ runs:
5761
AUTHOR_NAME: ${{ inputs.author-name }}
5862
AUTHOR_EMAIL: ${{ inputs.author-email }}
5963
COMMIT_SIGNOFF: ${{ inputs.commit-signoff }}
64+
MERGE_BASE: ${{ inputs.merge-base }}
6065
DRY_RUN: ${{ inputs.dry-run }}
6166
JOB_SUMMARY: ${{ inputs.job-summary }}
6267
PR_COMMENTS: ${{ inputs.pr-comments }}

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,12 @@ 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, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF, MERGE_BASE]
5356
)
5457
if value == "true"
5558
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy