GitHub 操作:运行 golint on wihdows

GitHub Actions: Run golint on wihdows

我想 运行 在 windows 上 GitHub 操作中的 golint。

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

但是我遇到了这个错误:

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.

接下来我该做什么?

下面是我的.github/workflows/test.yaml。这适用于 Ubuntu 和 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 ./...

这是最小存储库:https://github.com/sanemat/use-golint-on-windows 这是拉取请求:https://github.com/sanemat/use-golint-on-windows/pull/2

another (deleted) answer所述,这是一个 PATH 问题。

改为使用此工作流程:

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 ./...