diff --git a/.commitlintrc.yaml b/.commitlintrc.yaml index 28fbce6..763206d 100644 --- a/.commitlintrc.yaml +++ b/.commitlintrc.yaml @@ -1 +1,7 @@ extends: ['@commitlint/config-conventional'] + +rules: + type-enum: + - 2 + - always + - [arch, build, ci, docs, feat, fix, perf, refactor, test] diff --git a/.github/actions/setup-node/action.yaml b/.github/actions/setup-node/action.yaml new file mode 100644 index 0000000..47dc0af --- /dev/null +++ b/.github/actions/setup-node/action.yaml @@ -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- diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7700d41..e9e6550 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -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/')" diff --git a/.github/workflows/prepare_release.yaml b/.github/workflows/prepare_release.yaml index 861011e..f4d2340 100644 --- a/.github/workflows/prepare_release.yaml +++ b/.github/workflows/prepare_release.yaml @@ -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 }} @@ -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: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 109b232..5569d55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: @@ -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 diff --git a/knope.toml b/knope.toml index f138aef..7691191 100644 --- a/knope.toml +++ b/knope.toml @@ -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]] @@ -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]