Skip to content

Commit

Permalink
ci: better commitlint support
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 7, 2024
1 parent 0aa76e1 commit e36df83
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
extends: ['@commitlint/config-conventional']

rules:
type-enum:
- 2
- always
- [arch, build, ci, docs, feat, fix, perf, refactor, test]
29 changes: 29 additions & 0 deletions .github/actions/setup-node/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Setup Node & PNPM
description: Install NodeJS and PNPM tooling

runs:
using: composite
steps:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |-
${{ runner.os }}-pnpm-store-
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ jobs:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
requireScope: true
types: |
arch
build
ci
docs
feat
fix
perf
refactor
test
scopes: |
repo
release
data-stream
sdk-rust
sdk-ts
lockfile:
name: Validate Lockfile
Expand All @@ -34,6 +52,26 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo update --workspace --locked

commitlint:
name: Validating commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node && PNPM
uses: ./.github/actions/setup-node

- name: Validate current commit (last commit) with commitlint
if: github.event_name == 'push'
run: npx commitlint --last --verbose

- name: Validate PR commits with commitlint
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

lint:
name: Linting
if: "!startsWith(github.head_ref, 'releases/')"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prepare_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:
setup:
if: "!startsWith(github.event.head_commit.message, 'ci(bump)')"
if: "!startsWith(github.event.head_commit.message, 'ci(release)')"
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.set-vars.outputs.branch }}
Expand All @@ -29,7 +29,7 @@ jobs:
echo "branch=changeset/release-main" >> $GITHUB_OUTPUT
prepare-release:
if: "!startsWith(github.event.head_commit.message, 'ci(bump)')"
if: "!startsWith(github.event.head_commit.message, 'ci(release)')"
needs: setup
runs-on: ubuntu-latest
steps:
Expand Down
32 changes: 22 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ make setup
You can check the [./scripts/setup.sh](./scripts/setup.sh) file to see what is
being installed on your machine.

## 📝 Code conventions
## 📇 Code conventions

We enforce some conventions to ensure code quality, sustainability, and
maintainability. The following tools help us with that:
Expand All @@ -42,28 +42,40 @@ maintainability. The following tools help us with that:
Ensures that commit messages are clear and understandable.
- [Pre-commit](https://pre-commit.com/) - Ensures that the code is formatted
and linted before being committed.
- [Commitlint](https://commitlint.js.org/) - Lints commit messages to ensure
they follow the Conventional Commits specification.

### Writing your commits
### 📝 Writing your Commits & Pull Requests

When creating a commit, please follow the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. Use
`category(scope or module): message` in your commit message with one of the
following categories:

- `arch`: Changes that affect the architecture of the software.
- `build`: Changes regarding the build of the software, dependencies, or the
addition of new dependencies.
- `ci`: Changes regarding the configuration of continuous integration (e.g.,
GitHub Actions, CI systems).
- `docs`: Changes to existing documentation or creation of new documentation
(e.g., README, usage docs).
- `feat`: All changes that introduce completely new code or new
features.
- `fix`: Changes that fix a bug (ideally referencing an issue if present).
- `perf`: Changes that improve the performance of the software.
- `refactor`: Any code-related change that is not a fix or a feature.
- `docs`: Changes to existing documentation or creation of new documentation
(e.g., README, usage docs).
- `build`: Changes regarding the build of the software, dependencies, or the
addition of new dependencies.
- `test`: Changes regarding tests (adding new tests or changing existing
ones).
- `ci`: Changes regarding the configuration of continuous integration (e.g.,
GitHub Actions, CI systems).
- `chore`: Changes to the repository that do not fit into any of the above
categories.

This is a general rule used for commits. When you are creating a PR, ensure
that the title follows the same pattern, but in terms of PR, the scope is a
mandatory field. That's the scopes allowed at the moment:

- `repo`: Changes that affect a global scope of the repository.
- `release`: Scoped used for automatic release pull requests.
- `data-streams`: Changes that affect the data-streams package.
- `sdk-rust`: Changes that affect the Rust SDK package.
- `sdk-js`: Changes that affect the Typescript SDK package.

## 📜 Useful Commands

Expand Down
4 changes: 2 additions & 2 deletions knope.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ shell = true

[[workflows.steps]]
type = "Command"
command = "git commit -m \"ci(bump): prepare release $VERSION\""
command = "git commit -m \"ci(release): preparing $VERSION\""
variables = { "$VERSION" = "Version" }

[[workflows.steps]]
Expand All @@ -62,7 +62,7 @@ base = "main"
variables = { "$VERSION" = "Version" }

[workflows.steps.title]
template = "ci(bump): prepare release $VERSION"
template = "ci(release): preparing v$VERSION"
variables = { "$VERSION" = "Version" }

[workflows.steps.body]
Expand Down

0 comments on commit e36df83

Please sign in to comment.