Skip to content

Commit

Permalink
feat(pre-commit): migrate from apm-pipeline-library (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Sep 12, 2024
1 parent 93ca95e commit 5dc5897
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
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 }}

0 comments on commit 5dc5897

Please sign in to comment.