From ac9132b163ca30fe60cfc92c6dbf87f2a3d741ca Mon Sep 17 00:00:00 2001 From: Thanee Charattrakool <37617738+Planxnx@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:27:47 +0700 Subject: [PATCH] ci: Add Golang Lint and Test CI (#9) * ci: add golang linter and test runner gh action * ci: use go-test-action@v0 * ci: annotate test result * ci: update running flag * fix: try to fix malformed import path * feat: add mock test * ci: remove annotation ci * ci: add annotate test result * chore: remove unused * feat: try testify * feat: remove test * ci: add go test on macos, windows and go latest version * ci: test building * feat: remove mock code --- .github/workflows/code-analysis.yml | 77 +++++++++++++++++++++++++++++ go.sum | 0 2 files changed, 77 insertions(+) create mode 100644 .github/workflows/code-analysis.yml create mode 100644 go.sum diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml new file mode 100644 index 0000000..ccd15eb --- /dev/null +++ b/.github/workflows/code-analysis.yml @@ -0,0 +1,77 @@ +name: Code Analysis & Test +on: + workflow_dispatch: + pull_request: + branches: + - develop + - main + paths: + - "go.mod" + - "go.sum" + - "**.go" + - ".golangci.yaml" + - ".github/workflows/code-analysis.yml" + +jobs: + lint: + strategy: + matrix: + os: ["ubuntu-latest"] + name: Lint (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: "go.mod" + cache-dependency-path: "**/*.sum" + cache: true # caching and restoring go modules and build outputs. + + - name: Lint + uses: reviewdog/action-golangci-lint@v2 + with: # https://github.com/reviewdog/action-golangci-lint#inputs + go_version_file: "go.mod" + workdir: ./ + golangci_lint_flags: "--config=./.golangci.yaml --verbose --new-from-rev=${{ github.event.pull_request.base.sha }}" + fail_on_error: true + test: + strategy: + matrix: + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + go-version: ["1.22.x", "1.x"] # minimum version and latest version + name: Test (${{ matrix.os }}/${{ matrix.go-version }}) + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + cache: true # caching and restoring go modules and build outputs. + - run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -json ./... > test_output.json + + - name: Summary Test Results + if: always() + uses: robherley/go-test-action@v0 + with: + fromJSONFile: test_output.json + + - name: Annotate Test Results + if: always() + uses: guyarb/golang-test-annotations@v0.5.1 + with: + test-results: test_output.json diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29