From 993e4b11aafd2d854688017e3320d940ffa5f1bb 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} | 37 +------------------ .../workflows/enforce-semantic-commits.yml | 33 +++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) rename .github/workflows/{pr.yml => ci.yml} (55%) create mode 100644 .github/workflows/enforce-semantic-commits.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/ci.yml similarity index 55% rename from .github/workflows/pr.yml rename to .github/workflows/ci.yml index 48285c1f..e22b10c8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ -name: PR's +name: CI on: pull_request: - types: [opened, synchronize, reopened] + # 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..8ca679f8 --- /dev/null +++ b/.github/workflows/enforce-semantic-commits.yml @@ -0,0 +1,33 @@ +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: + - name: Check PR Title + run: | + PR_TITLE='${{ github.event.pull_request.title }}' + echo "PR TITLE": '$PR_TITLE' + echo "$PR_TITLE" | npx commitlint