diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 0000000..37cffb1
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1 @@
+* @commit-check/developers
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
deleted file mode 100644
index a091a5d..0000000
--- a/.github/FUNDING.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-# These are supported funding model platforms
-ko_fi: shenxianpeng
-# custom: ["https://www.paypal.me/shenxianpeng"]
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 95bb02f..0a723ca 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -5,10 +5,6 @@
version: 2
updates:
- - package-ecosystem: docker
- directory: /
- schedule:
- interval: "weekly"
- package-ecosystem: github-actions
directory: /
schedule:
@@ -16,4 +12,4 @@ updates:
- package-ecosystem: pip
directory: /
schedule:
- interval: "weekly"
+ interval: "daily"
diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml
new file mode 100644
index 0000000..0d0b1c9
--- /dev/null
+++ b/.github/release-drafter.yml
@@ -0,0 +1 @@
+_extends: .github
diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml
new file mode 100644
index 0000000..d9faf0e
--- /dev/null
+++ b/.github/workflows/commit-check.yml
@@ -0,0 +1,27 @@
+name: Commit Check
+
+on:
+ pull_request:
+ branches: 'main'
+ workflow_dispatch:
+
+jobs:
+ commit-check:
+ runs-on: ubuntu-latest
+ permissions: # use permissions because of use pr-comments
+ contents: read
+ pull-requests: write
+ steps:
+ - uses: actions/checkout@v6
+ with:
+ fetch-depth: 0 # Required for merge-base checks
+ - uses: ./ # self test
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for PR comments
+ with:
+ message: true
+ branch: true
+ author-name: true
+ author-email: true
+ job-summary: true
+ pr-comments: ${{ github.event_name == 'pull_request' }}
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
deleted file mode 100644
index 0ad072d..0000000
--- a/.github/workflows/main.yaml
+++ /dev/null
@@ -1,56 +0,0 @@
-name: main
-
-on:
- release:
- branches: [main]
- types: [published]
- workflow_dispatch:
- inputs:
- tag:
- description: 'which tag to update to'
- default: 'v1'
- required: true
- ref:
- description: 'which branch to update the tag on'
- default: 'main'
- required: true
-
-jobs:
- re-tag:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
- with:
- fetch-depth: 0
- ref: ${{ inputs.ref }}
- - name: Config git name and email
- run: |
- git config user.name 'github-actions'
- git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- - name: Update tag with parameter
- if: github.event.inputs.tag != ''
- run: |
- git tag --delete ${{ inputs.tag }} || true
- git push --delete origin ${{ inputs.tag }} || true
- git tag -a ${{ inputs.tag }} -m 'Retag ${{ inputs.tag }}'
- git push origin ${{ inputs.tag }}
- - name: Update tag to v1
- if: github.event.inputs.tag == ''
- run: |
- git tag --delete v1 || true
- git push --delete origin v1 || true
- git tag -a v1 -m 'Retag v1'
- git push origin v1
-
- commit-check:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
- - uses: commit-check/commit-check-action@v1
- id: check
- with:
- message: true
- branch: true
- author-name: true
- author-email: true
- dry-run: true
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
new file mode 100644
index 0000000..83151fa
--- /dev/null
+++ b/.github/workflows/pre-commit.yml
@@ -0,0 +1,12 @@
+name: Run pre-commit
+permissions:
+ contents: read
+
+on:
+ push:
+ pull_request:
+ types: opened
+
+jobs:
+ pre-commit:
+ uses: commit-check/.github/.github/workflows/pre-commit.yml@main
diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml
new file mode 100644
index 0000000..d25c13e
--- /dev/null
+++ b/.github/workflows/release-drafter.yml
@@ -0,0 +1,11 @@
+name: Release Drafter
+
+on:
+ push:
+ branches:
+ - "main"
+ workflow_dispatch:
+
+jobs:
+ draft-release:
+ uses: commit-check/.github/.github/workflows/release-drafter.yml@main
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
index 0000000..2e6068d
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,47 @@
+name: Release
+permissions:
+ contents: write
+
+on:
+ release:
+ branches: [main]
+ types: [released]
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: 'which tag to update to'
+ default: 'v2'
+ required: true
+ ref:
+ description: 'which branch to update the tag on'
+ default: 'main'
+ required: true
+
+jobs:
+ re-tag:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+ with:
+ fetch-depth: 0
+ ref: ${{ inputs.ref }}
+ - name: Config git name and email
+ run: |
+ git config user.name 'github-actions'
+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
+ - name: Update tag with parameter
+ if: github.event.inputs.tag != ''
+ env:
+ TAG: ${{ inputs.tag }}
+ run: |
+ git tag --delete "$TAG" || true
+ git push --delete origin "$TAG" || true
+ git tag -a "$TAG" -m "Retag $TAG"
+ git push origin "$TAG"
+ - name: Update tag to v2
+ if: github.event.inputs.tag == ''
+ run: |
+ git tag --delete v2 || true
+ git push --delete origin v2 || true
+ git tag -a v2 -m 'Retag v2'
+ git push origin v2
diff --git a/.github/workflows/used-by.yml b/.github/workflows/used-by.yml
new file mode 100644
index 0000000..e1aa9de
--- /dev/null
+++ b/.github/workflows/used-by.yml
@@ -0,0 +1,31 @@
+name: Used By
+
+on:
+ schedule:
+ # https://crontab.guru/
+ - cron: '0 9 * * 1' # At 09:00 on Monday.
+ workflow_dispatch:
+
+permissions:
+ pull-requests: write
+ contents: write
+
+jobs:
+ used-by:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+ - uses: shenxianpeng/used-by@v0.1.4
+ with:
+ repo: '${{ github.repository }}'
+ update-badge: 'true'
+
+ - name: Create Pull Request
+ uses: peter-evans/create-pull-request@v7
+ with:
+ add-paths: "README.md" # the file path to commit
+ commit-message: "chore: update used-by badge by github-actions[bot]"
+ title: "chore: automatically update used-by badge"
+ base: main
+ labels: skip-changelog
+ delete-branch: true
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..43f4b6f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+venv/
+.venv/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..571d5ee
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,27 @@
+# https://pre-commit.com/
+ci:
+ autofix_commit_msg: 'ci: auto fixes from pre-commit.com hooks'
+ autoupdate_commit_msg: 'ci: pre-commit autoupdate'
+
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v5.0.0
+ hooks:
+ - id: check-yaml
+ - id: check-toml
+ - id: end-of-file-fixer
+ - id: trailing-whitespace
+ - id: name-tests-test
+ - id: requirements-txt-fixer
+- repo: https://github.com/psf/black-pre-commit-mirror
+ rev: 24.10.0
+ hooks:
+ - id: black
+- repo: https://github.com/pre-commit/mirrors-mypy
+ rev: v1.12.0
+ hooks:
+ - id: mypy
+- repo: https://github.com/codespell-project/codespell
+ rev: v2.3.0
+ hooks:
+ - id: codespell
diff --git a/LICENSE b/LICENSE
index 075dbce..149b4e3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2022 Commit Check
+Copyright (c) 2023 shenxianpeng (xianpeng.shen@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 3b9414d..3924cab 100644
--- a/README.md
+++ b/README.md
@@ -1,43 +1,181 @@
# Commit-Check GitHub Action
-
-[](https://github.com/marketplace/actions/commit-check)
-
-A Github Action for checking commit message formatting, branch naming, referencing Jira tickets, and more.
+[](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml)
+
+[](https://github.com/commit-check/commit-check-action/network/dependents)
+[](https://github.com/marketplace/actions/commit-check-action)
+[](https://github.com/commit-check/commit-check-action/blob/a2873ca0482dd505c93fb51861c953e82fd0a186/action.yml#L59-L69)
+
+A GitHub Action for checking commit message formatting, branch naming, committer name, email, commit signoff, and more.
+
+## What's New in v2
+
+> [!IMPORTANT]
+> This v2 release introduces several 🚨**breaking changes**. Please review the [Breaking Changes](#breaking-changes) section carefully before upgrading.
+
+### Breaking Changes
+
+- Removed support for `commit-signoff`, `merge-base`, and `imperative` inputs — now configured via `commit-check.toml` or `cchk.toml`.
+- Deprecated `.commit-check.yml` in favor of `commit-check.toml` or `cchk.toml`.
+- Changed default values of `author-name` and `author-email` inputs to `false` to align with the default behavior in commit-check.
+- Upgraded core dependency [`commit-check`](https://github.com/commit-check/commit-check) to [**v2.0.0**](https://github.com/commit-check/commit-check/releases/tag/v2.0.0).
+
+## Table of Contents
+
+* [Usage](#usage)
+* [Optional Inputs](#optional-inputs)
+* [GitHub Action Job Summary](#github-action-job-summary)
+* [GitHub Pull Request Comments](#github-pull-request-comments)
+* [Badging Your Repository](#badging-your-repository)
+* [Versioning](#versioning)
+
+## Usage
+
+Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows/commit-check.yml](.github/workflows/commit-check.yml)
+
+```yaml
+name: Commit Check
+
+on:
+ push:
+ pull_request:
+ branches: 'main'
+
+jobs:
+ commit-check:
+ runs-on: ubuntu-latest
+ permissions: # use permissions because use of pr-comments
+ contents: read
+ pull-requests: write
+ steps:
+ - uses: actions/checkout@v5
+ with:
+ fetch-depth: 0 # Required for merge-base checks
+ - uses: commit-check/commit-check-action@v2
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for PR comments
+ with:
+ message: true
+ branch: true
+ author-name: false
+ author-email: false
+ job-summary: true
+ pr-comments: ${{ github.event_name == 'pull_request' }}
+```
+
+## Used By
+
+
+
+ Apache
+
+ discovery-unicamp
+
+ Texas Instruments
+
+ OpenCADC
+
+ Extrawest
+
+ Chainlift
+
+ Mila
+
+ RLinf
+ and many more.
+
## Optional Inputs
### `message`
-- **Description**: check commit message formatting convention
- - By default the rule follows [conventionalcommits](https://www.conventionalcommits.org/)
-- Default: 'true'
+- **Description**: check git commit message following [Conventional Commits](https://www.conventionalcommits.org/).
+- Default: `true`
### `branch`
-- **Description**: check git branch naming convention
- - By default follow bitbucket [branching model](https://support.atlassian.com/bitbucket-cloud/docs/configure-a-projects-branching-model/)
-- Default: 'true'
+- **Description**: check git branch name following [Conventional Branch](https://conventional-branch.github.io/).
+- Default: `true`
### `author-name`
-- **Description**: check committer author name
-- Default: 'true'
+- **Description**: check committer author name.
+- Default: `false`
### `author-email`
-- **Description**: check committer author email
-- Default: 'true'
+- **Description**: check committer author email.
+- Default: `false`
### `dry-run`
-- **Description**: run checks without failing
-- Default: 'false'
+- **Description**: run checks without failing. exit code is 0; otherwise is 1.
+- Default: `false`
+
+### `job-summary`
+
+- **Description**: display job summary to the workflow run.
+- Default: `true`
+
+### `pr-comments`
+
+- **Description**: post results to the pull request comments.
+- Default: `false`
+
+> [!IMPORTANT]
+> `pr-comments` is an experimental feature. By default, it's disabled. 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).
+
+Note: the default rule of above inputs is following [this configuration](https://github.com/commit-check/commit-check-action/blob/main/commit-check.toml). If you want to customize, just add your [`commit-check.toml`](https://commit-check.github.io/commit-check/configuration.html) config file under your repository root directory.
+
+## GitHub Action Job Summary
+
+By default, commit-check-action results are shown on the job summary page of the workflow.
+
+### Success Job Summary
+
+
+
+### Failure Job Summary
+
+
+
+## GitHub Pull Request Comments
+
+### Success Pull Request Comment
+
+
+
+### Failure Pull Request Comment
+
+
+
+## Badging Your Repository
+
+You can add a badge to your repository to show your contributors/users that you use commit-check!
+
+[](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml)
+
+Markdown
+
+```
+[](https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml)
+```
+
+reStructuredText
+
+```
+.. image:: https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml/badge.svg
+ :target: https://github.com/commit-check/commit-check-action/actions/workflows/commit-check.yml
+ :alt: Commit Check
+```
-Note: to change the default rules of above inputs, just add your own [`.commit-check.yml`](https://github.com/commit-check/commit-check#usage) config file.
## Versioning
Versioning follows [Semantic Versioning](https://semver.org/).
-[](https://ko-fi.com/H2H85WC9L)
+## Have questions or feedback?
+
+To provide feedback (requesting a feature or reporting a bug), please post to [issues](https://github.com/commit-check/commit-check/issues).
diff --git a/action.yml b/action.yml
index 7552d81..68df492 100644
--- a/action.yml
+++ b/action.yml
@@ -1,59 +1,71 @@
-name: commit-check-action
-description: Check commit message formatting, branch naming, referencing Jira tickets, and more
+name: Commit Check Action
+description: Check commit message formatting, branch naming, committer name, email, and more
author: shenxianpeng
branding:
icon: "git-commit"
color: "blue"
inputs:
message:
- description: check commit message formatting convention
+ description: check git commit message following conventional commits
required: false
default: true
branch:
- description: check git branch naming convention
+ description: check git branch name following conventional branch
required: false
default: true
author-name:
description: check committer author name
required: false
- default: true
+ default: false
author-email:
description: check committer author email
required: false
- default: true
+ default: false
dry-run:
description: run checks without failing
required: false
default: false
+ job-summary:
+ description: display job summary to the workflow run
+ required: false
+ default: true
+ pr-comments:
+ description: post results to the pull request comments
+ required: false
+ default: false
runs:
using: "composite"
steps:
- - name: Install action dependencies
+ - name: Install dependencies and run commit-check
shell: bash
run: |
- if [[ "${{runner.os}}" == "Linux" ]]; then
+ if [[ "$RUNNER_OS" == "Linux" ]]; then
# https://github.com/pypa/setuptools/issues/3269
export DEB_PYTHON_INSTALL_LAYOUT=deb
fi
- python3 -m pip install -r '${{ github.action_path }}/requirements.txt'
- - name: Run commit-check
- id: commit-check
- shell: bash
- run: |
- args=""
- if [ "${{ inputs.message }}" == "true" ]; then
- args="$args --message"
- fi
- if [ "${{ inputs.branch }}" == "true" ]; then
- args="$args --branch"
- fi
- if [ "${{ inputs.author-name }}" == "true" ]; then
- args="$args --author-name"
- fi
- if [ "${{ inputs.author-email }}" == "true" ]; then
- args="$args --author-email"
- fi
- if [ "${{ inputs.dry-run }}" == "true" ]; then
- args="$args --dry-run"
+
+ # Set up virtual environment
+ python3 -m venv venv
+ source venv/bin/activate
+
+ # Download artifact
+ python3 -m pip download -r "$GITHUB_ACTION_PATH/requirements.txt"
+
+ # Verify artifact attestations
+ if ! gh attestation verify commit_check-*.whl -R commit-check/commit-check; then
+ echo "Artifact verification failed. Aborting installation."
+ exit 1
fi
- commit-check $args
+
+ # Install artifact
+ python3 -m pip install commit_check-*.whl pygithub-*.whl
+
+ python3 "$GITHUB_ACTION_PATH/main.py"
+ env:
+ MESSAGE: ${{ inputs.message }}
+ BRANCH: ${{ inputs.branch }}
+ AUTHOR_NAME: ${{ inputs.author-name }}
+ AUTHOR_EMAIL: ${{ inputs.author-email }}
+ DRY_RUN: ${{ inputs.dry-run }}
+ JOB_SUMMARY: ${{ inputs.job-summary }}
+ PR_COMMENTS: ${{ inputs.pr-comments }}
diff --git a/commit-check.toml b/commit-check.toml
new file mode 100644
index 0000000..5eec90c
--- /dev/null
+++ b/commit-check.toml
@@ -0,0 +1,23 @@
+[commit]
+# https://www.conventionalcommits.org
+conventional_commits = true
+subject_capitalized = false
+subject_imperative = true
+subject_max_length = 80
+subject_min_length = 5
+allow_commit_types = ["feat", "fix", "docs", "style", "refactor", "test", "chore", "ci"]
+allow_merge_commits = true
+allow_revert_commits = true
+allow_empty_commits = false
+allow_fixup_commits = true
+allow_wip_commits = false
+require_body = false
+require_signed_off_by = false
+ignore_authors = ["dependabot[bot]", "copilot[bot]", "pre-commit-ci[bot]"]
+
+[branch]
+# https://conventional-branch.github.io/
+conventional_branch = true
+allow_branch_types = ["feature", "bugfix", "hotfix", "release", "chore", "feat", "fix"]
+require_rebase_target = "origin/main"
+ignore_authors = ["dependabot[bot]", "copilot[bot]", "pre-commit-ci[bot]"]
diff --git a/main.py b/main.py
new file mode 100755
index 0000000..2ec7ea5
--- /dev/null
+++ b/main.py
@@ -0,0 +1,202 @@
+#!/usr/bin/env python3
+import os
+import sys
+import subprocess
+import re
+from github import Github, Auth # type: ignore
+
+
+# Constants for message titles
+SUCCESS_TITLE = "# Commit-Check ✔️"
+FAILURE_TITLE = "# Commit-Check ❌"
+
+# Environment variables
+MESSAGE = os.getenv("MESSAGE", "false")
+BRANCH = os.getenv("BRANCH", "false")
+AUTHOR_NAME = os.getenv("AUTHOR_NAME", "false")
+AUTHOR_EMAIL = os.getenv("AUTHOR_EMAIL", "false")
+DRY_RUN = os.getenv("DRY_RUN", "false")
+JOB_SUMMARY = os.getenv("JOB_SUMMARY", "false")
+PR_COMMENTS = os.getenv("PR_COMMENTS", "false")
+GITHUB_STEP_SUMMARY = os.environ["GITHUB_STEP_SUMMARY"]
+GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
+GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY")
+GITHUB_REF = os.getenv("GITHUB_REF")
+
+
+def log_env_vars():
+ """Logs the environment variables for debugging purposes."""
+ print(f"MESSAGE = {MESSAGE}")
+ print(f"BRANCH = {BRANCH}")
+ print(f"AUTHOR_NAME = {AUTHOR_NAME}")
+ print(f"AUTHOR_EMAIL = {AUTHOR_EMAIL}")
+ print(f"DRY_RUN = {DRY_RUN}")
+ print(f"JOB_SUMMARY = {JOB_SUMMARY}")
+ print(f"PR_COMMENTS = {PR_COMMENTS}\n")
+
+
+def run_commit_check() -> int:
+ """Runs the commit-check command and logs the result."""
+ args = [
+ "--message",
+ "--branch",
+ "--author-name",
+ "--author-email",
+ ]
+ args = [
+ arg
+ for arg, value in zip(
+ args,
+ [
+ MESSAGE,
+ BRANCH,
+ AUTHOR_NAME,
+ AUTHOR_EMAIL,
+ ],
+ )
+ if value == "true"
+ ]
+
+ command = ["commit-check"] + args
+ print(" ".join(command))
+ with open("result.txt", "w") as result_file:
+ result = subprocess.run(
+ command, stdout=result_file, stderr=subprocess.PIPE, check=False
+ )
+ return result.returncode
+
+
+def read_result_file() -> str | None:
+ """Reads the result.txt file and removes ANSI color codes."""
+ if os.path.getsize("result.txt") > 0:
+ with open("result.txt", "r") as result_file:
+ result_text = re.sub(
+ r"\x1B\[[0-9;]*[a-zA-Z]", "", result_file.read()
+ ) # Remove ANSI colors
+ return result_text.rstrip()
+ return None
+
+
+def add_job_summary() -> int:
+ """Adds the commit check result to the GitHub job summary."""
+ if JOB_SUMMARY == "false":
+ return 0
+
+ result_text = read_result_file()
+
+ summary_content = (
+ SUCCESS_TITLE
+ if result_text is None
+ else f"{FAILURE_TITLE}\n```\n{result_text}\n```"
+ )
+
+ with open(GITHUB_STEP_SUMMARY, "a") as summary_file:
+ summary_file.write(summary_content)
+
+ return 0 if result_text is None else 1
+
+
+def add_pr_comments() -> int:
+ """Posts the commit check result as a comment on the pull request."""
+ if PR_COMMENTS == "false":
+ return 0
+
+ try:
+ token = os.getenv("GITHUB_TOKEN")
+ repo_name = os.getenv("GITHUB_REPOSITORY")
+ pr_number = os.getenv("GITHUB_REF")
+ if pr_number is not None:
+ pr_number = pr_number.split("/")[-2]
+ else:
+ # Handle the case where GITHUB_REF is not set
+ raise ValueError("GITHUB_REF environment variable is not set")
+
+ # Initialize GitHub client
+ # Use new Auth API to avoid deprecation warning
+ if not token:
+ raise ValueError("GITHUB_TOKEN is not set")
+ g = Github(auth=Auth.Token(token))
+ repo = g.get_repo(repo_name)
+ pull_request = repo.get_issue(int(pr_number))
+
+ # Prepare comment content
+ result_text = read_result_file()
+ pr_comments = (
+ SUCCESS_TITLE
+ if result_text is None
+ else f"{FAILURE_TITLE}\n```\n{result_text}\n```"
+ )
+
+ # Fetch all existing comments on the PR
+ comments = pull_request.get_comments()
+
+ # Track if we found a matching comment
+ matching_comments = []
+ last_comment = None
+
+ for comment in comments:
+ if comment.body.startswith(SUCCESS_TITLE) or comment.body.startswith(
+ FAILURE_TITLE
+ ):
+ matching_comments.append(comment)
+ if matching_comments:
+ last_comment = matching_comments[-1]
+
+ if last_comment.body == pr_comments:
+ print(f"PR comment already up-to-date for PR #{pr_number}.")
+ return 0
+ else:
+ # If the last comment doesn't match, update it
+ print(f"Updating the last comment on PR #{pr_number}.")
+ last_comment.edit(pr_comments)
+
+ # Delete all older matching comments
+ for comment in matching_comments[:-1]:
+ print(f"Deleting an old comment on PR #{pr_number}.")
+ comment.delete()
+ else:
+ # No matching comments, create a new one
+ print(f"Creating a new comment on PR #{pr_number}.")
+ pull_request.create_comment(body=pr_comments)
+
+ return 0 if result_text is None else 1
+ except Exception as e:
+ print(f"Error posting PR comment: {e}", file=sys.stderr)
+ return 1
+
+
+def log_error_and_exit(
+ failure_title: str, result_text: str | None, ret_code: int
+) -> None:
+ """
+ Logs an error message to GitHub Actions and exits with the specified return code.
+
+ Args:
+ failure_title (str): The title of the failure message.
+ result_text (str): The detailed result text to include in the error message.
+ ret_code (int): The return code to exit with.
+ """
+ if result_text:
+ error_message = f"{failure_title}\n```\n{result_text}\n```"
+ print(f"::error::{error_message}")
+ sys.exit(ret_code)
+
+
+def main():
+ """Main function to run commit-check, add job summary and post PR comments."""
+ log_env_vars()
+
+ # Combine return codes
+ ret_code = run_commit_check()
+ ret_code += add_job_summary()
+ ret_code += add_pr_comments()
+
+ if DRY_RUN == "true":
+ ret_code = 0
+
+ result_text = read_result_file()
+ log_error_and_exit(FAILURE_TITLE, result_text, ret_code)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/requirements.txt b/requirements.txt
index a4e5b42..830b52a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,5 @@
# Install commit-check CLI
# For details please see: https://github.com/commit-check/commit-check
-commit-check==0.2.3
+commit-check==2.1.2
+# Interact with the GitHub API.
+PyGithub==2.8.1