From 9c4368315dd070e47defc9270c42b673664af57d Mon Sep 17 00:00:00 2001 From: Mircea-Pavel Anton Date: Mon, 16 Sep 2024 00:55:54 +0300 Subject: [PATCH] feat(workflow): Add reusable CommitLint workflow (#41) * feat: Add reusable CommitLint workflow * fix * try fix * add sample config * fix? * add missing quotes * fix lint --- .commitlintrc.yaml | 13 ++++++ .github/workflows/lint-job.yaml | 11 +++-- .github/workflows/reusable-commitlint.yaml | 51 ++++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 .commitlintrc.yaml create mode 100644 .github/workflows/reusable-commitlint.yaml diff --git a/.commitlintrc.yaml b/.commitlintrc.yaml new file mode 100644 index 0000000..18c6d7c --- /dev/null +++ b/.commitlintrc.yaml @@ -0,0 +1,13 @@ +--- +# Inherit configuration of a package +include: package:commitlint_cli/commitlint.yaml + +# Custom rules +rules: + type-case: + - 2 + - always + - "lower-case" + +# Whether commitlint uses the default ignore rules. +defaultIgnores: true diff --git a/.github/workflows/lint-job.yaml b/.github/workflows/lint-job.yaml index 39defe0..62427c5 100644 --- a/.github/workflows/lint-job.yaml +++ b/.github/workflows/lint-job.yaml @@ -4,10 +4,7 @@ name: Lint on: workflow_dispatch: {} - - pull_request: - paths: - - "**.yaml" + pull_request: {} jobs: yamllint: @@ -31,3 +28,9 @@ jobs: secrets: inherit with: markdownlint-cli-version: "0.41.0" + + commitlint: + uses: ./.github/workflows/reusable-commitlint.yaml + secrets: inherit + with: + commitlint-version: "v19.5.0" diff --git a/.github/workflows/reusable-commitlint.yaml b/.github/workflows/reusable-commitlint.yaml new file mode 100644 index 0000000..6596533 --- /dev/null +++ b/.github/workflows/reusable-commitlint.yaml @@ -0,0 +1,51 @@ +--- +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Reusable - CommitLint + +on: + workflow_call: + inputs: + node-version: + description: "Node version" + required: false + type: string + default: "latest" + commitlint-version: + description: "Commitlint version" + required: false + type: string + default: "latest" + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - name: Generate Token + uses: actions/create-github-app-token@3378cda945da322a8db4b193e19d46352ebe2de5 # v1.10.4 + id: app-token + with: + app-id: "${{ secrets.BOT_APP_ID }}" + private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}" + + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + token: "${{ steps.app-token.outputs.token }}" + + - name: Set up Node + uses: actions/setup-node@v4.0.3 + with: + node-version: "${{ inputs.node-version }}" + + - name: Install commitlint + run: | + npm install conventional-changelog-conventionalcommits + npm install -g @commitlint/cli@${{ inputs.commitlint-version }} + + - name: Validate PR commits with commitlint + if: github.event_name == 'pull_request' + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + echo "$PR_TITLE" > file.txt + commitlint --verbose --color -e=file.txt