From cfcedd4f91dd9b431042b2c08b0562b6b7d4eb46 Mon Sep 17 00:00:00 2001 From: Benjamin Boboul <8467845+benjaminBoboul@users.noreply.github.com> Date: Thu, 9 Mar 2023 21:31:14 +0100 Subject: [PATCH 1/6] feat: Add regex for conventional commits customization --- action.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 8ce43c0..d68dd1f 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,22 @@ inputs: description: 'Range of commits.' required: false default: 'HEAD' + conventional-regex: + description: 'Regex used to determine if a commit is conventional' + required: false + default: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!)?: ([[:alnum:]])+([[:space:][:print:]]*)" + conventional-regex-patch: + description: 'Regex used to determine if a commit is conventional' + required: false + default: "^(fix){1}(\([[:alnum:]._-]+\))?: ([[:alnum:]])+([[:space:][:print:]]*)" + conventional-regex-minor: + description: 'Regex used to determine if a commit is conventional' + required: false + default: "^(feat){1}(\([[:alnum:]._-]+\))?: ([[:alnum:]])+([[:space:][:print:]]*)" + conventional-regex-major: + description: 'Regex used to determine if a commit is conventional' + required: false + default: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!): ([[:alnum:]])+([[:space:][:print:]]*)" outputs: patch: @@ -30,14 +46,14 @@ runs: - name: "Check commits messages" id: commits run: | - if [[ "" != $(git log --invert-grep --extended-regexp --grep="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!)?: ([[:alnum:]])+([[:space:][:print:]]*)" ${{ inputs.git-range }}) ]]; then + if [[ "" != $(git log --invert-grep --extended-regexp --grep=${{ inputs.conventional-regex }} ${{ inputs.git-range }}) ]]; then echo "The following commits message are invalid:" - git log --oneline --invert-grep --extended-regexp --grep="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!)?: ([[:alnum:]])+([[:space:][:print:]]*)" ${{ inputs.git-range }} + git log --oneline --invert-grep --extended-regexp --grep=${{ inputs.conventional-regex }} ${{ inputs.git-range }} exit 1 fi - echo patch=$(git log --oneline --extended-regexp --grep="^(fix){1}(\([[:alnum:]._-]+\))?: ([[:alnum:]])+([[:space:][:print:]]*)" ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT - echo minor=$(git log --oneline --extended-regexp --grep="^(feat){1}(\([[:alnum:]._-]+\))?: ([[:alnum:]])+([[:space:][:print:]]*)" ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT - echo major=$(git log --oneline --extended-regexp --grep="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!): ([[:alnum:]])+([[:space:][:print:]]*)" ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT + echo patch=$(git log --oneline --extended-regexp --grep=${{ inputs.conventional-regex-patch }} ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT + echo minor=$(git log --oneline --extended-regexp --grep=${{ inputs.conventional-regex-minor }} ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT + echo major=$(git log --oneline --extended-regexp --grep=${{ inputs.conventional-regex-major }} ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT shell: bash \ No newline at end of file From 7d962478ebc05d14e85ee5f42540c8d16e62391a Mon Sep 17 00:00:00 2001 From: Benjamin Boboul <8467845+benjaminBoboul@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:24:25 +0100 Subject: [PATCH 2/6] refactor: escape backslash from commit regex --- .github/workflows/pr.yml | 5 +---- action.yml | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index cb97657..1166eca 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,7 +6,4 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - with: - fetch-depth: ${{ github.event.pull_request.commits }} - ref: ${{ github.event.pull_request.head.sha }} - - uses: bugbundle/commits@v1.0.0 \ No newline at end of file + - uses: ./action.yml \ No newline at end of file diff --git a/action.yml b/action.yml index d68dd1f..5ee5c25 100644 --- a/action.yml +++ b/action.yml @@ -14,19 +14,19 @@ inputs: conventional-regex: description: 'Regex used to determine if a commit is conventional' required: false - default: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!)?: ([[:alnum:]])+([[:space:][:print:]]*)" + default: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([[:alnum:]._-]+\\))?(!)?: ([[:alnum:]])+([[:space:][:print:]]*)" conventional-regex-patch: description: 'Regex used to determine if a commit is conventional' required: false - default: "^(fix){1}(\([[:alnum:]._-]+\))?: ([[:alnum:]])+([[:space:][:print:]]*)" + default: "^(fix){1}(\\([[:alnum:]._-]+\\))?: ([[:alnum:]])+([[:space:][:print:]]*)" conventional-regex-minor: description: 'Regex used to determine if a commit is conventional' required: false - default: "^(feat){1}(\([[:alnum:]._-]+\))?: ([[:alnum:]])+([[:space:][:print:]]*)" + default: "^(feat){1}(\\([[:alnum:]._-]+\\))?: ([[:alnum:]])+([[:space:][:print:]]*)" conventional-regex-major: description: 'Regex used to determine if a commit is conventional' required: false - default: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([[:alnum:]._-]+\))?(!): ([[:alnum:]])+([[:space:][:print:]]*)" + default: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([[:alnum:]._-]+\\))?(!): ([[:alnum:]])+([[:space:][:print:]]*)" outputs: patch: From 0dab2a013a15af5d2db748b266b936aed690a3f7 Mon Sep 17 00:00:00 2001 From: Benjamin Boboul <8467845+benjaminBoboul@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:25:45 +0100 Subject: [PATCH 3/6] fix: update local action path --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1166eca..cd9cfd9 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,4 +6,4 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - uses: ./action.yml \ No newline at end of file + - uses: $GITHUB_WORKSPACE \ No newline at end of file From d05fc0208c01d0e36b6e96d5ed84f4979977f172 Mon Sep 17 00:00:00 2001 From: Benjamin Boboul <8467845+benjaminBoboul@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:26:25 +0100 Subject: [PATCH 4/6] fix: use dot to refer root path --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index cd9cfd9..30a028b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,4 +6,4 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - uses: $GITHUB_WORKSPACE \ No newline at end of file + - uses: . \ No newline at end of file From 91034db87a3c44f69c7795338276b8f751803d84 Mon Sep 17 00:00:00 2001 From: Benjamin Boboul <8467845+benjaminBoboul@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:27:11 +0100 Subject: [PATCH 5/6] fix: add slash --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 30a028b..bb6740f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,4 +6,4 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - uses: . \ No newline at end of file + - uses: ./ \ No newline at end of file From 073e49703c184b42f4efeb5e8e4156e73ba2c5cf Mon Sep 17 00:00:00 2001 From: Benjamin Boboul <8467845+benjaminBoboul@users.noreply.github.com> Date: Sun, 19 Mar 2023 11:28:46 +0100 Subject: [PATCH 6/6] fix: add quotes to prevent syntax error from refex --- action.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 5ee5c25..db6fc57 100644 --- a/action.yml +++ b/action.yml @@ -46,14 +46,14 @@ runs: - name: "Check commits messages" id: commits run: | - if [[ "" != $(git log --invert-grep --extended-regexp --grep=${{ inputs.conventional-regex }} ${{ inputs.git-range }}) ]]; then + if [[ "" != $(git log --invert-grep --extended-regexp --grep="${{ inputs.conventional-regex }}" ${{ inputs.git-range }}) ]]; then echo "The following commits message are invalid:" - git log --oneline --invert-grep --extended-regexp --grep=${{ inputs.conventional-regex }} ${{ inputs.git-range }} + git log --oneline --invert-grep --extended-regexp --grep="${{ inputs.conventional-regex }}" ${{ inputs.git-range }} exit 1 fi - echo patch=$(git log --oneline --extended-regexp --grep=${{ inputs.conventional-regex-patch }} ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT - echo minor=$(git log --oneline --extended-regexp --grep=${{ inputs.conventional-regex-minor }} ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT - echo major=$(git log --oneline --extended-regexp --grep=${{ inputs.conventional-regex-major }} ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT + echo patch=$(git log --oneline --extended-regexp --grep="${{ inputs.conventional-regex-patch }}" ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT + echo minor=$(git log --oneline --extended-regexp --grep="${{ inputs.conventional-regex-minor }}" ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT + echo major=$(git log --oneline --extended-regexp --grep="${{ inputs.conventional-regex-major }}" ${{ inputs.git-range }} | wc -l) >> $GITHUB_OUTPUT shell: bash \ No newline at end of file