Skip to content
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
10 changes: 7 additions & 3 deletions .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<p align="center">
Expand Down
24 changes: 16 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion commit-check.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -165,6 +165,7 @@ def run_check_command(
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
check=False,
)
if result.stdout:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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", "")
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading