Skip to content

feat: support merge-base option #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ checks:
regex: ^.+@.+$
error: The committer email seems invalid
suggest: run command `git config user.email yourname@example.com`

- check: merge_base
regex: main # it can be master, develop, devel etc based on your project.
error: Current branch is not rebased onto target branch
suggest: please ensure your branch is rebased with the target branch
2 changes: 2 additions & 0 deletions .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
fetch-depth: 0 # fetch all history for all branches and tags
- uses: ./ # self test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
Expand All @@ -24,5 +25,6 @@ jobs:
author-name: true
author-email: true
commit-signoff: true
merge-base: true
job-summary: true
pr-comments: ${{ github.event_name == 'pull_request' }}
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
fetch-depth: 0 # required for merge-base check
- uses: commit-check/commit-check-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
Expand All @@ -39,6 +40,7 @@ jobs:
author-name: true
author-email: true
commit-signoff: true
merge-base: false
job-summary: true
pr-comments: ${{ github.event_name == 'pull_request' }}
```
Expand All @@ -59,38 +61,48 @@ jobs:

### `author-name`

- **Description**: check committer author name
- **Description**: check committer author name.
- Default: 'true'

### `author-email`

- **Description**: check committer author email
- **Description**: check committer author email.
- Default: 'true'

### `commit-signoff`

- **Description**: check committer commit signature
- **Description**: check committer commit signature.
- Default: 'true'

### `merge-base`

- **Description**: check current branch is rebased onto target branch.
- Default: 'false'

> [!IMPORTANT]
> `merge-base` is an experimental feature. by default it's disable.
>
> To use this feature, you need fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`.

### `dry-run`

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

### `job-summary`

- **Description**: display job summary to the workflow run
- **Description**: display job summary to the workflow run.
- Default: 'true'

### `pr-comments`

- **Description**: post results to the pull request comments
- **Description**: post results to the pull request comments.
- Default: 'false'

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

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.

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ inputs:
description: check committer commit signature
required: false
default: true
merge-base:
description: check current branch is rebased onto target branch
required: false
default: false
dry-run:
description: run checks without failing
required: false
Expand Down Expand Up @@ -57,6 +61,7 @@ runs:
AUTHOR_NAME: ${{ inputs.author-name }}
AUTHOR_EMAIL: ${{ inputs.author-email }}
COMMIT_SIGNOFF: ${{ inputs.commit-signoff }}
MERGE_BASE: ${{ inputs.merge-base }}
DRY_RUN: ${{ inputs.dry-run }}
JOB_SUMMARY: ${{ inputs.job-summary }}
PR_COMMENTS: ${{ inputs.pr-comments }}
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AUTHOR_NAME = os.getenv("AUTHOR_NAME", "false")
AUTHOR_EMAIL = os.getenv("AUTHOR_EMAIL", "false")
COMMIT_SIGNOFF = os.getenv("COMMIT_SIGNOFF", "false")
MERGE_BASE = os.getenv("MERGE_BASE", "false")
DRY_RUN = os.getenv("DRY_RUN", "false")
JOB_SUMMARY = os.getenv("JOB_SUMMARY", "false")
PR_COMMENTS = os.getenv("PR_COMMENTS", "false")
Expand All @@ -32,6 +33,7 @@ def log_env_vars():
print(f"AUTHOR_NAME = {AUTHOR_NAME}")
print(f"AUTHOR_EMAIL = {AUTHOR_EMAIL}")
print(f"COMMIT_SIGNOFF = {COMMIT_SIGNOFF}")
print(f"MERGE_BASE = {MERGE_BASE}")
print(f"DRY_RUN = {DRY_RUN}")
print(f"JOB_SUMMARY = {JOB_SUMMARY}")
print(f"PR_COMMENTS = {PR_COMMENTS}\n")
Expand All @@ -45,11 +47,12 @@ def run_commit_check() -> int:
"--author-name",
"--author-email",
"--commit-signoff",
"--merge-base",
]
args = [
arg
for arg, value in zip(
args, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF]
args, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF, MERGE_BASE]
)
if value == "true"
]
Expand Down