Skip to content

Commit

Permalink
ci: create a pr title and commit linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dianjuar committed Oct 29, 2024
1 parent 95c5a50 commit 08a8240
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
41 changes: 4 additions & 37 deletions .github/workflows/pr.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/enforce-semantic-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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
- uses: ./.github/actions/setup

- name: Check PR Title
run: |
PR_TITLE='${{ github.event.pull_request.title }}'
echo "PR TITLE": '$PR_TITLE'
echo "$PR_TITLE" | npx commitlint

0 comments on commit 08a8240

Please sign in to comment.