From 4f553a147bf11f07e9afd3a45466cd91fca53fcd Mon Sep 17 00:00:00 2001 From: mrekucci Date: Wed, 7 Aug 2024 10:21:37 +0200 Subject: [PATCH] refactor: lint GitHub PR title --- .commitlintrc.yml | 37 ---------------- .../pull_request_template.md | 0 .github/workflows/ci.yml | 43 +++---------------- .github/workflows/pr.yml | 37 ++++++++++++++++ 4 files changed, 42 insertions(+), 75 deletions(-) delete mode 100644 .commitlintrc.yml rename pull_request_template.md => .github/pull_request_template.md (100%) 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/pull_request_template.md b/.github/pull_request_template.md similarity index 100% rename from pull_request_template.md rename to .github/pull_request_template.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 897851f29..682622c88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,11 @@ on: pull_request: branches: - main + workflow_run: + workflows: + - pr + types: + - completed permissions: contents: read @@ -16,43 +21,6 @@ concurrency: cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} jobs: - commitlint: - name: Check Commit Message - runs-on: ubuntu-24.04 - timeout-minutes: 30 - - 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 - go-modules: name: Test and Build Go Modules runs-on: ubuntu-24.04 @@ -245,7 +213,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..3ce0ceb86 --- /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 PR Title + runs-on: ubuntu-24.04 + timeout-minutes: 1 + + steps: + - name: Lint PR Title + run: | + regex="^(fix|feat|refactor|revert|test|perf|style|chore|docs): .*[^.\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 }}