Skip to content

feat: add job summary #8

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 1 commit into from
Feb 3, 2023
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
3 changes: 1 addition & 2 deletions .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Commit Check

on:
push:
branches: 'main'
pull_request:
branches: 'main'

Expand All @@ -17,4 +16,4 @@ jobs:
branch: true
author-name: true
author-email: true
dry-run: true
summary: true
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows
```yaml
name: Commit Check

on: pull_request
on:
push:
pull_request:
branches: 'main'

jobs:
commit-check:
Expand All @@ -26,20 +29,21 @@ jobs:
author-name: true
author-email: true
dry-run: true
summary: true
```

## Optional Inputs

### `message`

- **Description**: check commit message formatting convention
- By default the rule follows [conventionalcommits](https://www.conventionalcommits.org/)
- **Description**: check commit message formatting convention.
- By default the rule follows [conventionalcommits](https://www.conventionalcommits.org/).
- Default: 'true'

### `branch`

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

### `author-name`
Expand All @@ -54,10 +58,15 @@ jobs:

### `dry-run`

- **Description**: run checks without failing
- **Description**: run checks without failing. exit code is 0 otherwise is 1.
- Default: 'false'

Note: to change the default rules of above inputs, just add your own [`.commit-check.yml`](.commit-check.yml) config file.
### `summary`

- **Description**: display job summary to a workflow run
- Default: 'true'

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.

## Badging your repository

Expand Down
42 changes: 13 additions & 29 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Commit Check Action
description: Check commit message formatting, branch naming, referencing Jira tickets, and more
description: Check commit message formatting, branch naming, committer name, email, and more
author: shenxianpeng
branding:
icon: "git-commit"
Expand All @@ -25,35 +25,19 @@ inputs:
description: run checks without failing
required: false
default: false
summary:
description: add a job summary
required: false
default: true
runs:
using: "composite"
steps:
- name: Install action dependencies
shell: bash
run: |
if [[ "${{runner.os}}" == "Linux" ]]; then
# https://github.com/pypa/setuptools/issues/3269
export DEB_PYTHON_INSTALL_LAYOUT=deb
fi
python3 -m pip install -r '${{ github.action_path }}/requirements.txt'
- name: Run commit-check
id: commit-check
- run: ${{ github.action_path }}/entrypoint
shell: bash
run: |
args=""
if [ "${{ inputs.message }}" == "true" ]; then
args="$args --message"
fi
if [ "${{ inputs.branch }}" == "true" ]; then
args="$args --branch"
fi
if [ "${{ inputs.author-name }}" == "true" ]; then
args="$args --author-name"
fi
if [ "${{ inputs.author-email }}" == "true" ]; then
args="$args --author-email"
fi
if [ "${{ inputs.dry-run }}" == "true" ]; then
args="$args --dry-run"
fi
commit-check $args
env:
MESSAGE: ${{ inputs.message }}
BRANCH: ${{ inputs.branch }}
AUTHOR_NAME: ${{ inputs.author-name }}
AUTHOR_EMAIL: ${{ inputs.author-email }}
DRY_RUN: ${{ inputs.dry-run }}
SUMMARY: ${{ inputs.summary }}
63 changes: 63 additions & 0 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

ret_code=0

install_deps(){
if [ "$RUNNER_OS" == "Linux" ]; then
# https://github.com/pypa/setuptools/issues/3269
export DEB_PYTHON_INSTALL_LAYOUT=deb
fi
python3 -m pip install -r requirements.txt
}

run_commit_check(){
args=""
if [ "$MESSAGE" == "true" ]; then
args="$args --message"
fi
if [ "$BRANCH" == "true" ]; then
args="$args --branch"
fi
if [ "$AUTHOR_NAME" == "true" ]; then
args="$args --author-name"
fi
if [ "$AUTHOR_EMAIL" == "true" ]; then
args="$args --author-email"
fi

echo "commit-check $args"
commit-check $args > result.txt
ret_code=$?
}

add_job_summary(){
if [ "$SUMMARY" == "false" ]; then
exit
fi

if [ -s result.txt ]; then
# strips ANSI colors
sed -i "s,\x1B\[[0-9;]*[a-zA-Z],,g" result.txt
cat result.txt
echo "### Commit-Check ❌" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat result.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
ret_code=1
else
echo "### Commit-Check ✔️" >> $GITHUB_STEP_SUMMARY
ret_code=0
fi
}

# start of main
install_deps
run_commit_check
add_job_summary

if [ "$DRY_RUN" == "true" ]; then
ret_code=0
fi

exit $ret_code
# end of main