From 7c2574fb89a3af8428686ff02adc05fd28a91da3 Mon Sep 17 00:00:00 2001 From: mrekucci Date: Wed, 7 Aug 2024 10:21:37 +0200 Subject: [PATCH] lint GitHub PR title --- .commitlintrc.yml | 37 ------------------------------------ .github/workflows/ci.yml | 41 +++++++--------------------------------- .github/workflows/pr.yml | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 71 deletions(-) delete mode 100644 .commitlintrc.yml create mode 100644 .github/workflows/pr.yml diff --git a/.commitlintrc.yml b/.commitlintrc.yml deleted file mode 100644 index 6d6fb8b23..000000000 --- a/.commitlintrc.yml +++ /dev/null @@ -1,37 +0,0 @@ -extends: - - '@commitlint/config-conventional' -rules: - header-max-length: [1, 'always', 72] - body-leading-blank: [2, 'always'] - subject-empty: [2, 'never'] - subject-full-stop: [2, 'never', '.'] - subject-case: - - 2 - - never - - - sentence-case - - start-case - - pascal-case - type-empty: [2, 'never'] - type-enum: - - 2 - - always - - - fix - - feat - - refactor - - revert - - test - - perf - - style - - chore - - docs -help: | - **Possible types**: - `fix`: Solves a bug. - `feat`: Adds a new feature. - `refactor`: Rewrites code without feature, performance or bug changes. - `revert`: Changes that reverting other changes. - `test`: Adds missing or correcting existing tests. - `perf`: A code change that improves performance. - `style`: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc). - `chore`: Changes to the build process or auxiliary tools and libraries such as documentation generation. - `docs`: Documentation only changes. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 897851f29..6e3623e0a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,47 +16,21 @@ concurrency: cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} jobs: - commitlint: - name: Check Commit Message + pr: + name: Lint PR Title runs-on: ubuntu-24.04 - timeout-minutes: 30 + timeout-minutes: 1 steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install Required Dependencies - run: | - sudo apt-get update - sudo apt-get install -y git curl - curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs - - npm install conventional-changelog-conventionalcommits - npm install --save-dev @commitlint/config-conventional - npm install commitlint@latest - - - name: Print Versions - run: | - git --version - node --version - npm --version - npx commitlint --version - - - name: Validate Current (Last) Commit Message - if: github.event_name == 'push' - run: npx commitlint --last --verbose - - - name: Validate PR Commit Messages - if: github.event_name == 'pull_request' - run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose + uses: ./.github/workflows/pr.yml + secrets: inherit go-modules: name: Test and Build Go Modules runs-on: ubuntu-24.04 timeout-minutes: 60 + needs: + - steps: - name: Checkout Code @@ -245,7 +219,6 @@ jobs: uses: ./.github/workflows/infrastructure.yml secrets: inherit needs: - - commitlint - go-modules - foundry - contracts diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 000000000..9666ae4f5 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,37 @@ +name: pr + +on: + pull_request: + types: + - opened + - edited + - synchronize + branches: + - main + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + lint: + name: Lint + runs-on: ubuntu-24.04 + timeout-minutes: 1 + + steps: + - name: Lint PR Title + run: | + regex="^(fix|feat|refactor|revert|test|perf|style|chore|docs): [a-z][^.\n]{0,70}$" + if [[ "${PR_TITLE}" =~ $regex ]]; then + echo -e "PR title is valid: ${PR_TITLE}" + else + echo -e "Invalid PR title: ${PR_TITLE}" + echo -e "PR title must match the following pattern: ${regex}" + exit 1 + fi + env: + PR_TITLE: ${{ github.event.pull_request.title }} \ No newline at end of file