diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c538750f..baae2f95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,11 +6,39 @@ on: - main pull_request: +permissions: + contents: write + pull-requests: write + jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Format Check + run: | + unformatted="$(find cmd internal test -name '*.go' -print0 | xargs -0r gofmt -l)" + test -z "$unformatted" || (printf '%s\n' "$unformatted" && exit 1) + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.64.8 + args: ./... + test: + name: Test runs-on: ubuntu-latest timeout-minutes: 20 - steps: - name: Check out repository uses: actions/checkout@v4 @@ -26,19 +54,83 @@ jobs: - name: Build run: make build - - name: Format Check - run: | - unformatted="$(find cmd hack internal test -name '*.go' -print0 | xargs -0r gofmt -l)" - test -z "$unformatted" || (printf '%s\n' "$unformatted" && exit 1) + - name: Test with Race Detection + run: go test -v -race -count=1 -timeout=5m ./cmd/... ./internal/... - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + coverage: + name: Coverage + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 with: - version: v1.64.8 - args: ./... + go-version-file: go.mod - - name: Test - run: make test + - name: Install archive tooling + run: sudo apt-get update && sudo apt-get install -y zip unzip + + - name: Build + run: make build + + - name: Run tests with coverage + run: | + go test -coverprofile=coverage.txt -covermode=atomic ./cmd/... ./internal/... + go tool cover -func=coverage.txt + + - name: Generate coverage report + run: go tool cover -html=coverage.txt -o coverage.html + + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: | + coverage.txt + coverage.html + + - name: Update coverage badge + if: github.ref == 'refs/heads/main' + run: | + COVERAGE=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}' | sed 's/%//') + echo "Coverage: ${COVERAGE}%" + if (( $(echo "$COVERAGE >= 80" | bc -l) )); then + COLOR="brightgreen" + elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then + COLOR="yellow" + else + COLOR="red" + fi + mkdir -p .github/badges + curl -s "https://img.shields.io/badge/coverage-${COVERAGE}%25-${COLOR}" > .github/badges/coverage.svg + + - name: Commit badge + if: github.ref == 'refs/heads/main' + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add .github/badges/coverage.svg || true + git diff --staged --quiet || git commit -m "chore: update coverage badge [skip ci]" + git push || true + + policy: + name: Policy Check + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Build + run: make build - name: Policy run: make policy diff --git a/README.md b/README.md index 52bd98c5..c11b61fc 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Go 1.25+ License Apache-2.0 v1.1.0 + CI + Coverage

diff --git a/README_en.md b/README_en.md index e72e5b8b..c6446b77 100644 --- a/README_en.md +++ b/README_en.md @@ -10,6 +10,8 @@ Go 1.25+ License Apache-2.0 v1.1.0 + CI + Coverage