Skip to content

Commit 42c1fa3

Browse files
authored
feat: add job summary (#8)
1 parent 20b5a92 commit 42c1fa3

File tree

4 files changed

+93
-38
lines changed

4 files changed

+93
-38
lines changed

.github/workflows/commit-check.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Commit Check
22

33
on:
44
push:
5-
branches: 'main'
65
pull_request:
76
branches: 'main'
87

@@ -17,4 +16,4 @@ jobs:
1716
branch: true
1817
author-name: true
1918
author-email: true
20-
dry-run: true
19+
summary: true

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows
1212
```yaml
1313
name: Commit Check
1414

15-
on: pull_request
15+
on:
16+
push:
17+
pull_request:
18+
branches: 'main'
1619

1720
jobs:
1821
commit-check:
@@ -26,20 +29,21 @@ jobs:
2629
author-name: true
2730
author-email: true
2831
dry-run: true
32+
summary: true
2933
```
3034
3135
## Optional Inputs
3236
3337
### `message`
3438

35-
- **Description**: check commit message formatting convention
36-
- By default the rule follows [conventionalcommits](https://www.conventionalcommits.org/)
39+
- **Description**: check commit message formatting convention.
40+
- By default the rule follows [conventionalcommits](https://www.conventionalcommits.org/).
3741
- Default: 'true'
3842

3943
### `branch`
4044

41-
- **Description**: check git branch naming convention
42-
- By default follow bitbucket [branching model](https://support.atlassian.com/bitbucket-cloud/docs/configure-a-projects-branching-model/)
45+
- **Description**: check git branch naming convention.
46+
- By default follow bitbucket [branching model](https://support.atlassian.com/bitbucket-cloud/docs/configure-a-projects-branching-model/).
4347
- Default: 'true'
4448

4549
### `author-name`
@@ -54,10 +58,15 @@ jobs:
5458

5559
### `dry-run`
5660

57-
- **Description**: run checks without failing
61+
- **Description**: run checks without failing. exit code is 0 otherwise is 1.
5862
- Default: 'false'
5963

60-
Note: to change the default rules of above inputs, just add your own [`.commit-check.yml`](.commit-check.yml) config file.
64+
### `summary`
65+
66+
- **Description**: display job summary to a workflow run
67+
- Default: 'true'
68+
69+
Note: the default rule of above inputs is following [this configuration](https://github.com/commit-check/commit-check/blob/main/.commit-check.yml), if you want to customize just add your `.commit-check.yml` config file under your repository root directory.
6170

6271
## Badging your repository
6372

action.yml

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Commit Check Action
2-
description: Check commit message formatting, branch naming, referencing Jira tickets, and more
2+
description: Check commit message formatting, branch naming, committer name, email, and more
33
author: shenxianpeng
44
branding:
55
icon: "git-commit"
@@ -25,35 +25,19 @@ inputs:
2525
description: run checks without failing
2626
required: false
2727
default: false
28+
summary:
29+
description: add a job summary
30+
required: false
31+
default: true
2832
runs:
2933
using: "composite"
3034
steps:
31-
- name: Install action dependencies
32-
shell: bash
33-
run: |
34-
if [[ "${{runner.os}}" == "Linux" ]]; then
35-
# https://github.com/pypa/setuptools/issues/3269
36-
export DEB_PYTHON_INSTALL_LAYOUT=deb
37-
fi
38-
python3 -m pip install -r '${{ github.action_path }}/requirements.txt'
39-
- name: Run commit-check
40-
id: commit-check
35+
- run: ${{ github.action_path }}/entrypoint
4136
shell: bash
42-
run: |
43-
args=""
44-
if [ "${{ inputs.message }}" == "true" ]; then
45-
args="$args --message"
46-
fi
47-
if [ "${{ inputs.branch }}" == "true" ]; then
48-
args="$args --branch"
49-
fi
50-
if [ "${{ inputs.author-name }}" == "true" ]; then
51-
args="$args --author-name"
52-
fi
53-
if [ "${{ inputs.author-email }}" == "true" ]; then
54-
args="$args --author-email"
55-
fi
56-
if [ "${{ inputs.dry-run }}" == "true" ]; then
57-
args="$args --dry-run"
58-
fi
59-
commit-check $args
37+
env:
38+
MESSAGE: ${{ inputs.message }}
39+
BRANCH: ${{ inputs.branch }}
40+
AUTHOR_NAME: ${{ inputs.author-name }}
41+
AUTHOR_EMAIL: ${{ inputs.author-email }}
42+
DRY_RUN: ${{ inputs.dry-run }}
43+
SUMMARY: ${{ inputs.summary }}

entrypoint

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
ret_code=0
4+
5+
install_deps(){
6+
if [ "$RUNNER_OS" == "Linux" ]; then
7+
# https://github.com/pypa/setuptools/issues/3269
8+
export DEB_PYTHON_INSTALL_LAYOUT=deb
9+
fi
10+
python3 -m pip install -r requirements.txt
11+
}
12+
13+
run_commit_check(){
14+
args=""
15+
if [ "$MESSAGE" == "true" ]; then
16+
args="$args --message"
17+
fi
18+
if [ "$BRANCH" == "true" ]; then
19+
args="$args --branch"
20+
fi
21+
if [ "$AUTHOR_NAME" == "true" ]; then
22+
args="$args --author-name"
23+
fi
24+
if [ "$AUTHOR_EMAIL" == "true" ]; then
25+
args="$args --author-email"
26+
fi
27+
28+
echo "commit-check $args"
29+
commit-check $args > result.txt
30+
ret_code=$?
31+
}
32+
33+
add_job_summary(){
34+
if [ "$SUMMARY" == "false" ]; then
35+
exit
36+
fi
37+
38+
if [ -s result.txt ]; then
39+
# strips ANSI colors
40+
sed -i "s,\x1B\[[0-9;]*[a-zA-Z],,g" result.txt
41+
cat result.txt
42+
echo "### Commit-Check ❌" >> $GITHUB_STEP_SUMMARY
43+
echo '```' >> $GITHUB_STEP_SUMMARY
44+
cat result.txt >> $GITHUB_STEP_SUMMARY
45+
echo '```' >> $GITHUB_STEP_SUMMARY
46+
ret_code=1
47+
else
48+
echo "### Commit-Check ✔️" >> $GITHUB_STEP_SUMMARY
49+
ret_code=0
50+
fi
51+
}
52+
53+
# start of main
54+
install_deps
55+
run_commit_check
56+
add_job_summary
57+
58+
if [ "$DRY_RUN" == "true" ]; then
59+
ret_code=0
60+
fi
61+
62+
exit $ret_code
63+
# end of main

0 commit comments

Comments
 (0)