<commit_before># Copyright 2020 The Periph Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.

# References:
# https://developer.github.com/webhooks/event-payloads/
# https://github.com/actions/cache
# https://github.com/actions/checkout
# https://github.com/actions/setup-go
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#using-the-github_token-in-a-workflow
# https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions/
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions

on: [push, pull_request]
name: Run tests
jobs:
  test_all:
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        gover: ['1.14.3']
    runs-on: "${{matrix.os}}"
    name: "go${{matrix.gover}} on ${{matrix.os}}"
    steps:
    - uses: actions/setup-go@v2
      with:
        go-version: "^${{matrix.gover}}"
    - name: 'Cache: ~/go/pkg/mod'
      uses: actions/cache@v1
      with:
        path: "~/go/pkg/mod"
        # We want a key that helps with keeping the tools.
        key: "${{runner.os}}-gopkg-${{hashFiles('~/go/pkg/**/go.sum')}}"
        restore-keys: "${{runner.os}}-gopkg-"

      # Fetch the tools before checking out, so they don't modify go.mod/go.sum.
    - name: 'go get necessary tools'
      run: >
        go get -u
        github.com/gordonklaus/ineffassign
        golang.org/x/lint/golint
        golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
        honnef.co/go/tools/cmd/staticcheck
    - name: 'go get necessary tools (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: >
        go get -u
        github.com/client9/misspell/cmd/misspell
        github.com/google/addlicense

      # Checkout and print debugging information.
    - uses: actions/checkout@v2
    - name: "Debug (posix)"
      if: always() && matrix.os != 'windows-latest'
      run: |
        echo GOPATH = $GOPATH
        echo GOROOT = $GOROOT
        echo HOME = $HOME
        echo GITHUB_WORKSPACE = $GITHUB_WORKSPACE
        echo PATH = $PATH
        echo ""
        echo pwd = $(pwd)
        echo $ ls -la
        ls -la
        echo ""
        echo $ ls -la $HOME
        ls -la $HOME
        echo ""
        echo $ ls -la $HOME/go
        ls -la $HOME/go
        echo ""
        echo $ ls -la $HOME/go/bin
        ls -la $HOME/go/bin
    - name: "Debug (windows)"
      if: always() && matrix.os == 'windows-latest'
      shell: cmd
      run: |
        echo GOPATH = %GOPATH%
        echo GOROOT = %GOROOT%
        echo USERPROFILE = %USERPROFILE%
        echo GITHUB_WORKSPACE = %GITHUB_WORKSPACE%
        echo PATH = %PATH%
        echo cd = %CD%
        dir /a
        dir /a %USERPROFILE%
        dir /a %USERPROFILE%\go
        dir /a %USERPROFILE%\go\bin

      # Now run proper checks.
    - name: 'Check: go vet'
      if: always()
      run: go vet ./...
    - name: 'Check: go vet shadow; shadowed variables (posix)'
      if: always() && matrix.os != 'windows-latest'
      run: go vet -vettool=$(which shadow) ./...
    - name: 'Check: go vet shadow; shadowed variables (windows)'
      if: always() && matrix.os == 'windows-latest'
      shell: cmd
      run: go vet -vettool=%USERPROFILE%/go/bin/shadow.exe ./...
    - name: 'Check: golint'
      if: always()
      run: golint -set_exit_status ./...
    - name: 'Check: inefficient variable assignment'
      if: always()
      run: ineffassign .
    - name: 'Check: staticcheck'
      if: always()
      run: staticcheck -checks all,-U1000 ./...

      # The following checks are not dependent on the OS or go build tags. Only
      # run them on ubuntu-latest since it's the fastest one.
    - name: 'Check: no executable was committed (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: |
        if find . -path ./systemd/setup.sh -prune -o -path ./.git -prune -o -type f -executable -print | grep -e . ; then
          echo 'Do not commit executables'
          false
        fi
    - name: 'Check: gofmt; code is well formatted (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: |
        FILES=$(gofmt -s -l .)
        if ! test -z "$FILES"; then
          echo 'Please run `gofmt -s -w` on the following files:' >> _gofmt.txt
          echo "" >> _gofmt.txt
          for FILE in ${FILES}; do
            echo "- ${FILE}" >> _gofmt.txt
          done
          cat _gofmt.txt
          echo "## ⚠ gofmt Failed" >> _comments.txt
          echo "" >> _comments.txt
          cat _gofmt.txt >> _comments.txt
          echo "" >> _comments.txt
          false
        fi
    - name: 'Check: addlicense; all sources have a license header (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: addlicense -check .
    - name: "Check: misspelling; code doesn't contain misspelling (ubuntu)"
      if: always() && matrix.os == 'ubuntu-latest'
      run: |
        ERR=$(misspell .)
        if ! test -z "$ERR"; then
          echo "$ERR"
          echo "## ⚠ misspell Failed" >> _comments.txt
          echo "" >> _comments.txt
          echo "$ERR" >> _comments.txt
          echo "" >> _comments.txt
          false
        fi

      # Run tests last since it's potentially the slowest step.
    - name: 'Check: go test -cover (posix)'
      if: always() && matrix.os != 'windows-latest'
      run: go test -covermode=count -coverprofile=coverage.txt ./...
    - name: 'Check: go test -cover (windows)'
      if: always() && matrix.os == 'windows-latest'
      # Powershell messes things up.
      shell: cmd
      run: go test -covermode=count -coverprofile=coverage.txt ./...
      # Don't send code coverage if anything failed to reduce spam.
    - uses: codecov/codecov-action@v1
    - name: 'Cleanup'
      run: rm coverage.txt
      # Don't run go test -race if anything failed, to speed up the results.
    - name: 'Check: go test -race'
      run: go test -race ./...

    - name: "Check: go generate doesn't modify files (posix)"
      # TODO(maruel): Find a way to enable this check on Windows.
      if: matrix.os != 'windows-latest'
      run: |
        go generate ./...
        TOUCHED=$(git status --porcelain --ignored)
        if ! test -z "$TOUCHED"; then
          echo "go generate modified these files, please update:"
          echo "$TOUCHED"
          git diff<commit_msg>github actions: run go mod tidy<commit_after># Copyright 2020 The Periph Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.

# References:
# https://developer.github.com/webhooks/event-payloads/
# https://github.com/actions/cache
# https://github.com/actions/checkout
# https://github.com/actions/setup-go
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#using-the-github_token-in-a-workflow
# https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions/
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions

on: [push, pull_request]
name: Run tests
jobs:
  test_all:
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        gover: ['1.14.3']
    runs-on: "${{matrix.os}}"
    name: "go${{matrix.gover}} on ${{matrix.os}}"
    steps:
    - uses: actions/setup-go@v2
      with:
        go-version: "^${{matrix.gover}}"
    - name: 'Cache: ~/go/pkg/mod'
      uses: actions/cache@v1
      with:
        path: "~/go/pkg/mod"
        # We want a key that helps with keeping the tools.
        key: "${{runner.<KEY>{{hashFiles('~/go/pkg/**/go.sum')}}"
        restore-keys: "${{runner.<KEY>

      # Fetch the tools before checking out, so they don't modify go.mod/go.sum.
    - name: 'go get necessary tools'
      run: >
        go get -u
        github.com/gordonklaus/ineffassign
        golang.org/x/lint/golint
        golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
        honnef.co/go/tools/cmd/staticcheck
    - name: 'go get necessary tools (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: >
        go get -u
        github.com/client9/misspell/cmd/misspell
        github.com/google/addlicense

      # Checkout and print debugging information.
    - uses: actions/checkout@v2
    - name: "Debug (posix)"
      if: always() && matrix.os != 'windows-latest'
      run: |
        echo GOPATH = $GOPATH
        echo GOROOT = $GOROOT
        echo HOME = $HOME
        echo GITHUB_WORKSPACE = $GITHUB_WORKSPACE
        echo PATH = $PATH
        echo ""
        echo pwd = $(pwd)
        echo $ ls -la
        ls -la
        echo ""
        echo $ ls -la $HOME
        ls -la $HOME
        echo ""
        echo $ ls -la $HOME/go
        ls -la $HOME/go
        echo ""
        echo $ ls -la $HOME/go/bin
        ls -la $HOME/go/bin
    - name: "Debug (windows)"
      if: always() && matrix.os == 'windows-latest'
      shell: cmd
      run: |
        echo GOPATH = %GOPATH%
        echo GOROOT = %GOROOT%
        echo USERPROFILE = %USERPROFILE%
        echo GITHUB_WORKSPACE = %GITHUB_WORKSPACE%
        echo PATH = %PATH%
        echo cd = %CD%
        dir /a
        dir /a %USERPROFILE%
        dir /a %USERPROFILE%\go
        dir /a %USERPROFILE%\go\bin

      # Now run proper checks.
    - name: 'Check: go vet'
      if: always()
      run: go vet ./...
    - name: 'Check: go vet shadow; shadowed variables (posix)'
      if: always() && matrix.os != 'windows-latest'
      run: go vet -vettool=$(which shadow) ./...
    - name: 'Check: go vet shadow; shadowed variables (windows)'
      if: always() && matrix.os == 'windows-latest'
      shell: cmd
      run: go vet -vettool=%USERPROFILE%/go/bin/shadow.exe ./...
    - name: 'Check: golint'
      if: always()
      run: golint -set_exit_status ./...
    - name: 'Check: inefficient variable assignment'
      if: always()
      run: ineffassign .
    - name: 'Check: staticcheck'
      if: always()
      run: staticcheck -checks all,-U1000 ./...

      # The following checks are not dependent on the OS or go build tags. Only
      # run them on ubuntu-latest since it's the fastest one.
    - name: 'Check: no executable was committed (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: |
        if find . -path ./systemd/setup.sh -prune -o -path ./.git -prune -o -type f -executable -print | grep -e . ; then
          echo 'Do not commit executables'
          false
        fi
    - name: 'Check: gofmt; code is well formatted (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: |
        FILES=$(gofmt -s -l .)
        if ! test -z "$FILES"; then
          echo 'Please run `gofmt -s -w` on the following files:' >> _gofmt.txt
          echo "" >> _gofmt.txt
          for FILE in ${FILES}; do
            echo "- ${FILE}" >> _gofmt.txt
          done
          cat _gofmt.txt
          echo "## ⚠ gofmt Failed" >> _comments.txt
          echo "" >> _comments.txt
          cat _gofmt.txt >> _comments.txt
          echo "" >> _comments.txt
          false
        fi
    - name: 'Check: addlicense; all sources have a license header (ubuntu)'
      if: always() && matrix.os == 'ubuntu-latest'
      run: addlicense -check .
    - name: "Check: misspelling; code doesn't contain misspelling (ubuntu)"
      if: always() && matrix.os == 'ubuntu-latest'
      run: |
        ERR=$(misspell .)
        if ! test -z "$ERR"; then
          echo "$ERR"
          echo "## ⚠ misspell Failed" >> _comments.txt
          echo "" >> _comments.txt
          echo "$ERR" >> _comments.txt
          echo "" >> _comments.txt
          false
        fi

      # Run tests last since it's potentially the slowest step.
    - name: 'Check: go test -cover (posix)'
      if: always() && matrix.os != 'windows-latest'
      run: go test -covermode=count -coverprofile=coverage.txt ./...
    - name: 'Check: go test -cover (windows)'
      if: always() && matrix.os == 'windows-latest'
      # Powershell messes things up.
      shell: cmd
      run: go test -covermode=count -coverprofile=coverage.txt ./...
      # Don't send code coverage if anything failed to reduce spam.
    - uses: codecov/codecov-action@v1
    - name: 'Cleanup'
      run: rm coverage.txt
      # Don't run go test -race if anything failed, to speed up the results.
    - name: 'Check: go test -race'
      run: go test -race ./...

    - name: "Check: go generate + go mod tidy doesn't modify files (posix)"
      # TODO(maruel): Find a way to enable this check on Windows.
      if: matrix.os != 'windows-latest'
      run: |
        go generate ./...
        go mod tidy
        TOUCHED=$(git status --porcelain --ignored)
        if ! test -z "$TOUCHED"; then
          echo "go generate modified these files, please update:"
          echo "$TOUCHED"
          git diff
{'fraction_non_alphanumeric': 0.1369591712370506, 'fraction_numerical': 0.002894576477757465, 'mean_word_length': 2.0064117242958552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6312895', 'n_tokens_mistral': 4311, 'n_tokens_neox': 4140, 'n_words': 1224}