feat: add pre-commit hook for validator #1002

Merged
earl-warren merged 1 commit from Freso/forgejo-runner:pre-commit into main 2025-09-18 08:08:57 +00:00
Contributor

This will allow users to validate their Forgejo Actions files (both actions and workflows) prior to committing them to their repositories, using a pre-commit configuration similar to

  - repo: https://code.forgejo.org/forgejo/runner
    rev: v11.1.0
    hooks:
      - id: forgejo-runner-validate
  • features
    • PR: feat: add pre-commit hook for validator
This will allow users to validate their Forgejo Actions files (both actions and workflows) prior to committing them to their repositories, using a `pre-commit` configuration similar to ```yaml - repo: https://code.forgejo.org/forgejo/runner rev: v11.1.0 hooks: - id: forgejo-runner-validate ``` <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/1002): <!--number 1002 --><!--line 0 --><!--description ZmVhdDogYWRkIHByZS1jb21taXQgaG9vayBmb3IgdmFsaWRhdG9y-->feat: add pre-commit hook for validator<!--description--> <!--end release-notes-assistant-->
@ -0,0 +4,4 @@
entry: forgejo-runner validate
args: ["--repository", "."]
language: golang
files: ^(\.(forgejo|github)/workflows/[^/]+|action)\.ya?ml$
Owner

some users my still use .gitea folder

some users my still use `.gitea` folder
Author
Contributor

Fixed!

Fixed!
Freso marked this conversation as resolved
Contributor

This is an excellent improvement 🙏 I did not know about that pre-commit technique.

Now... the not so easy part will be to add testing for it, to verify it works as it should. I assume you tried it manually already and I'm sure it works fine. But it needs automated testing to ensure no regression sneaks in later.

Let me know if you need help with that.

This is an excellent improvement 🙏 I did not know about that pre-commit technique. Now... the not so easy part will be to add testing for it, to verify it works as it should. I assume you tried it manually already and I'm sure it works fine. But it needs automated testing to ensure no regression sneaks in later. Let me know if you need help with that.
Author
Contributor

My intent of making this PR was a big motivation for forgejo/forgejo-actions-feature-requests#48 – since the current footprint is way larger than it needs to be, esp. if one wants to integrate pre-commit checks into an action or otherwise CI it, and possibly not able to cache the built thing (e.g., Forgejo Actions on Codeberg). :)


I guess one (simple) test would be to validate the file against the pre-commit-hooks (JSON) schema.

Another test could be to manually invoke pre-commit run forgejo-runner-validate on some test files and check that we get the expected pass or fail, though I’m not entirely sure how I’d go about this.

I assume forgejo-runner validate has its own battery of tests, so there’s no need to duplicate those here. I’m not sure how/if other projects test pre-commit-hooks files.

I’ll try and expand the PR with at least a test validating the hooks file against the schema. Maybe it’ll be more clear to me how to add more/other tests in the process of doing this.

My intent of making this PR was a big motivation for https://code.forgejo.org/forgejo/forgejo-actions-feature-requests/issues/48 – since the current footprint is way larger than it needs to be, esp. if one wants to integrate `pre-commit` checks into an action or otherwise CI it, and possibly not able to cache the built thing (e.g., Forgejo Actions on Codeberg). :) ----- I guess one (simple) test would be to validate the file against the [`pre-commit-hooks` (JSON) schema](https://www.schemastore.org/pre-commit-hooks.json). Another test could be to manually invoke `pre-commit run forgejo-runner-validate` on some test files and check that we get the expected pass or fail, though I’m not entirely sure how I’d go about this. I assume `forgejo-runner validate` has its own battery of tests, so there’s no need to duplicate those here. I’m not sure how/if other projects test `pre-commit-hooks` files. I’ll try and expand the PR with at least a test validating the hooks file against the schema. Maybe it’ll be more clear to me how to add more/other tests in the process of doing this.
Freso force-pushed pre-commit from 1f6fdbeb3c
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate mocks (pull_request) Successful in 1m1s
checks / build and test (pull_request) Successful in 2m56s
checks / runner exec tests (pull_request) Successful in 26s
checks / runner integration tests (pull_request) Successful in 4m44s
checks / integration tests (pull_request) Successful in 10m58s
to 418232196b
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Failing after 7s
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 35s
checks / build and test (pull_request) Successful in 44s
checks / runner exec tests (pull_request) Successful in 28s
checks / runner integration tests (pull_request) Successful in 4m14s
checks / integration tests (pull_request) Successful in 10m52s
2025-09-16 11:05:32 +00:00
Compare
Freso force-pushed pre-commit from 418232196b
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Failing after 7s
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 35s
checks / build and test (pull_request) Successful in 44s
checks / runner exec tests (pull_request) Successful in 28s
checks / runner integration tests (pull_request) Successful in 4m14s
checks / integration tests (pull_request) Successful in 10m52s
to d5bb189011
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 4s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 43s
checks / build and test (pull_request) Successful in 51s
checks / runner exec tests (pull_request) Successful in 29s
checks / runner integration tests (pull_request) Successful in 5m1s
checks / integration tests (pull_request) Successful in 11m7s
2025-09-16 11:26:31 +00:00
Compare
Freso force-pushed pre-commit from d5bb189011
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 4s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 43s
checks / build and test (pull_request) Successful in 51s
checks / runner exec tests (pull_request) Successful in 29s
checks / runner integration tests (pull_request) Successful in 5m1s
checks / integration tests (pull_request) Successful in 11m7s
to a87970e187
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Failing after 5s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 35s
checks / build and test (pull_request) Successful in 43s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m17s
checks / integration tests (pull_request) Successful in 10m17s
2025-09-16 11:51:13 +00:00
Compare
Freso force-pushed pre-commit from a87970e187
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Failing after 5s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 35s
checks / build and test (pull_request) Successful in 43s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m17s
checks / integration tests (pull_request) Successful in 10m17s
to 8cda0aecee
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 7s
checks / validate mocks (pull_request) Successful in 36s
checks / build and test (pull_request) Successful in 45s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m27s
checks / integration tests (pull_request) Successful in 10m24s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
2025-09-16 11:56:08 +00:00
Compare
Author
Contributor

Okay, there’s now a “validate pre-commit-hooks file” job in the action workflows.

I guess one way to additionally test its functionality could be to make some test action/workflow files (in .forgejo/testdata?), and then expand the new job to something like:

  1. mkdir forgejo-runner-validate-test
  2. git init
  3. pre-commit install-hooks
    1. cp -R ../.forgejo/testdata/pre-commit-hook/good/* ./
      1. git add .
      2. git commit -m 'test commit'
      3. commits!
    2. cp -R ../.forgejo/testdata/pre-commit-hook/bad/* ./
      1. git add .
      2. git commit -m 'test commit'
      3. doesn’t commit!

I’m not really sure how or if to take the automated testing further, so any suggestions for what additional testing needs to happen would be welcome!

Okay, there’s now a “validate pre-commit-hooks file” job in the action workflows. I guess one way to additionally test its functionality could be to make some test action/workflow files (in `.forgejo/testdata`?), and then expand the new job to something like: 1. `mkdir forgejo-runner-validate-test` 2. `git init` 3. `pre-commit install-hooks` 1. `cp -R ../.forgejo/testdata/pre-commit-hook/good/* ./` 1. `git add .` 2. `git commit -m 'test commit'` 3. commits! 1. `cp -R ../.forgejo/testdata/pre-commit-hook/bad/* ./` 1. `git add .` 2. `git commit -m 'test commit'` 3. doesn’t commit! I’m not really sure how or if to take the automated testing further, so any suggestions for what additional testing needs to happen would be welcome!
Contributor

#1002/files is a good start. 👍

I guess one way to additionally test its functionality could be to make some test action/workflow files (in .forgejo/testdata?), and then expand the new job to something like:

That sounds perfect. You can obtain the runner compiled from the pull request like so:

8cda0aecee/.forgejo/workflows/test.yml (L84-L89)

https://code.forgejo.org/forgejo/runner/pulls/1002/files#diff-e279008ee2688efff2d624322ae03dff2e9c0cc3 is a good start. 👍 > I guess one way to additionally test its functionality could be to make some test action/workflow files (in .forgejo/testdata?), and then expand the new job to something like: That sounds perfect. You can obtain the runner compiled from the pull request like so: https://code.forgejo.org/forgejo/runner/src/commit/8cda0aeceec6e734415113b5132da8f5639e1e30/.forgejo/workflows/test.yml#L84-L89
Author
Contributor

That sounds perfect.

Okay, so, uh… What exactly do you want tested? Just that a valid workflow passes and a non-valid workflow fails? Do you want action.ya?ml tested too? Different file names? I’m a bit overwhelmed by the possibilities, hence why I asked for more guidance on how/what to test further. 🙇

Another (additional?) option could be to add /.pre-commit-config.yaml to run the pre-commit hook on this repository itself, which would hopefully also help with catching any regressions.


You can obtain the runner compiled from the pull request

That won’t really help with the pre-commit hook, since that’ll want to build it itself in its own “container”-like thing. (Again, another reason for forgejo/forgejo-actions-feature-requests#48 :) )

> That sounds perfect. Okay, so, uh… What exactly do you want tested? Just that a valid workflow passes and a non-valid workflow fails? Do you want `action.ya?ml` tested too? Different file names? I’m a bit overwhelmed by the possibilities, hence why I asked for more guidance on how/what to test further. 🙇 Another (additional?) option could be to add `/.pre-commit-config.yaml` to run the `pre-commit` hook on this repository itself, which would hopefully also help with catching any regressions. ----- > You can obtain the runner compiled from the pull request That won’t really help with the `pre-commit` hook, since that’ll want to build it itself in its own “container”-like thing. (Again, another reason for https://code.forgejo.org/forgejo/forgejo-actions-feature-requests/issues/48 :) )
Contributor

Okay, so, uh… What exactly do you want tested? Just that a valid workflow passes and a non-valid workflow fails?

Yes, that would be perfect. After this is done, more refinements can be added but that would be proof enough that the hook actually works. It would, for instance, guard against a regression where someone editing the hook in the future changes:

args: ["--repository", "."]

to

args: ["--repo<typo>sitory", "."]

by accident.

> Okay, so, uh… What exactly do you want tested? Just that a valid workflow passes and a non-valid workflow fails? Yes, that would be perfect. After this is done, more refinements can be added but that would be proof enough that the hook actually works. It would, for instance, guard against a regression where someone editing the hook in the future changes: ```yaml args: ["--repository", "."] ``` to ```yaml args: ["--repo<typo>sitory", "."] ``` by accident.
Contributor

Note that once this is merged it should also be documented somewhere in https://forgejo.org/docs/next/user/actions/troubleshooting/ and a new section at https://forgejo.org/docs/next/user/actions/advanced-features/. I think it deserves to be the first section there, it is going to help a lot.

Note that once this is merged it should also be documented somewhere in https://forgejo.org/docs/next/user/actions/troubleshooting/ and a new section at https://forgejo.org/docs/next/user/actions/advanced-features/. I think it deserves to be the first section there, it is going to help a lot.
Author
Contributor

During additional testing to get the automated testing working… I realised some unwanted behaviour (or lack of behaviour): forgejo/forgejo-actions-feature-requests#51 – so I’ll probably consider this blocked by that and leave this PR be until forgejo/forgejo-actions-feature-requests#51 is implemented. :)

During additional testing to get the automated testing working… I realised some unwanted behaviour (or lack of behaviour): https://code.forgejo.org/forgejo/forgejo-actions-feature-requests/issues/51 – so I’ll probably consider this blocked by that and leave this PR be until https://code.forgejo.org/forgejo/forgejo-actions-feature-requests/issues/51 is implemented. :)
Freso changed title from feat: Add pre-commit hook for validator to WIP: feat: Add pre-commit hook for validator [blocked] 2025-09-16 15:51:35 +00:00
Contributor

You can validate --clonedir . --repository . to avoid cloning when at the root of the repository.

You can `validate --clonedir . --repository .` to avoid cloning when at the root of the repository.
Freso force-pushed pre-commit from 8cda0aecee
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 7s
checks / validate mocks (pull_request) Successful in 36s
checks / build and test (pull_request) Successful in 45s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m27s
checks / integration tests (pull_request) Successful in 10m24s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
to ab4f2549c5
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Failing after 26s
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate mocks (pull_request) Successful in 53s
checks / build and test (pull_request) Successful in 2m37s
checks / runner exec tests (pull_request) Successful in 22s
/ example-lxc-systemd (pull_request) Successful in 6m12s
checks / runner integration tests (pull_request) Successful in 4m24s
checks / integration tests (pull_request) Successful in 10m8s
2025-09-16 17:26:17 +00:00
Compare
Freso changed title from WIP: feat: Add pre-commit hook for validator [blocked] to feat: Add pre-commit hook for validator 2025-09-16 17:26:43 +00:00
Freso force-pushed pre-commit from ab4f2549c5
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Failing after 26s
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate mocks (pull_request) Successful in 53s
checks / build and test (pull_request) Successful in 2m37s
checks / runner exec tests (pull_request) Successful in 22s
/ example-lxc-systemd (pull_request) Successful in 6m12s
checks / runner integration tests (pull_request) Successful in 4m24s
checks / integration tests (pull_request) Successful in 10m8s
to 967a8005ed
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 0s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 35s
checks / build and test (pull_request) Successful in 45s
checks / runner exec tests (pull_request) Successful in 28s
checks / runner integration tests (pull_request) Successful in 4m32s
/ example-lxc-systemd (pull_request) Successful in 6m11s
checks / integration tests (pull_request) Successful in 10m26s
2025-09-16 17:44:25 +00:00
Compare
Freso force-pushed pre-commit from 967a8005ed
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 0s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 35s
checks / build and test (pull_request) Successful in 45s
checks / runner exec tests (pull_request) Successful in 28s
checks / runner integration tests (pull_request) Successful in 4m32s
/ example-lxc-systemd (pull_request) Successful in 6m11s
checks / integration tests (pull_request) Successful in 10m26s
to 4c107493ca
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 25s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate mocks (pull_request) Successful in 41s
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / build and test (pull_request) Successful in 49s
checks / runner exec tests (pull_request) Successful in 27s
checks / runner integration tests (pull_request) Successful in 4m25s
/ example-lxc-systemd (pull_request) Successful in 6m33s
checks / integration tests (pull_request) Successful in 11m28s
2025-09-16 17:47:40 +00:00
Compare
Freso force-pushed pre-commit from 4c107493ca
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 25s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate mocks (pull_request) Successful in 41s
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / build and test (pull_request) Successful in 49s
checks / runner exec tests (pull_request) Successful in 27s
checks / runner integration tests (pull_request) Successful in 4m25s
/ example-lxc-systemd (pull_request) Successful in 6m33s
checks / integration tests (pull_request) Successful in 11m28s
to b21e5e4bbe
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate pre-commit-hooks file (pull_request) Failing after 24s
checks / validate mocks (pull_request) Successful in 40s
checks / build and test (pull_request) Successful in 47s
checks / runner exec tests (pull_request) Successful in 26s
checks / runner integration tests (pull_request) Successful in 5m1s
/ example-lxc-systemd (pull_request) Successful in 6m25s
checks / integration tests (pull_request) Successful in 12m7s
2025-09-16 18:00:49 +00:00
Compare
Freso force-pushed pre-commit from b21e5e4bbe
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate pre-commit-hooks file (pull_request) Failing after 24s
checks / validate mocks (pull_request) Successful in 40s
checks / build and test (pull_request) Successful in 47s
checks / runner exec tests (pull_request) Successful in 26s
checks / runner integration tests (pull_request) Successful in 5m1s
/ example-lxc-systemd (pull_request) Successful in 6m25s
checks / integration tests (pull_request) Successful in 12m7s
to 23f4d991bd
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 27s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate mocks (pull_request) Successful in 47s
checks / build and test (pull_request) Successful in 52s
checks / runner exec tests (pull_request) Successful in 29s
checks / runner integration tests (pull_request) Successful in 5m8s
/ example-lxc-systemd (pull_request) Successful in 6m32s
checks / integration tests (pull_request) Successful in 12m56s
2025-09-16 18:03:05 +00:00
Compare
Freso force-pushed pre-commit from 23f4d991bd
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Failing after 27s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate mocks (pull_request) Successful in 47s
checks / build and test (pull_request) Successful in 52s
checks / runner exec tests (pull_request) Successful in 29s
checks / runner integration tests (pull_request) Successful in 5m8s
/ example-lxc-systemd (pull_request) Successful in 6m32s
checks / integration tests (pull_request) Successful in 12m56s
to 90418423fa
Some checks failed
checks / build and test (pull_request) Successful in 51s
checks / validate mocks (pull_request) Successful in 41s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate pre-commit-hooks file (pull_request) Failing after 39s
checks / runner exec tests (pull_request) Successful in 28s
/ example-lxc-systemd (pull_request) Successful in 6m44s
checks / runner integration tests (pull_request) Successful in 5m10s
checks / integration tests (pull_request) Successful in 12m19s
2025-09-16 18:05:36 +00:00
Compare
Freso force-pushed pre-commit from 90418423fa
Some checks failed
checks / build and test (pull_request) Successful in 51s
checks / validate mocks (pull_request) Successful in 41s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate pre-commit-hooks file (pull_request) Failing after 39s
checks / runner exec tests (pull_request) Successful in 28s
/ example-lxc-systemd (pull_request) Successful in 6m44s
checks / runner integration tests (pull_request) Successful in 5m10s
checks / integration tests (pull_request) Successful in 12m19s
to a289965b5e
Some checks failed
checks / build and test (pull_request) Successful in 53s
checks / validate mocks (pull_request) Successful in 48s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate pre-commit-hooks file (pull_request) Failing after 59s
checks / runner exec tests (pull_request) Successful in 33s
checks / runner integration tests (pull_request) Successful in 4m53s
/ example-lxc-systemd (pull_request) Successful in 6m44s
checks / integration tests (pull_request) Successful in 11m46s
2025-09-16 18:11:39 +00:00
Compare
Author
Contributor

Is forgejo-runner supposed to build and install correctly using go install ./... at the root of the repository?

Is `forgejo-runner` supposed to build and install correctly using `go install ./...` at the root of the repository?
@ -225,0 +250,4 @@
- name: validate .pre-commit-hooks.yaml
run: pre-commit validate-manifest .pre-commit-hooks.yaml
Contributor

You can obtain the runner compiled from the pull request by inserting those steps here:

8cda0aecee/.forgejo/workflows/test.yml (L84-L89)

you can probably move it to /usr/local/bin so it is in the PATH

You can obtain the runner compiled from the pull request by inserting those steps here: https://code.forgejo.org/forgejo/runner/src/commit/8cda0aeceec6e734415113b5132da8f5639e1e30/.forgejo/workflows/test.yml#L84-L89 you can probably move it to `/usr/local/bin` so it is in the PATH
Author
Contributor

Yes, but that’s not how pre-commit works (or is supposed to work), at least for non-language: system. One of the ideas of pre-commit is that developers don’t need to manually install all the tools for the checks themselves, but rather have pre-commit handle that part.

Some of the best linters are written in languages that you do not use in your project or have installed on your machine. For example scss-lint is a linter for SCSS written in Ruby. If you’re writing a project in node you should be able to use scss-lint as a pre-commit hook without adding a Gemfile to your project or understanding how to get scss-lint installed.

For language: golang hooks, pre-commit will build and install them using go install ./...:

The hook repository must contain go source code. It will be installed via go install ./.... pre-commit will create an isolated GOPATH for each hook and the entry should match an executable which will get installed into the GOPATH's bin directory.

I tried running go install ./... locally and didn’t find any forgejo-runner executable afterwards, hence my question whether that is supposed to work here.

Yes, but that’s not how `pre-commit` works (or is supposed to work), at least for non-`language: system`. One of the ideas of `pre-commit` is that developers don’t need to manually install all the tools for the checks themselves, but rather have `pre-commit` handle that part. > Some of the best linters are written in languages that you do not use in your project or have installed on your machine. For example scss-lint is a linter for SCSS written in Ruby. If you’re writing a project in node you should be able to use scss-lint as a pre-commit hook without adding a Gemfile to your project or understanding how to get scss-lint installed. For [`language: golang` hooks](https://pre-commit.com/#golang), `pre-commit` will build and install them using `go install ./...`: > The hook repository must contain go source code. It will be installed via `go install ./...`. pre-commit will create an isolated `GOPATH` for each hook and the `entry` should match an executable which will get installed into the `GOPATH`'s `bin` directory. I tried running `go install ./...` locally and didn’t find any `forgejo-runner` executable afterwards, hence my question whether that is supposed to work here.
Contributor

Thanks for explaining so patiently, I'm learning a lot 😁

I tried running go install ./... locally and didn’t find any forgejo-runner...

I tried and found that it is installed under the name runner.

Thanks for explaining so patiently, I'm learning a lot 😁 > I tried running go install ./... locally and didn’t find any forgejo-runner... I tried and found that it is installed under the name `runner`.
Author
Contributor

Yahaha! Found it! 🌱

Thank you! :)

Yahaha! Found it! 🌱 Thank you! :)
Freso marked this conversation as resolved
@ -0,0 +5,4 @@
# Hopefully there will be a less hacky way to do this in the future :)
# https://code.forgejo.org/forgejo/forgejo-actions-feature-requests/issues/51
args: ['--repository', '.', '--clonedir', '.']
language: golang
Contributor

Although that would work fine, it seems to require a lot of resources when validating workflows/actions in environments where Go is not in use at all.

Wouldn't it be lighter to instead use something like script that downloads the required version of the runner if not already available?

It is just a question: as long as it works it is fine by me.

Although that would work fine, it seems to require a lot of resources when validating workflows/actions in environments where Go is not in use at all. Wouldn't it be lighter to instead use something like [script](https://pre-commit.com/#script) that downloads the required version of the runner if not already available? It is just a question: as long as it works it is fine by me.
Author
Contributor

I’m considering adding both a -script and a -system variant (see e.g., how actionlint provides a -docker and a -system in addition to the language: golang hook), but sticking to the core concept for now/for this PR, to not have it balloon too much. :)

I’m considering adding both a `-script` and a `-system` variant (see e.g., [how `actionlint` provides a `-docker` and a `-system` in addition to the `language: golang` hook](https://github.com/rhysd/actionlint/blob/main/.pre-commit-hooks.yaml)), but sticking to the core concept for now/for this PR, to not have it balloon too much. :)
Freso marked this conversation as resolved
Freso force-pushed pre-commit from a289965b5e
Some checks failed
checks / build and test (pull_request) Successful in 53s
checks / validate mocks (pull_request) Successful in 48s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate pre-commit-hooks file (pull_request) Failing after 59s
checks / runner exec tests (pull_request) Successful in 33s
checks / runner integration tests (pull_request) Successful in 4m53s
/ example-lxc-systemd (pull_request) Successful in 6m44s
checks / integration tests (pull_request) Successful in 11m46s
to 00311f0545
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 50s
checks / validate pre-commit-hooks file (pull_request) Failing after 48s
checks / runner exec tests (pull_request) Successful in 27s
checks / runner integration tests (pull_request) Successful in 4m15s
/ example-lxc-systemd (pull_request) Successful in 6m6s
checks / integration tests (pull_request) Successful in 10m43s
2025-09-17 07:46:28 +00:00
Compare
Freso force-pushed pre-commit from 00311f0545
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 50s
checks / validate pre-commit-hooks file (pull_request) Failing after 48s
checks / runner exec tests (pull_request) Successful in 27s
checks / runner integration tests (pull_request) Successful in 4m15s
/ example-lxc-systemd (pull_request) Successful in 6m6s
checks / integration tests (pull_request) Successful in 10m43s
to 2bd48807f8
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 47s
checks / validate pre-commit-hooks file (pull_request) Failing after 52s
checks / runner exec tests (pull_request) Successful in 32s
checks / runner integration tests (pull_request) Successful in 4m22s
/ example-lxc-systemd (pull_request) Successful in 6m25s
checks / integration tests (pull_request) Successful in 10m35s
2025-09-17 07:52:31 +00:00
Compare
Freso force-pushed pre-commit from 2bd48807f8
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 47s
checks / validate pre-commit-hooks file (pull_request) Failing after 52s
checks / runner exec tests (pull_request) Successful in 32s
checks / runner integration tests (pull_request) Successful in 4m22s
/ example-lxc-systemd (pull_request) Successful in 6m25s
checks / integration tests (pull_request) Successful in 10m35s
to 3944762bd1
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 38s
checks / build and test (pull_request) Successful in 48s
checks / runner exec tests (pull_request) Successful in 34s
checks / runner integration tests (pull_request) Successful in 4m15s
/ example-lxc-systemd (pull_request) Successful in 6m9s
checks / integration tests (pull_request) Successful in 10m44s
2025-09-17 08:21:01 +00:00
Compare
Freso force-pushed pre-commit from 3944762bd1
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 38s
checks / build and test (pull_request) Successful in 48s
checks / runner exec tests (pull_request) Successful in 34s
checks / runner integration tests (pull_request) Successful in 4m15s
/ example-lxc-systemd (pull_request) Successful in 6m9s
checks / integration tests (pull_request) Successful in 10m44s
to b2f0c2b7a3
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 8s
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 47s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m53s
/ example-lxc-systemd (pull_request) Successful in 6m24s
checks / integration tests (pull_request) Successful in 11m2s
2025-09-17 08:46:21 +00:00
Compare
Freso force-pushed pre-commit from b2f0c2b7a3
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 8s
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 47s
checks / runner exec tests (pull_request) Successful in 25s
checks / runner integration tests (pull_request) Successful in 4m53s
/ example-lxc-systemd (pull_request) Successful in 6m24s
checks / integration tests (pull_request) Successful in 11m2s
to b4151f51b4
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 34s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate mocks (pull_request) Successful in 46s
checks / build and test (pull_request) Successful in 52s
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / runner exec tests (pull_request) Successful in 28s
checks / runner integration tests (pull_request) Successful in 4m32s
/ example-lxc-systemd (pull_request) Successful in 6m30s
checks / integration tests (pull_request) Successful in 11m28s
2025-09-17 08:48:44 +00:00
Compare
Freso force-pushed pre-commit from b4151f51b4
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 34s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate mocks (pull_request) Successful in 46s
checks / build and test (pull_request) Successful in 52s
issue-labels / release-notes (pull_request_target) Successful in 6s
checks / runner exec tests (pull_request) Successful in 28s
checks / runner integration tests (pull_request) Successful in 4m32s
/ example-lxc-systemd (pull_request) Successful in 6m30s
checks / integration tests (pull_request) Successful in 11m28s
to 1da07b5acf
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 8s
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 44s
checks / build and test (pull_request) Successful in 48s
checks / runner exec tests (pull_request) Successful in 30s
checks / runner integration tests (pull_request) Successful in 4m19s
/ example-lxc-systemd (pull_request) Successful in 6m15s
checks / integration tests (pull_request) Successful in 11m22s
2025-09-17 09:02:27 +00:00
Compare
Freso force-pushed pre-commit from 1da07b5acf
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 8s
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 44s
checks / build and test (pull_request) Successful in 48s
checks / runner exec tests (pull_request) Successful in 30s
checks / runner integration tests (pull_request) Successful in 4m19s
/ example-lxc-systemd (pull_request) Successful in 6m15s
checks / integration tests (pull_request) Successful in 11m22s
to 4f400d6d8b
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 38s
checks / build and test (pull_request) Successful in 48s
checks / runner exec tests (pull_request) Successful in 26s
checks / runner integration tests (pull_request) Successful in 4m51s
/ example-lxc-systemd (pull_request) Successful in 6m20s
checks / integration tests (pull_request) Failing after 10m37s
2025-09-17 09:13:07 +00:00
Compare
Freso force-pushed pre-commit from 4f400d6d8b
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 38s
checks / build and test (pull_request) Successful in 48s
checks / runner exec tests (pull_request) Successful in 26s
checks / runner integration tests (pull_request) Successful in 4m51s
/ example-lxc-systemd (pull_request) Successful in 6m20s
checks / integration tests (pull_request) Failing after 10m37s
to 66b2ab0f74
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 37s
cascade / forgejo (pull_request_target) Has been skipped
checks / validate mocks (pull_request) Successful in 44s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / build and test (pull_request) Successful in 52s
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / runner exec tests (pull_request) Successful in 27s
checks / runner integration tests (pull_request) Successful in 4m36s
/ example-lxc-systemd (pull_request) Successful in 6m32s
checks / integration tests (pull_request) Successful in 11m42s
2025-09-17 09:15:32 +00:00
Compare
Author
Contributor

Okay, seems like everything’s working on the pre-commit side now!

Two issues which I believe lie with forgejo-runner validate:

  1. validate always exits with code 0 (success) regardless of whether validation succeeded or failed, which in turn means that pre-commit doesn’t get a signal that it didn’t validate. As a workaround, I’ve set the hook to always be verbose so end-users can at least see the validate output in case anything doesn’t pass.
  2. validate doesn’t only check action.ya?ml in the root of the repository, but rather checks any action.ya?ml file in the repository. This causes forgejo-runner validate to fail (well, except for point 1. :) ) on https://code.forgejo.org/forgejo/runner since there is a deliberately bad action.yml testdata file (act/runner/testdata/local-action-fails-schema-validation/action/action.yml).
    I’m not quite sure what the best way to deal with this is, but this is unlikely to be an issue for a lot of repositories besides this one, so it can be worked around on a local basis where/when/if needed.

I can open separate issues for these (if there aren’t any already), but I think these are outside the scope of this PR.

Okay, seems like everything’s working on the `pre-commit` side now! Two issues which I believe lie with `forgejo-runner validate`: 1. `validate` always exits with code 0 (success) regardless of whether validation succeeded or failed, which in turn means that `pre-commit` doesn’t get a signal that it didn’t validate. As a workaround, I’ve set the hook to always be `verbose` so end-users can at least see the validate output in case anything doesn’t pass. 2. `validate` doesn’t only check `action.ya?ml` in the root of the repository, but rather checks _any_ `action.ya?ml` file in the repository. This causes `forgejo-runner validate` to fail (well, except for point 1. :) ) on https://code.forgejo.org/forgejo/runner since there is a deliberately bad `action.yml` testdata file (`act/runner/testdata/local-action-fails-schema-validation/action/action.yml`). I’m not quite sure what the best way to deal with this is, but this is unlikely to be an issue for a lot of repositories besides this one, so it can be worked around on a local basis where/when/if needed. I can open separate issues for these (if there aren’t any already), but I think these are outside the scope of this PR.
Freso force-pushed pre-commit from 66b2ab0f74
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 37s
cascade / forgejo (pull_request_target) Has been skipped
checks / validate mocks (pull_request) Successful in 44s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / build and test (pull_request) Successful in 52s
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / runner exec tests (pull_request) Successful in 27s
checks / runner integration tests (pull_request) Successful in 4m36s
/ example-lxc-systemd (pull_request) Successful in 6m32s
checks / integration tests (pull_request) Successful in 11m42s
to 2214ac4e36
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 47s
checks / runner exec tests (pull_request) Successful in 24s
checks / runner integration tests (pull_request) Successful in 4m43s
checks / integration tests (pull_request) Successful in 11m2s
issue-labels / release-notes (pull_request_target) Successful in 5s
2025-09-17 09:29:35 +00:00
Compare
earl-warren changed title from feat: Add pre-commit hook for validator to feat: add pre-commit hook for validator 2025-09-17 09:48:20 +00:00
Contributor

validate doesn’t only check action.ya?ml in the root of the repository, but rather checks any action.ya?ml

Yes, because actions can exist in sub-directories and there really are no rules to figure out where they are. I think it is fine if the pre-commit hook does not work for the runner repository itself as a first implementation. And this is likely the only repository where a deliberately corrupted action is to be found 😁

> validate doesn’t only check action.ya?ml in the root of the repository, but rather checks any action.ya?ml Yes, because actions can exist in sub-directories and there really are no rules to figure out where they are. I think it is fine if the pre-commit hook does not work for the runner repository itself as a first implementation. And this is likely the only repository where a deliberately corrupted action is to be found 😁
Contributor

@Freso wrote in #1002 (comment):

  1. validate always exits with code 0 (success) regardless of whether validation succeeded or failed

I will send a fix for that today.

@Freso wrote in https://code.forgejo.org/forgejo/runner/pulls/1002#issuecomment-60464: > 1. `validate` always exits with code 0 (success) regardless of whether validation succeeded or failed I will send a fix for that today.
Contributor
- https://code.forgejo.org/forgejo/runner/pulls/1008 - https://code.forgejo.org/forgejo/runner/pulls/1009
Freso force-pushed pre-commit from 2214ac4e36
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 47s
checks / runner exec tests (pull_request) Successful in 24s
checks / runner integration tests (pull_request) Successful in 4m43s
checks / integration tests (pull_request) Successful in 11m2s
issue-labels / release-notes (pull_request_target) Successful in 5s
to c9498b877d
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate pre-commit-hooks file (pull_request) Successful in 36s
checks / validate mocks (pull_request) Successful in 45s
checks / build and test (pull_request) Successful in 52s
checks / runner exec tests (pull_request) Successful in 29s
checks / runner integration tests (pull_request) Successful in 5m13s
checks / integration tests (pull_request) Successful in 11m20s
2025-09-17 16:59:08 +00:00
Compare
earl-warren force-pushed pre-commit from c9498b877d
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate pre-commit-hooks file (pull_request) Successful in 36s
checks / validate mocks (pull_request) Successful in 45s
checks / build and test (pull_request) Successful in 52s
checks / runner exec tests (pull_request) Successful in 29s
checks / runner integration tests (pull_request) Successful in 5m13s
checks / integration tests (pull_request) Successful in 11m20s
to ba17b0dde6
All checks were successful
issue-labels / release-notes (pull_request_target) Successful in 8s
checks / validate pre-commit-hooks file (pull_request) Successful in 32s
checks / validate mocks (pull_request) Successful in 39s
checks / build and test (pull_request) Successful in 50s
checks / runner exec tests (pull_request) Successful in 30s
checks / runner integration tests (pull_request) Successful in 4m30s
checks / integration tests (pull_request) Successful in 11m39s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 4s
cascade / forgejo (pull_request_target) Successful in 1m48s
2025-09-18 07:57:11 +00:00
Compare
earl-warren scheduled this pull request to auto merge when all checks succeed 2025-09-18 07:57:28 +00:00
earl-warren deleted branch pre-commit 2025-09-18 08:08:57 +00:00
Author
Contributor

PR for documentation additions/updates: https://codeberg.org/forgejo/docs/pulls/1495

PR for documentation additions/updates: https://codeberg.org/forgejo/docs/pulls/1495
Sign in to join this conversation.
No reviewers
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
forgejo/runner!1002
No description provided.