Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f35ff35

Browse files
feat: add main.py and remove entrypoint.sh (#41)
1 parent e055f14 commit f35ff35

File tree

3 files changed

+62
-57
lines changed

3 files changed

+62
-57
lines changed

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ runs:
4646
python3 -m pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
4747
- name: Run commit-check
4848
shell: bash
49-
run: ${{ github.action_path }}/entrypoint.sh
49+
run: python3 ${{ github.action_path }}/main.py
5050
env:
5151
MESSAGE: ${{ inputs.message }}
5252
BRANCH: ${{ inputs.branch }}

‎entrypoint.sh‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

‎main.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import sys
4+
import subprocess
5+
import re
6+
7+
8+
def run_commit_check() -> int:
9+
args = ["--message", "--branch", "--author-name", "--author-email", "--commit-signoff"]
10+
args = [arg for arg, value in zip(args, [MESSAGE, BRANCH, AUTHOR_NAME, AUTHOR_EMAIL, COMMIT_SIGNOFF]) if value == "true"]
11+
12+
command = ["commit-check"] + args
13+
print(" ".join(command))
14+
with open("result.txt", "w") as result_file:
15+
result = subprocess.run(command, stdout=result_file, stderr=subprocess.PIPE, check=False)
16+
return result.returncode
17+
18+
19+
def add_job_summary() -> int:
20+
if JOB_SUMMARY == "false":
21+
sys.exit()
22+
23+
if os.path.getsize("result.txt") > 0:
24+
with open("result.txt", "r") as result_file:
25+
result_text = re.sub(r'\x1B\[[0-9;]*[a-zA-Z]', '', result_file.read()) # Remove ANSI colors
26+
27+
with open(GITHUB_STEP_SUMMARY, "a") as summary_file:
28+
summary_file.write("### Commit-Check ❌\n```\n")
29+
summary_file.write(result_text)
30+
summary_file.write("```")
31+
return 1
32+
else:
33+
with open(GITHUB_STEP_SUMMARY, "a") as summary_file:
34+
summary_file.write("### Commit-Check ✔️\n")
35+
return 0
36+
37+
38+
MESSAGE = os.getenv("MESSAGE", "false")
39+
BRANCH = os.getenv("BRANCH", "false")
40+
AUTHOR_NAME = os.getenv("AUTHOR_NAME", "false")
41+
AUTHOR_EMAIL = os.getenv("AUTHOR_EMAIL", "false")
42+
COMMIT_SIGNOFF = os.getenv("COMMIT_SIGNOFF", "false")
43+
DRY_RUN = os.getenv("DRY_RUN", "false")
44+
JOB_SUMMARY = os.getenv("JOB_SUMMARY", "false")
45+
GITHUB_STEP_SUMMARY = os.environ["GITHUB_STEP_SUMMARY"]
46+
47+
print(f"MESSAGE = {MESSAGE}")
48+
print(f"BRANCH = {BRANCH}")
49+
print(f"AUTHOR_NAME = {AUTHOR_NAME}")
50+
print(f"AUTHOR_EMAIL = {AUTHOR_EMAIL}")
51+
print(f"COMMIT_SIGNOFF = {COMMIT_SIGNOFF}")
52+
print(f"DRY_RUN = {DRY_RUN}")
53+
print(f"JOB_SUMMARY = {JOB_SUMMARY}\n")
54+
55+
ret_code = run_commit_check()
56+
ret_code += add_job_summary() # Combine return codes
57+
58+
if DRY_RUN == "true":
59+
ret_code = 0
60+
61+
sys.exit(ret_code)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /