ci: enhance CI with multi-OS and Go version testing

- Rename `testing` job to `test`
- Add matrix strategy to run tests on multiple OS and Go versions
- Replace `actions/checkout@v4` with `actions/setup-go@v5` for setting up Go
- Add caching for Go build and module files 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 OS and Go version

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2024-10-04 15:21:23 +08:00
parent 65d16c52a3
commit 5122d14617
+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, macos-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 }}