diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index f62c734..4ef0eb3 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -8,8 +8,11 @@ on: jobs: commit-check: - runs-on: ubuntu-latest - permissions: # use permissions because of use pr-comments + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + permissions: contents: read pull-requests: write steps: @@ -23,5 +26,6 @@ jobs: author-name: true author-email: true job-summary: true - pr-comments: ${{ github.event_name == 'pull_request' }} + # Only post PR comments from the ubuntu job to avoid duplicates + pr-comments: ${{ github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' }} pr-title: true diff --git a/README.md b/README.md index ddfa6a6..cbde04e 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ jobs: pr-comments: ${{ github.event_name == 'pull_request' }} ``` +> [!NOTE] +> This action supports running on Linux, macOS, and Windows (`ubuntu-latest`, `macos-latest`, `windows-latest`). + ## Used By

diff --git a/action.yml b/action.yml index 5fa3bce..0018a52 100644 --- a/action.yml +++ b/action.yml @@ -43,17 +43,25 @@ runs: - name: Install dependencies and run commit-check shell: bash run: | - if [[ "$RUNNER_OS" == "Linux" ]]; then - # https://github.com/pypa/setuptools/issues/3269 - export DEB_PYTHON_INSTALL_LAYOUT=deb + # Platform-specific settings + if [[ "$RUNNER_OS" == "Windows" ]]; then + PYTHON_CMD="python" + VENV_ACTIVATE="venv/Scripts/activate" + else + if [[ "$RUNNER_OS" == "Linux" ]]; then + # https://github.com/pypa/setuptools/issues/3269 + export DEB_PYTHON_INSTALL_LAYOUT=deb + fi + PYTHON_CMD="python3" + VENV_ACTIVATE="venv/bin/activate" fi # Set up virtual environment - python3 -m venv venv - source venv/bin/activate + $PYTHON_CMD -m venv venv + source "$VENV_ACTIVATE" # Download artifact - python3 -m pip download -r "$GITHUB_ACTION_PATH/requirements.txt" + $PYTHON_CMD -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 @@ -62,9 +70,9 @@ runs: fi # Install artifact - python3 -m pip install commit_check-*.whl pygithub-*.whl + $PYTHON_CMD -m pip install commit_check-*.whl pygithub-*.whl - python3 "$GITHUB_ACTION_PATH/main.py" + $PYTHON_CMD "$GITHUB_ACTION_PATH/main.py" env: MESSAGE: ${{ inputs.message }} BRANCH: ${{ inputs.branch }} diff --git a/commit-check.toml b/commit-check.toml index 5eec90c..dc3b366 100644 --- a/commit-check.toml +++ b/commit-check.toml @@ -3,7 +3,7 @@ conventional_commits = true subject_capitalized = false subject_imperative = true -subject_max_length = 80 +subject_max_length = 100 subject_min_length = 5 allow_commit_types = ["feat", "fix", "docs", "style", "refactor", "test", "chore", "ci"] allow_merge_commits = true diff --git a/main.py b/main.py index b61241e..9bb2187 100755 --- a/main.py +++ b/main.py @@ -72,7 +72,7 @@ def get_pr_title() -> str | None: if not event_path: return None try: - with open(event_path, "r") as f: + with open(event_path, "r", encoding="utf-8") as f: event = json.load(f) return event.get("pull_request", {}).get("title") except Exception as e: @@ -165,6 +165,7 @@ def run_check_command( stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, + encoding="utf-8", check=False, ) if result.stdout: @@ -247,7 +248,7 @@ def run_commit_check() -> int: exit_code = 0 emitted_failure_output = False - with open("result.txt", "w") as result_file: + with open("result.txt", "w", encoding="utf-8") as result_file: # ---- 1. PR title check ------------------------------------------------ if PR_TITLE_ENABLED and is_pr_event(): pr_title = get_pr_title() @@ -286,7 +287,7 @@ def run_commit_check() -> int: 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: + with open("result.txt", "r", encoding="utf-8") as result_file: result_text = re.sub( r"\x1B\[[0-9;]*[a-zA-Z]", "", result_file.read() ) # Remove ANSI colors @@ -308,7 +309,7 @@ def add_job_summary() -> int: result_text = read_result_file() - with open(GITHUB_STEP_SUMMARY, "a") as summary_file: + with open(GITHUB_STEP_SUMMARY, "a", encoding="utf-8") as summary_file: summary_file.write(build_result_body(result_text)) return 0 if result_text is None else 1 @@ -320,7 +321,7 @@ def is_fork_pr() -> bool: if not event_path: return False try: - with open(event_path, "r") as f: + with open(event_path, "r", encoding="utf-8") as f: event = json.load(f) pr = event.get("pull_request", {}) head_full_name = pr.get("head", {}).get("repo", {}).get("full_name", "") @@ -357,7 +358,7 @@ def get_pr_number() -> int: event_path = os.getenv("GITHUB_EVENT_PATH") if event_path: try: - with open(event_path, "r") as f: + with open(event_path, "r", encoding="utf-8") as f: event = json.load(f) number = event.get("number") or (event.get("pull_request", {}) or {}).get( "number" @@ -389,7 +390,7 @@ def add_pr_comments() -> int: ) print(f"::warning::{msg}") if JOB_SUMMARY_ENABLED: - with open(GITHUB_STEP_SUMMARY, "a") as f: + with open(GITHUB_STEP_SUMMARY, "a", encoding="utf-8") as f: f.write( "\n---\n" "### \u2139\ufe0f PR Comment Skipped\n\n"