Skip to content

feat: add main.py and remove entrypoint.sh #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2024
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
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ runs:
python3 -m pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
- name: Run commit-check
shell: bash
run: ${{ github.action_path }}/entrypoint.sh
run: python3 ${{ github.action_path }}/main.py
env:
MESSAGE: ${{ inputs.message }}
BRANCH: ${{ inputs.branch }}
Expand Down
56 changes: 0 additions & 56 deletions entrypoint.sh

This file was deleted.

61 changes: 61 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
import re


def run_commit_check() -> int:
args = ["--message", "--branch", "--author-name", "--author-email", "--commit-signoff"]
args = [arg for arg, value in zip(args, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF]) 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 add_job_summary() -> int:
if JOB_SUMMARY == "false":
sys.exit()

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

with open(GITHUB_STEP_SUMMARY, "a") as summary_file:
summary_file.write("### Commit-Check ❌\n```\n")
summary_file.write(result_text)
summary_file.write("```")
return 1
else:
with open(GITHUB_STEP_SUMMARY, "a") as summary_file:
summary_file.write("### Commit-Check ✔️\n")
return 0


MESSAGE = os.getenv("MESSAGE", "false")
BRANCH = os.getenv("BRANCH", "false")
AUTHOR_NAME = os.getenv("AUTHOR_NAME", "false")
AUTHOR_EMAIL = os.getenv("AUTHOR_EMAIL", "false")
COMMIT_SIGNOFF = os.getenv("COMMIT_SIGNOFF", "false")
DRY_RUN = os.getenv("DRY_RUN", "false")
JOB_SUMMARY = os.getenv("JOB_SUMMARY", "false")
GITHUB_STEP_SUMMARY = os.environ["GITHUB_STEP_SUMMARY"]

print(f"MESSAGE = {MESSAGE}")
print(f"BRANCH = {BRANCH}")
print(f"AUTHOR_NAME = {AUTHOR_NAME}")
print(f"AUTHOR_EMAIL = {AUTHOR_EMAIL}")
print(f"COMMIT_SIGNOFF = {COMMIT_SIGNOFF}")
print(f"DRY_RUN = {DRY_RUN}")
print(f"JOB_SUMMARY = {JOB_SUMMARY}\n")

ret_code = run_commit_check()
ret_code += add_job_summary() # Combine return codes

if DRY_RUN == "true":
ret_code = 0

sys.exit(ret_code)