|
| 1 | +name: Main |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +env: |
| 10 | + GO_VERSION: 1.23 |
| 11 | + CGO_ENABLED: 0 |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + name: Go Lint |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + GOLANGCI_LINT_VERSION: v2.5.0 |
| 19 | + defaults: |
| 20 | + run: |
| 21 | + working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} |
| 22 | + |
| 23 | + steps: |
| 24 | + # https://github.com/marketplace/actions/setup-go-environment |
| 25 | + - name: Set up Go ${{ env.GO_VERSION }} |
| 26 | + uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2 |
| 27 | + with: |
| 28 | + go-version: ${{ env.GO_VERSION }} |
| 29 | + |
| 30 | + # https://github.com/marketplace/actions/checkout |
| 31 | + - name: Check out code |
| 32 | + uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2 |
| 33 | + with: |
| 34 | + path: go/src/github.com/${{ github.repository }} |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + # https://golangci-lint.run/usage/install#other-ci |
| 38 | + - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} |
| 39 | + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} |
| 40 | + |
| 41 | + - name: Setup GOPATH |
| 42 | + run: go env -w GOPATH=${{ github.workspace }}/go |
| 43 | + |
| 44 | + - name: gofmt |
| 45 | + run: | |
| 46 | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then |
| 47 | + gofmt -s -d . |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Golangci-lint |
| 52 | + run: make lint |
| 53 | + |
| 54 | + test: |
| 55 | + name: Go Tests |
| 56 | + runs-on: ubuntu-latest |
| 57 | + defaults: |
| 58 | + run: |
| 59 | + working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Set up Go ${{ env.GO_VERSION }} |
| 63 | + uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2 |
| 64 | + with: |
| 65 | + go-version: ${{ env.GO_VERSION }} |
| 66 | + |
| 67 | + - name: Check out code |
| 68 | + uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2 |
| 69 | + with: |
| 70 | + path: go/src/github.com/${{ github.repository }} |
| 71 | + fetch-depth: 0 |
| 72 | + |
| 73 | + - name: Cache Go modules |
| 74 | + uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3 |
| 75 | + with: |
| 76 | + path: ${{ github.workspace }}/go/pkg/mod |
| 77 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 78 | + restore-keys: | |
| 79 | + ${{ runner.os }}-go- |
| 80 | +
|
| 81 | + - name: Setup GOPATH |
| 82 | + run: go env -w GOPATH=${{ github.workspace }}/go |
| 83 | + |
| 84 | + - name: Run tests |
| 85 | + run: make test |
| 86 | + |
| 87 | + - name: Upload coverage reports to Codecov |
| 88 | + uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5 |
| 89 | + with: |
| 90 | + token: ${{ secrets.CODECOV_TOKEN }} |
0 commit comments