diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml index 129e694..3c421da 100644 --- a/.github/workflows/commit-check.yml +++ b/.github/workflows/commit-check.yml @@ -2,7 +2,6 @@ name: Commit Check on: push: - branches: 'main' pull_request: branches: 'main' @@ -17,4 +16,4 @@ jobs: branch: true author-name: true author-email: true - dry-run: true + summary: true diff --git a/README.md b/README.md index a1706a1..0eb34c8 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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` @@ -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 diff --git a/action.yml b/action.yml index b842850..ef16335 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -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 }} diff --git a/entrypoint b/entrypoint new file mode 100755 index 0000000..697b594 --- /dev/null +++ b/entrypoint @@ -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