From f014b03ab497cd1eabc8789a45b1aa46cc6d63f4 Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Tue, 1 Oct 2024 10:07:50 -0700 Subject: [PATCH 1/2] chore: add PR title check workflow --- .../check-convential-commit-pr-title.yml | 28 +++++++++++++++++++ scripts/generate-conventional-commit-regex.sh | 10 +++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/check-convential-commit-pr-title.yml create mode 100755 scripts/generate-conventional-commit-regex.sh diff --git a/.github/workflows/check-convential-commit-pr-title.yml b/.github/workflows/check-convential-commit-pr-title.yml new file mode 100644 index 00000000000..17e37edacd2 --- /dev/null +++ b/.github/workflows/check-convential-commit-pr-title.yml @@ -0,0 +1,28 @@ +name: Check Conventional Commit PR Title + +on: + pull_request: + types: [opened, edited, reopened] + +jobs: + check-pr-title: + runs-on: ubuntu-latest + env: + PR_TITLE: ${{ github.event.pull_request.title }} + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + path: amplify-js + - name: Generate Regex and Check PR title + working-directory: ./amplify-js + run: | + regex=$(./scripts/generate-conventional-commit-regex.sh) + if [[ $PR_TITLE =~ $regex ]]; then + echo "✅ PR title '$PR_TITLE' is valid" + exit 0 + else + echo "❌ PR title '$PR_TITLE' is invalid" + echo "It should match the pattern: $regex" + exit 1 + fi diff --git a/scripts/generate-conventional-commit-regex.sh b/scripts/generate-conventional-commit-regex.sh new file mode 100755 index 00000000000..1a5b34362f6 --- /dev/null +++ b/scripts/generate-conventional-commit-regex.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Get the list of directory names under ./packages +scopes=$(ls -d ./packages/*/ 2>/dev/null | xargs -n 1 basename | tr '\n' '|' | sed 's/|$//') + +# Generate the regular expression +regex="^(feat|fix|docs|style|refactor|perf|test|chore|revert|release)(\(($scopes|required)\))?: .+$" + +# Output the generated regex +echo "$regex"; From eaeb9f0e0bac9be4edf576d2970960e657ee7805 Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Tue, 8 Oct 2024 11:01:20 -0700 Subject: [PATCH 2/2] chore: double quote the env var --- .github/workflows/check-convential-commit-pr-title.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-convential-commit-pr-title.yml b/.github/workflows/check-convential-commit-pr-title.yml index 17e37edacd2..b3a656dab53 100644 --- a/.github/workflows/check-convential-commit-pr-title.yml +++ b/.github/workflows/check-convential-commit-pr-title.yml @@ -18,7 +18,7 @@ jobs: working-directory: ./amplify-js run: | regex=$(./scripts/generate-conventional-commit-regex.sh) - if [[ $PR_TITLE =~ $regex ]]; then + if [[ "$PR_TITLE" =~ $regex ]]; then echo "✅ PR title '$PR_TITLE' is valid" exit 0 else