From e4dde8e52cd79fb042c2e7df64ae75f4ceffe696 Mon Sep 17 00:00:00 2001 From: Auguste Baum Date: Tue, 24 Sep 2024 16:20:37 +0200 Subject: [PATCH 1/3] add commitlint Workflow --- .commitlintrc.yml | 7 +++++++ .github/workflows/lint-pr-title.yml | 31 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .commitlintrc.yml create mode 100644 .github/workflows/lint-pr-title.yml diff --git a/.commitlintrc.yml b/.commitlintrc.yml new file mode 100644 index 00000000..fd0fffb1 --- /dev/null +++ b/.commitlintrc.yml @@ -0,0 +1,7 @@ +# Rules for commitlint +# Reference of all rules: https://commitlint.js.org/reference/rules.html +# This file adds customizations rules to the default ones defined in https://www.npmjs.com/package/@commitlint/config-conventional + +extends: ["@commitlint/config-conventional"] +rules: + "subject-case": [2, "always", ["sentence-case"]] diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 00000000..db46b1dd --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,31 @@ +name: Lint PR title + +on: + pull_request: + types: [opened, reopened, edited] + +permissions: + pull-requests: read + +jobs: + lint-pr-title: + runs-on: ubuntu-latest + steps: + # Only download commitlint config, not the whole repo + - uses: actions/checkout@v4 + with: + sparse-checkout: "*commitlint*" + sparse-checkout-cone-mode: false + - uses: actions/setup-node@v4 + with: + node-version: "20" + - name: Install commitlint + run: | + npm install @commitlint/config-conventional@19.5.0 + npm install commitlint@19.2.0 + - name: Lint PR title + # Use an environment variable to avoid a security vulnerability + # https://stackoverflow.com/a/76679447 + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: echo $PR_TITLE | npx commitlint --verbose From fd8515401e6b7c1e83a11387090e2121578f0a88 Mon Sep 17 00:00:00 2001 From: Auguste Baum Date: Mon, 30 Sep 2024 13:33:22 +0200 Subject: [PATCH 2/3] add docs --- CONTRIBUTING.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 79eb2df2..fca98e0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,6 +70,14 @@ Then, you can access the local build via: open doc/_build/html/index.html ``` +### PR format + +We use the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format, and we automatically check that the PR title fits this format. +In particular, commits are "sentence case", meaning "fix: Fix issue" passes, while "fix: fix issue" doesn't. +Our custom set of rules is in [commitlint.config.js](./commitlint.config.js). + +Generally the description of a commit should start with a verb in the imperative voice, so that it would properly complete the sentence: "When applied, this commit will [...]". + ## Help for common issues ### `make build-frontend` doesn't work! From 149c2b33485568a017b1d719ee6023232da997ba Mon Sep 17 00:00:00 2001 From: Auguste Baum Date: Tue, 1 Oct 2024 10:35:01 +0200 Subject: [PATCH 3/3] move config inside workflow --- .commitlintrc.yml | 7 ------- .github/workflows/lint-pr-title.yml | 14 +++++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 .commitlintrc.yml diff --git a/.commitlintrc.yml b/.commitlintrc.yml deleted file mode 100644 index fd0fffb1..00000000 --- a/.commitlintrc.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Rules for commitlint -# Reference of all rules: https://commitlint.js.org/reference/rules.html -# This file adds customizations rules to the default ones defined in https://www.npmjs.com/package/@commitlint/config-conventional - -extends: ["@commitlint/config-conventional"] -rules: - "subject-case": [2, "always", ["sentence-case"]] diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml index db46b1dd..dc7cecdc 100644 --- a/.github/workflows/lint-pr-title.yml +++ b/.github/workflows/lint-pr-title.yml @@ -11,11 +11,6 @@ jobs: lint-pr-title: runs-on: ubuntu-latest steps: - # Only download commitlint config, not the whole repo - - uses: actions/checkout@v4 - with: - sparse-checkout: "*commitlint*" - sparse-checkout-cone-mode: false - uses: actions/setup-node@v4 with: node-version: "20" @@ -23,6 +18,15 @@ jobs: run: | npm install @commitlint/config-conventional@19.5.0 npm install commitlint@19.2.0 + - name: Generate config file + # Here we define our custom rules for commitlint + # Reference of all rules: https://commitlint.js.org/reference/rules.html + run: | + tee -a .commitlintrc.yml << END + extends: ["@commitlint/config-conventional"] + rules: + "subject-case": [2, "always", ["sentence-case"]] + END - name: Lint PR title # Use an environment variable to avoid a security vulnerability # https://stackoverflow.com/a/76679447