From 5dc589756c6d6efb6a4fc772fdca4b465f60f73c Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 12 Sep 2024 14:15:09 +0200 Subject: [PATCH] feat(pre-commit): migrate from apm-pipeline-library (#119) --- pre-commit/README.md | 33 +++++++++++++++++++++++++++++++++ pre-commit/action.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 pre-commit/README.md create mode 100644 pre-commit/action.yml diff --git a/pre-commit/README.md b/pre-commit/README.md new file mode 100644 index 00000000..e12c7b3a --- /dev/null +++ b/pre-commit/README.md @@ -0,0 +1,33 @@ +# pre-commit + +[![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) + + +Run pre-commit independently you are running on a PR or a branch. + + +## Inputs + + +| Name | Description | Required | Default | +|------------------|-------------------------------------------------------------------------------|----------|---------| +| `clean-checkout` | Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching | `false` | `true` | + + +## Usage + + +```yaml +on: + pull_request: ~ + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: elastic/oblt-actions/pre-commit@v1 +``` + diff --git a/pre-commit/action.yml b/pre-commit/action.yml new file mode 100644 index 00000000..418278c3 --- /dev/null +++ b/pre-commit/action.yml @@ -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 }}