From 51f0b338c58c2096940c155d96d7ec0f00062a9a Mon Sep 17 00:00:00 2001 From: appleboy Date: Fri, 4 Oct 2024 21:06:18 +0800 Subject: [PATCH] ci: enhance CI pipeline for Go projects - Rename job from `testing` to `test` - Add matrix strategy to test on multiple Go versions (1.21, 1.22, 1.23) - Set up Go environment variables `GO111MODULE` and `GOPROXY` - Replace `actions/checkout@v4` with `actions/setup-go@v5` for setting up Go - Add caching for Go build and module directories using `actions/cache@v4` - Change test command from `make test` to `go test -v -covermode=atomic -coverprofile=coverage.out` - Add flags to `codecov/codecov-action@v4` for matrix OS and Go version Signed-off-by: appleboy --- .github/workflows/lint.yml | 43 +++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6483270..b6e76fe 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,20 +25,43 @@ jobs: with: dockerfile: docker/Dockerfile - testing: - runs-on: ubuntu-latest - container: golang:1.22-alpine + test: + strategy: + matrix: + os: [ubuntu-latest] + go: [1.21, 1.22, 1.23] + include: + - os: ubuntu-latest + go-build: ~/.cache/go-build + name: ${{ matrix.os }} @ Go ${{ matrix.go }} + runs-on: ${{ matrix.os }} + env: + GO111MODULE: on + GOPROXY: https://proxy.golang.org steps: - - name: Checkout repository + - name: Set up Go ${{ matrix.go }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Checkout Code uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} - - name: setup sshd server + - uses: actions/cache@v4 + with: + path: | + ${{ matrix.go-build }} + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run Tests run: | - apk add git make curl perl bash build-base zlib-dev ucl-dev - - - name: testing - run: | - make test + go test -v -covermode=atomic -coverprofile=coverage.out - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 + with: + flags: ${{ matrix.os }},go-${{ matrix.go }}