diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 3363b7ef..3f3f939e 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -55,15 +55,17 @@ jobs: validateSingleCommit: ${{ inputs.validateSingleCommit }} - name: ๐Ÿท๏ธ Check PR labels - if: ${{ inputs.checkLabels }} + if: ${{ inputs.checkLabels && github.event.pull_request.head.repo.fork == false }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - if [ -z "$(gh api repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name')" ]; then + labels=$(gh api repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name') + + if [ -z "$labels" ]; then echo "::error::No labels found on this PR. Please add at least one label." exit 1 else - echo "PR has labels, validation passed." + echo "PR has labels" fi validate-commits: @@ -75,8 +77,8 @@ jobs: with: fetch-depth: 0 - - name: ๐Ÿงพ Validate Commit Messages - uses: webiny/action-conventional-commits@v1.3.1 + - name: ๐Ÿงพ Commitlint Validation (Inline Config) + uses: wagoid/commitlint-github-action@v6 with: - allowed-commit-types: ${{ inputs.types }} + configFile: commitlint.config.cjs ... diff --git a/commitlint.config.cjs b/commitlint.config.cjs new file mode 100644 index 00000000..abc6b37d --- /dev/null +++ b/commitlint.config.cjs @@ -0,0 +1,19 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'type-enum': [2, 'always', [ + 'fix', + 'feat', + 'docs', + 'ci', + 'chore', + 'test', + 'refactor', + 'style', + 'perf', + 'build', + 'revert' + ]], + 'header-max-length': [2, 'always', 100] + } +}; \ No newline at end of file diff --git a/docs/pr-checks.md b/docs/pr-checks.md index a4125b18..1b04b211 100644 --- a/docs/pr-checks.md +++ b/docs/pr-checks.md @@ -23,6 +23,71 @@ Automatically validates: ### Usage This workflow triggers automatically on PR events and can be configured with input parameters. +### 1๏ธโƒฃ PR Title Validation +- Using [amannn/action-semantic-pull-request](https://github.com/amannn/action-semantic-pull-request/blob/main/README.md) +- Ensures PR titles follow Conventional Commits format. +- Example: + +โœ… Valid + +``` + feat(api): Add login endpoint + fix: Resolve token issue + docs(readme): Update installation guide +``` + + โŒ Invalid + ``` + update login + bug fix + added new feature + ``` + + **๐Ÿท๏ธ Check PR labels** + | **PR Type** | **Label Validation** | + |--------------------|--------------------------| + | Internal PR | โœ… checked | + | Fork PR | โญ skipped | + +#### **Example flow** + Internal contributor + + PR โ†’ validation runs: + ``` + PR title โœ” + commits โœ” + labels โœ” + ``` + + Fork contributor + + PR โ†’ validation runs: + ``` + PR title โœ” + commits โœ” + labels โญ skipped + ``` + +### 2๏ธโƒฃ Commit Message Validation +- Using [wagoid/commitlint-github-action](https://github.com/wagoid/commitlint-github-action/blob/master/README.md) +- Ensures all commits follow Conventional Commit format. +- Example: + +โœ… Valid commits + +``` + feat(api): add login endpoint + fix(auth): resolve token issue + docs: update readme +``` + โŒ Invalid + +``` + update code + bug fix + changes +``` + #### Example Implementation ```yaml name: 'PR Validation'