From ecb12c3a7a4dbe99f8c18cdb51ecde5feb08157a Mon Sep 17 00:00:00 2001 From: Cyril Rohr Date: Sat, 8 Nov 2025 18:03:25 +0100 Subject: [PATCH] Add pre-commit hook support for roc lint - Add .pre-commit-hooks.yaml to enable pre-commit integration - Update README with pre-commit hook setup instructions - Update bump-readme to also bump pre-commit rev field --- .pre-commit-hooks.yaml | 8 ++++++++ Makefile | 8 ++++++++ README.md | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..54c18fb --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,8 @@ +- id: roc-lint + name: Lint runs-on.yml files + entry: roc lint + language: system + files: ^.*runs-on\.yml$ + pass_filenames: true + description: Validate runs-on.yml configuration files using roc lint + diff --git a/Makefile b/Makefile index 2beadc5..cfb6d5c 100644 --- a/Makefile +++ b/Makefile @@ -27,10 +27,12 @@ bump-readme: @VERSION=$$(echo $(TAG) | sed 's/^v//'); \ README_TAG=$$(grep -oE 'releases/download/v[0-9]+\.[0-9]+\.[0-9]+' README.md | head -n 1 | sed 's|releases/download/||'); \ README_VERSION=$$(echo $$README_TAG | sed 's/^v//'); \ + README_REV=$$(grep -oE 'rev: v[0-9]+\.[0-9]+\.[0-9]+' README.md | head -n 1 | sed 's|rev: ||'); \ if [ -z "$$README_TAG" ]; then \ echo "No version tag found in download URLs, updating placeholder versions"; \ sed -i.bak "s|v0\.0\.0|$(TAG)|g" README.md; \ sed -i.bak "s|roc_0\.0\.0|roc_$$VERSION|g" README.md; \ + sed -i.bak "s|rev: v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*|rev: $(TAG)|g" README.md; \ rm -f README.md.bak; \ else \ echo "Current tag: $(TAG)"; \ @@ -40,10 +42,16 @@ bump-readme: echo "Updating README.md: $$README_TAG -> $(TAG), roc_$$README_VERSION -> roc_$$VERSION"; \ sed -i.bak "s|releases/download/$$README_TAG|releases/download/$(TAG)|g" README.md; \ sed -i.bak "s|roc_$$README_VERSION|roc_$$VERSION|g" README.md; \ + sed -i.bak "s|rev: $$README_TAG|rev: $(TAG)|g" README.md; \ rm -f README.md.bak; \ else \ echo "README.md already contains $(TAG)"; \ fi; \ + if [ -n "$$README_REV" ] && [ "$$README_REV" != "$(TAG)" ]; then \ + echo "Updating pre-commit rev: $$README_REV -> $(TAG)"; \ + sed -i.bak "s|rev: $$README_REV|rev: $(TAG)|g" README.md; \ + rm -f README.md.bak; \ + fi; \ fi; \ if git diff --exit-code README.md > /dev/null 2>&1; then \ echo "README.md already up to date"; \ diff --git a/README.md b/README.md index e1a18ad..816874c 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,32 @@ else fi ``` +**Pre-commit hook:** + +You can use `roc lint` as a pre-commit hook to automatically validate `runs-on.yml` files before committing. First, install [pre-commit](https://pre-commit.com/): + +```bash +pip install pre-commit +``` + +Then add the hook to your `.pre-commit-config.yaml`: + +```yaml +repos: + - repo: https://github.com/runs-on/cli + rev: v0.1.12 # Use the latest release tag + hooks: + - id: roc-lint +``` + +Finally, install the git hook scripts: + +```bash +pre-commit install +``` + +Now `roc lint` will automatically run on staged `runs-on.yml` files before each commit. The commit will be blocked if validation errors are found. + ## Stack Management ### `roc stack doctor`