From 7c452c94a2e3224465f3a859b67d72ead0f8a23a Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 15:26:18 +0000 Subject: [PATCH 1/9] feat: add a empty commit to main for testing From 28387a74b0811bdefc39cde2dd34fdb2eb57cbf4 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 15:22:58 +0000 Subject: [PATCH 2/9] feat: support merge-base option #85 --- .commit-check.yml | 5 +++++ .github/workflows/commit-check.yml | 1 + README.md | 23 ++++++++++++++++------- action.yml | 5 +++++ main.py | 5 ++++- 5 files changed, 31 insertions(+), 8 deletions(-) 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..0a25e2b 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -24,5 +24,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..a4d9874 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,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 +60,27 @@ 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. + ### `dry-run` - **Description**: run checks without failing. exit code is 0 otherwise is 1. @@ -79,18 +88,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" ] From d1c0d5b044b40bcc738f07f6ed072c87b8484353 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 15:47:06 +0000 Subject: [PATCH 3/9] test: update commit-check.yml to debug --- .commit-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.commit-check.yml b/.commit-check.yml index 35052d6..7ea95ca 100644 --- a/.commit-check.yml +++ b/.commit-check.yml @@ -25,6 +25,6 @@ checks: 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. + regex: origin/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 From 5b9a78d8b5c1d66b807bed855ee5844255327a1a Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 15:49:57 +0000 Subject: [PATCH 4/9] test: checkout all branches and tags --- .github/workflows/commit-check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index 0a25e2b..182802f 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 # all history for all branches and tags - uses: ./ # self test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments From 97eff796ba4f11c0a4437830cff9e5455e464cf1 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 15:51:44 +0000 Subject: [PATCH 5/9] feat: add a empty commit to main for testing From f53a486d0bfda75c0a79666f73bf2455dd614312 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 15:56:11 +0000 Subject: [PATCH 6/9] docs: update readme --- .commit-check.yml | 2 +- .github/workflows/commit-check.yml | 2 +- README.md | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.commit-check.yml b/.commit-check.yml index 7ea95ca..35052d6 100644 --- a/.commit-check.yml +++ b/.commit-check.yml @@ -25,6 +25,6 @@ checks: suggest: run command `git config user.email yourname@example.com` - check: merge_base - regex: origin/main # it can be master, develop, devel etc based on your project. + 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 182802f..dc398fd 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit - fetch-depth: 0 # all history for all branches and tags + 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 diff --git a/README.md b/README.md index a4d9874..8a3d1fb 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ jobs: > [!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` From 95669421d25fbc4842e6016ecb49b8af99bd2a9c Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 16:01:07 +0000 Subject: [PATCH 7/9] test: update merge_base regex --- .commit-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.commit-check.yml b/.commit-check.yml index 35052d6..7ea95ca 100644 --- a/.commit-check.yml +++ b/.commit-check.yml @@ -25,6 +25,6 @@ checks: 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. + regex: origin/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 From e55fd3c86cb04c69caa7f83b849de095f67415b3 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 20:02:56 +0200 Subject: [PATCH 8/9] fix: update .commit-check.yml --- .commit-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.commit-check.yml b/.commit-check.yml index 7ea95ca..35052d6 100644 --- a/.commit-check.yml +++ b/.commit-check.yml @@ -25,6 +25,6 @@ checks: suggest: run command `git config user.email yourname@example.com` - check: merge_base - regex: origin/main # it can be master, develop, devel etc based on your project. + 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 From 1596adc0e2ce96c851d0d20f07d60cbc793d825d Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 12 Nov 2024 20:33:35 +0200 Subject: [PATCH 9/9] docs: update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8a3d1fb..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