Skip to content
Merged
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
33 changes: 33 additions & 0 deletions pre-commit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# <!--name-->pre-commit<!--/name-->

[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2Fpre-commit+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code)

<!--description-->
Run pre-commit independently you are running on a PR or a branch.
<!--/description-->

## Inputs

<!--inputs-->
| Name | Description | Required | Default |
|------------------|-------------------------------------------------------------------------------|----------|---------|
| `clean-checkout` | Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching | `false` | `true` |
<!--/inputs-->

## Usage

<!--usage action="elastic/oblt-actions/**" version="env:VERSION"-->
```yaml
on:
pull_request: ~

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: elastic/oblt-actions/pre-commit@v1
```
<!--/usage-->
29 changes: 29 additions & 0 deletions pre-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: 'pre-commit'
description: |
Run pre-commit independently you are running on a PR or a branch.
inputs:
clean-checkout:
default: "true"
description: "Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching"
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
with:
clean: ${{ inputs.clean-checkout }}
# Fetch all the history so the pre-commit/action can compare changes between the target and the git commit
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: 3.9

- 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 }}