run pre-commit.com script for golang in github actions

Issue

This Content is from Stack Overflow. Question asked by lgl1

I’m trying to run pre-commit.com script with some hooks related to golang in github actions. Seems like the testing environment lack of some tools to execute go-imports and golangci-lint.
I’ve added steps for setting up required tools in the environment prior to pre-commit step, but it doesn’t help.

pre-commit-config.yaml:

repos:
- repo: https://github.com/dnephin/pre-commit-golang
  rev: v0.5.0
  hooks:
    - id: go-imports
    - id: golangci-lint
    - id: go-unit-tests

github action config:

name: pre-commit

on:
  pull_request:
  push:
    branches: [main]
jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
    - uses: actions/setup-go@v3
    - run: go install golang.org/x/tools/cmd/goimports@latest
    - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
    - uses: pre-commit/a

Gihub Action Output:
all go invironments set-up steps completed successfully

Details of pre-commit/action@v2.0.2:

[...]
[INFO] This may take a few minutes...
go imports...............................................................Failed
- hook id: go-imports
- exit code: 127

/home/runner/.cache/pre-commit/repow0byklud/run-go-imports.sh: line 8: goimports: command not found

golangci-lint............................................................Failed
- hook id: golangci-lint
- exit code: 127

/home/runner/.cache/pre-commit/repow0byklud/run-golangci-lint.sh: 2: exec: golangci-lint: not found

go-unit-tests............................................................Passed
[...]



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?