diff --git a/.github/commitlint.yml b/.github/commitlint.yml deleted file mode 100644 index d69322fc..00000000 --- a/.github/commitlint.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: "Lint commit messages" - -# Run on every push to main (or your default branch) and on PRs -on: - push: - branches: - - main - pull_request: - -jobs: - commit_lint: - runs-on: ubuntu-latest - - steps: - # 1. Fetch all history so we can diff commit ranges - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - # 2. Set up Node.js (needed to run commitlint) - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" - - # 3. Install commitlint and the conventional-commits preset - - name: Install Commitlint - run: npm install @commitlint/cli @commitlint/config-conventional - - # 4. Run commitlint over the pushed or PR range - - name: Lint commits - run: | - if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then - RANGE="${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" - else - RANGE="${{ github.event.before }}...${{ github.sha }}" - fi - npx commitlint --from "$RANGE" --to "${{ github.sha }}" diff --git a/.github/workflows/lint_pr_title.yaml b/.github/workflows/lint_pr_title.yaml new file mode 100644 index 00000000..05b4e7fe --- /dev/null +++ b/.github/workflows/lint_pr_title.yaml @@ -0,0 +1,39 @@ +name: "Lint PR title" + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + +jobs: + lint_pr_title: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Install commitlint + run: npm install @commitlint/cli @commitlint/config-conventional + + - name: Get current PR title + id: get_title + uses: actions/github-script@v6 + with: + script: | + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + }); + return pr.data.title; + + - name: Lint PR title + run: | + echo "${{ steps.get_title.outputs.result }}" > pr_title.txt + npx commitlint --edit pr_title.txt --config commitlint.config.js