Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: example of how to pre-install actionlint when using pre-commit #268

Closed
wants to merge 2 commits into from

Conversation

gilesw
Copy link

@gilesw gilesw commented Feb 2, 2023

No description provided.

@rhysd
Copy link
Owner

rhysd commented Feb 4, 2023

I'm actually not a user of pre-commit (this file was added by community). Would you explain what this change does? I'm not understanding why the 'example' thing is necessary here.

@silven
Copy link

silven commented Feb 9, 2023

@gilesw, is this change intended to automatically install the executable? If so, that'd be awesome, as the current pre-commit hook is a bit of a burden in its current state.

@antdking
Copy link

antdking commented Feb 10, 2023

Now that pre-commit 3.0 added support for bootstrapping the go binary, it's a lot simpler to use actionlint through pre-commit.

While it'd be great to have this, pre-commit won't build, as it tries to build everything with go install ./....
This fails as it tries to build the playground without targeting JS.

Unfortunately, it means that language: golang can't be added to .pre-commit-hooks.yml when other parts of the codebase have specific constraints.

Build Error
An unexpected error has occurred: CalledProcessError: command: ('~/.cache/pre-commit/repoa95w4qhr/golangenv-1.19/.go/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/yuin/goldmark v1.5.3
    go: downloading gopkg.in/yaml.v3 v3.0.1
    go: downloading github.com/fatih/color v1.13.0
    go: downloading github.com/mattn/go-runewidth v0.0.14
    go: downloading github.com/mattn/go-colorable v0.1.13
    go: downloading github.com/robfig/cron v1.2.0
    go: downloading golang.org/x/sync v0.1.0
    go: downloading golang.org/x/sys v0.4.0
    go: downloading github.com/mattn/go-isatty v0.0.17
    go: downloading github.com/rivo/uniseg v0.4.3
    package github.com/rhysd/actionlint/playground
        imports syscall/js: build constraints exclude all Go files in ~/.cache/pre-commit/repoa95w4qhr/golangenv-1.19/.go/src/syscall/js

You can, however, use a Local Hook, with additional_dependencies in your own .pre-commit-config.yaml file.
A caveat of this approach is that pre-commit autoupdate will not update additional_dependencies for you.

Here's an example (I assume this is what the Giles was getting at):
Feel free to add to the Usage Docs.

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: actionlint
        name: Lint GitHub Actions workflow files
        description: Runs actionlint to lint GitHub Actions workflow files
        entry: actionlint
        language: golang
        language_version: "1.19"
        additional_dependencies: [github.com/rhysd/actionlint/cmd/actionlint@v1.6.23]
        types: ["yaml"]
        files: "^.github/workflows/"

@gilesw
Copy link
Author

gilesw commented Feb 15, 2023

@rhysd I copy and pasted that community file thinking it was how to use it with pre-commit as the official way, as others might do. I now use my modified stanza as it installs actionlint automatically. Works a treat in github actions. Possibly the stanza needs to be part of the Readme.md.

@s-weigand
Copy link

Following the workaround of @antdking, I created a mirror repo that auto-updates the version and uses golang as language.
There also is another mirror using python as language and downloading the binaries.

@rhysd
Copy link
Owner

rhysd commented Jun 14, 2023

Closing this PR in favor of #301. Now actionlint pre-commit hook is installed with Go toolchain.

@rhysd rhysd closed this Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants