diff --git a/.commit-check.yml b/.commit-check.yml index 7d5e579..35052d6 100644 --- a/.commit-check.yml +++ b/.commit-check.yml @@ -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 diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index 7ee0be4..dc398fd 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -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 @@ -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' }} diff --git a/README.md b/README.md index e58e79c..a25d56f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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' }} ``` @@ -59,19 +61,29 @@ 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. @@ -79,18 +91,18 @@ jobs: ### `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. diff --git a/action.yml b/action.yml index 531acb4..d23acfc 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }} diff --git a/main.py b/main.py index eb0af9c..91d2246 100755 --- a/main.py +++ b/main.py @@ -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") @@ -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") @@ -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" ]
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: