Skip to content
Closed
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
19 changes: 18 additions & 1 deletion .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Commit Check

on:
pull_request:
branches: 'main'
branches: [ 'main' ]
workflow_dispatch:

jobs:
Expand All @@ -17,6 +17,7 @@ jobs:
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
id: commit-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
with:
Expand All @@ -29,3 +30,19 @@ jobs:
imperative: true
job-summary: true
pr-comments: ${{ github.event_name == 'pull_request' }}

- name: Save PR comments to pr-comments.txt
run: echo "${{ steps.commit-check.outputs.pr_comments }}" > pr-comments.txt

- name: Post PR comments
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const content = fs.readFileSync('pr-comments.txt', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: content
});
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
venv/
.venv/
__pycache__/
*.pyc
*.pyo
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ inputs:
description: post results to the pull request comments
required: false
default: false

outputs:
pr_comments:
description: The formatted PR comment body containing commit-check results
value: ${{ steps.commit-check.outputs.pr_comments }}

runs:
using: "composite"
steps:
- name: Install dependencies and run commit-check
- id: commit-check
name: Install dependencies and run commit-check
shell: bash
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
Expand Down
17 changes: 17 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ def add_job_summary() -> int:
return 0 if result_text is None else 1


def set_pr_comments_output() -> None:
"""Sets the pr_comments output regardless of PR_COMMENTS setting."""
result_text = read_result_file()
pr_comments = (
SUCCESS_TITLE
if result_text is None
else f"{FAILURE_TITLE}\n```\n{result_text}\n```"
)

# output pr_comments to $GITHUB_OUTPUT
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output_file:
output_file.write(f"pr_comments={pr_comments}\n")


def add_pr_comments() -> int:
"""Posts the commit check result as a comment on the pull request."""
if PR_COMMENTS == "false":
Expand Down Expand Up @@ -200,6 +214,9 @@ def main():
ret_code += add_job_summary()
ret_code += add_pr_comments()

# Always set pr_comments output regardless of PR_COMMENTS setting
set_pr_comments_output()

if DRY_RUN == "true":
ret_code = 0

Expand Down