Skip to content

fix: I18n error --bug=1 #15

fix: I18n error --bug=1

fix: I18n error --bug=1 #15

Workflow file for this run

name: Test and Coverage
on:
push:
branches: [ main, develop, '**-nl-to-cmd' ]
pull_request:
branches: [ main, develop ]
jobs:
test:
name: Test with Coverage
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.24', '1.25']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Download dependencies
run: go mod download
- name: Run tests
run: |
# 运行所有测试
go test -v ./...
# 只计算核心库代码的覆盖率(排除cmd目录)
go test -coverprofile=coverage.out ./internal/... ./pkg/...
- name: Run race detector
run: go test -v -race ./...
- name: Calculate coverage
id: coverage
run: |
# 提取总覆盖率,处理可能的格式变化
COVERAGE=$(go tool cover -func=coverage.out | grep total | grep -oP '\d+\.\d+(?=%)')
if [ -z "$COVERAGE" ]; then
# 如果上面的方法失败,尝试另一种方法
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $NF}' | sed 's/%//')
fi
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Test coverage: $COVERAGE%"
- name: Check coverage threshold
run: |
COVERAGE=${{ steps.coverage.outputs.coverage }}
THRESHOLD=60
if [ -z "$COVERAGE" ]; then
echo "❌ Failed to calculate coverage"
exit 1
fi
# 使用 awk 进行浮点数比较(更可靠)
if awk "BEGIN {exit !($COVERAGE < $THRESHOLD)}"; then
echo "❌ Coverage $COVERAGE% is below threshold $THRESHOLD%"
exit 1
else
echo "✅ Coverage $COVERAGE% meets threshold $THRESHOLD%"
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Generate coverage report
if: matrix.go-version == '1.25'
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage report
if: matrix.go-version == '1.25'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.html
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
args: --timeout=5m
skip-config-verify: true
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ['1.25']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Build
run: go build -v ./cmd/aicli
- name: Verify binary
if: runner.os != 'Windows'
run: |
./aicli --version || echo "Binary built successfully (version command not yet implemented)"
- name: Verify binary (Windows)
if: runner.os == 'Windows'
run: |
.\aicli.exe --version || echo "Binary built successfully (version command not yet implemented)"