diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..38d33b3 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,72 @@ +name: Test + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + go: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.17"] + path: ["", "examples"] + name: Go ${{ matrix.go }} ${{ matrix.path }} + steps: + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Go modules cache + id: cache-go-module + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-gomod-${{ matrix.path }}-${{ hashFiles('go.sum') }}- + restore-keys: | + ${{ runner.os }}-gomod- + + - name: Setup Go build cache + id: cache-go-build + uses: actions/cache@v2 + with: + path: ~/.cache/go-build + key: ${{ runner.os }}-gobuild-${{ matrix.path }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-gobuild- + + - name: Download dependencies + working-directory: ${{ matrix.path }} + if: steps.cache-go-module.outputs.cache-hit != 'true' + run: go mod download + + - name: Verify go modules up to date + working-directory: ${{ matrix.path }} + run: | + set -ex + go mod tidy + [ -z "$(git diff -- go.{mod,sum})" ] # Check there are no changes! + + - name: Test + working-directory: ${{ matrix.path }} + run: go test ./... + + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.41 + skip-go-installation: true + github-token: ${{ secrets.GITHUB_TOKEN }} + only-new-issues: false + skip-pkg-cache: true + skip-build-cache: true + args: --timeout=10m + working-directory: ${{ matrix.path }}