GitHub Actions: Run golint on wihdows

1.6k views Asked by At

I want to run golint on windows in GitHub Actions.

go install golang.org/x/lint/golint
golint ./...

But I met this error:

golint : The term 'golint' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\a\_temp\dd1f47cc-42be-445e-9300-b2b5fbfd04da.ps1:4 char:1
+ golint ./...
+ ~~~~~~
+ CategoryInfo          : ObjectNotFound: (golint:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException

##[error]Process completed with exit code 1.

What do I do next?

This is my .github/workflows/test.yaml below. This works well on Ubuntu and Mac.

name: test
on:
  push:
    branches:
    - "**"
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
        - ubuntu-latest
        - macOS-latest
        - windows-latest
    steps:
    - name: setup env unix
      run: |
        echo ::set-env name=GOPATH::${{ runner.workspace }}
        echo ::add-path::${{ runner.workspace }}/bin
      if: "matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'"
    - name: setup env windows
      run: |
        echo ::set-env name=GOPATH::${{ runner.workspace }}
        echo ::add-path::${{ runner.workspace }}\bin
      if: "matrix.os == 'windows-latest'"
    - name: setup go
      uses: actions/setup-go@v1
      with:
        go-version: 1.x
    - name: checkout
      uses: actions/checkout@v1
      with:
        fetch-depth: 1
        path: src/github.com/${{ github.repository }}
    - name: golint
      run: |
        go env
        go install golang.org/x/lint/golint
        golint ./...

This is the minimal repository: https://github.com/sanemat/use-golint-on-windows This is the pull request: https://github.com/sanemat/use-golint-on-windows/pull/2

1

There are 1 answers

0
smac89 On BEST ANSWER

As another (deleted) answer mentioned, this is a PATH issue.

Use this workflow instead:

name: test
on:
  push:
    branches:
    - "**"
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
        - ubuntu-latest
        - macOS-latest
        - windows-latest
    steps:
    - name: setup go
      uses: actions/setup-go@v1
      with:
        go-version: 1.x
    - name: setup env
      run: |
        echo "::set-env name=GOPATH::$(go env GOPATH)"
        echo "::add-path::$(go env GOPATH)/bin"
      shell: bash
    - name: checkout
      uses: actions/checkout@v1
      with:
        fetch-depth: 1
        path: src/github.com/${{ github.repository }}
    - name: golint
      run: |
        go env
        go install golang.org/x/lint/golint
        golint ./...