From b9b253c36bbdf5c7615938bc8bd11c2e7dd050ab Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 19:55:06 -0500 Subject: [PATCH] ci: create a pr title and commit linter --- .github/workflows/{pr.yml => ci.yml} | 41 ++----------------- .../workflows/enforce-semantic-commits.yml | 35 ++++++++++++++++ 2 files changed, 39 insertions(+), 37 deletions(-) rename .github/workflows/{pr.yml => ci.yml} (54%) create mode 100644 .github/workflows/enforce-semantic-commits.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/ci.yml similarity index 54% rename from .github/workflows/pr.yml rename to .github/workflows/ci.yml index 48285c1f..0dadfaa1 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ -name: PR's -on: - pull_request: - types: [opened, synchronize, reopened] +name: CI +# on: +# pull_request: +# types: [opened, synchronize, reopened] env: PR_NUMBER: ${{ github.event.pull_request.number }} @@ -13,39 +13,6 @@ jobs: pr-e2e-test: uses: ./.github/workflows/e2e-test.yml - check-commit-lint: - name: Check commit message follows guidelines - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Execute commitlint - run: npx commitlint --from=origin/${{ github.base_ref }} - - - name: Get PR Title - run: "echo 'PR Title: ${{ github.event.pull_request.title }}'" - - - name: Get commit messages - run: | - BODY=$(git log \ - --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} \ - --pretty=format:'* %s%n%n%b') - TITLE='${{ github.event.pull_request.title }}' - - echo $TITLE - echo '---------' - echo $BODY - echo '---------' - echo "${TITLE}\n${BODY}" - echo '---------' - - echo "${TITLE}\n${BODY}" > commit-message.txt - cat commit-message.txt - - - name: Check commit message - run: cat commit-message.txt | npx commitlint - check-file-format: name: Check files changes follow guidelines runs-on: ubuntu-latest diff --git a/.github/workflows/enforce-semantic-commits.yml b/.github/workflows/enforce-semantic-commits.yml new file mode 100644 index 00000000..08b05398 --- /dev/null +++ b/.github/workflows/enforce-semantic-commits.yml @@ -0,0 +1,35 @@ +name: Enforce Semantic Commits + +on: + pull_request: + types: [opened, edited, synchronize] #? reopened + +jobs: + check-semantic-commits: + name: Check Semantic Commits + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + + - name: Fetch all commits for the PR + run: git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge + + - name: Check commit messages + run: | + COMMIT_MESSAGES="$(git log --pretty=format:'%s' --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})" + echo "$COMMIT_MESSAGES" | npx commitlint + + # 'Check if the PR title is a valid semantic commit message' + check-pr-title: + name: Check PR Title + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Check PR Title + run: | + PR_TITLE='${{ github.event.pull_request.title }}' + echo "PR TITLE": '$PR_TITLE' + echo "$PR_TITLE" | npx commitlint