go.dev/dl redirects to dl.google.com which is blocked in China. Use mirrors.aliyun.com for Go toolchain download and goproxy.cn for Go module proxy.
81 lines
1.9 KiB
YAML
81 lines
1.9 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
tags: ["v*"]
|
|
pull_request:
|
|
branches: [master]
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
env:
|
|
GO_MIRROR: https://mirrors.aliyun.com/golang
|
|
GOPROXY: https://goproxy.cn,direct
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Go
|
|
run: |
|
|
GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}')
|
|
curl -sL "${GO_MIRROR}/go${GO_VERSION}.linux-amd64.tar.gz" | tar -C /usr/local -xzf -
|
|
echo "/usr/local/go/bin" >> $GITHUB_PATH
|
|
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
|
|
|
|
- name: Check formatting
|
|
run: |
|
|
go install mvdan.cc/gofumpt@latest
|
|
output=$(gofumpt -l .)
|
|
if [ -n "$output" ]; then
|
|
echo "Files need formatting:"
|
|
echo "$output"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Run lint
|
|
run: |
|
|
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
|
|
golangci-lint run ./...
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Go
|
|
run: |
|
|
GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}')
|
|
curl -sL "${GO_MIRROR}/go${GO_VERSION}.linux-amd64.tar.gz" | tar -C /usr/local -xzf -
|
|
echo "/usr/local/go/bin" >> $GITHUB_PATH
|
|
|
|
- name: Run unit tests
|
|
run: go test -race -count=1 ./internal/...
|
|
|
|
build:
|
|
name: Build
|
|
needs: [lint, test]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Go
|
|
run: |
|
|
GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}')
|
|
curl -sL "${GO_MIRROR}/go${GO_VERSION}.linux-amd64.tar.gz" | tar -C /usr/local -xzf -
|
|
echo "/usr/local/go/bin" >> $GITHUB_PATH
|
|
|
|
- name: Build
|
|
run: make build
|
|
|
|
- name: Verify binary
|
|
run: ./bin/lolly --help
|