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 <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2024-10-04 21:06:18 +08:00
parent 2e8d61dcf2
commit 51f0b338c5
+33 -10
View File
@@ -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 }}