Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ max_line_length = 160
indent_style = space
indent_size = 4

[*.{md,markdown,json,js,yml,csproj,fsproj,targets,targets,props}]
[*.{md,markdown,json,js,yml,yaml,csproj,fsproj,targets,targets,props}]
indent_style = space
indent_size = 2

Expand Down
6 changes: 5 additions & 1 deletion .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ runs:
# Ensure we fetch all tags
- shell: bash
run: |
git fetch --prune --unshallow --tags
if [ -f .git/shallow ]; then
git fetch --prune --unshallow --tags
else
git fetch --prune --tags
fi
git tag --list

- name: Git config
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: ./.github/actions/bootstrap
- run: npm ci
working-directory: src/Elastic.Documentation.Site
- uses: actions/setup-python@v6
- name: Run pre-commit on PRs
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
if: ${{ github.event.pull_request }}
with:
extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
- name: Run pre-commit on branches
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
if: ${{ ! github.event.pull_request }}
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
- repo: local
hooks:
- id: dotnet-format
name: dotnet format
language: system
entry: dotnet format --no-restore --verbosity quiet --include
files: \.(cs|fs)$
pass_filenames: true

# Run prettier only for src/Elastic.Documentation.Site
- id: prettier
name: Prettier Code Formatter
language: system
entry: bash -c 'cd src/Elastic.Documentation.Site && npx prettier --write "${@#src/Elastic.Documentation.Site/}"' --
files: ^src/Elastic\.Documentation\.Site
verbose: true
pass_filenames: true

# Run TypeScript type checking for src/Elastic.Documentation.Site
- id: typescript-check
name: TypeScript Type Check
language: system
entry: bash -c 'cd src/Elastic.Documentation.Site && npx tsc --noEmit'
files: ^src/Elastic\.Documentation\.Site/.*\.tsx?$
pass_filenames: false

# Run eslint only for src/Elastic.Documentation.Site
- id: eslint
name: ESLint
language: system
entry: bash -c 'cd src/Elastic.Documentation.Site && npx eslint --fix "${@#src/Elastic.Documentation.Site/}"' --
files: ^src/Elastic\.Documentation\.Site/.*\.(js|jsx|ts|tsx|mjs)$
verbose: true
pass_filenames: true
62 changes: 62 additions & 0 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,68 @@ based on the labels of the pull requests merged into the `main` branch.

See the [release-drafter configuration](./.github/release-drafter.yml) for more details.

## Pre-commit Hooks

This repository uses [pre-commit](https://pre-commit.com/) to automatically format and validate code before commits.

### What Gets Checked

The following hooks run automatically on staged files:

- **dotnet format** - Formats C# and F# files
- **prettier** - Formats TypeScript, JavaScript, CSS, and other files in `src/Elastic.Documentation.Site/`
- **TypeScript** - Type checks TypeScript files with `tsc --noEmit`
- **ESLint** - Lints and fixes JavaScript/TypeScript files

### Installation

#### Install pre-commit

```bash
# macOS/Linux
pip install pre-commit

# macOS with Homebrew
brew install pre-commit

# Windows
pip install pre-commit
```

#### Install the hooks

```bash
pre-commit install
```

### Usage

Once installed, hooks run automatically when you commit:

```bash
git add .
git commit -m "your message"
```

**Note:** If hooks modify files (prettier, eslint, dotnet format), the commit will fail so you can review the changes. Simply run the commit command again to commit the formatted code.

#### Manual Execution

Run hooks on all files:
```bash
pre-commit run --all-files
```

Run a specific hook:
```bash
pre-commit run prettier --all-files
pre-commit run dotnet-format --all-files
```

#### CI Integration

Pre-commit hooks also run in GitHub Actions on all pull requests to ensure code quality and consistency.

## Creating a New Release

To create a new release trigger the [release](https://github.com/elastic/docs-builder/actions/workflows/release.yml) workflow on the `main` branch.
Expand Down
Loading