Skip to content

Go pre-commit hooks and environment variables #2237

@timuralp

Description

@timuralp

Hi there,

I'm struggling to figure out the best way to use Golang pre-commit hooks and set the Go environment variables (specifically, GOOS and GOARCH). It's the only way to inform Go that the code is meant to be compiled for a different platform/architecture. For example, when using linux system calls and running go vet on OS X, GOOS=linux is required.

I followed the discussion in #758 and #1157 and am not able to square the suggestions with the implementation of the script language (which is how all the Go hooks that I found are implemented -- https://github.com/TekWizely/pre-commit-golang, https://github.com/dnephin/pre-commit-golang, https://github.com/Bahjat/pre-commit-golang/blob/master/.pre-commit-hooks.yaml): https://github.com/pre-commit/pre-commit/blob/master/pre_commit/languages/script.py#L19

Specifically, as the consumer of the hook, I cannot modify the entry, as it will be prefixed with the pre-commit hook's directory, subsequently resulting in an ExecutableNotFoundError. What's the right way to use these hooks and pass in, for example, the GOOS environment variable? I think the answer today is: none of these hooks work on a platform different from the target. Is that right?

It would be great if I could specify a map of environment variables to be set when running the hook, but there is no such support via pre-commit itself or in any of the hooks. Is the only way to plumb through this support through a special argument that the hooks parse? Keeping their language as script seems sensible to me. Are there any other alternatives?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions