Add CI and SonarQube workflows for automated testing and code quality analysis
Some checks failed
SonarQube Scan / SonarQube Analysis (push) Failing after 1m13s
Some checks failed
SonarQube Scan / SonarQube Analysis (push) Failing after 1m13s
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
81
.gitea/workflows/ci.yml
Normal file
81
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: go test -v -race -coverprofile=coverage.out ./src
|
||||||
|
|
||||||
|
- name: Upload coverage
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: coverage
|
||||||
|
path: coverage.out
|
||||||
|
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Install golangci-lint
|
||||||
|
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
|
|
||||||
|
- name: Run linter
|
||||||
|
run: golangci-lint run ./src
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [test, lint]
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Build binary (Linux)
|
||||||
|
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o epage-linux ./src
|
||||||
|
|
||||||
|
- name: Build binary (macOS)
|
||||||
|
run: CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o epage-macos ./src
|
||||||
|
|
||||||
|
- name: Build binary (Windows)
|
||||||
|
run: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o epage-windows.exe ./src
|
||||||
|
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: binaries
|
||||||
|
path: |
|
||||||
|
epage-linux
|
||||||
|
epage-macos
|
||||||
|
epage-windows.exe
|
||||||
31
.gitea/workflows/sonarqube.yml
Normal file
31
.gitea/workflows/sonarqube.yml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: SonarQube Scan
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sonarqube:
|
||||||
|
name: SonarQube Analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Run tests with coverage
|
||||||
|
run: go test -v -coverprofile=coverage.out ./src
|
||||||
|
|
||||||
|
- name: Run SonarQube scanner
|
||||||
|
uses: SonarSource/sonarqube-scan-action@v7.1.0
|
||||||
|
env:
|
||||||
|
SONAR_HOST_URL: ${{ secrets.SONAR_URL }}
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
68
SONARQUBE.md
Normal file
68
SONARQUBE.md
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# SonarQube Configuration
|
||||||
|
|
||||||
|
This project uses SonarQube for code quality analysis.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
To enable SonarQube scanning, you need to configure the following GitHub/Gitea secrets:
|
||||||
|
|
||||||
|
### Secrets Required
|
||||||
|
|
||||||
|
- `SONAR_HOST_URL`: Your SonarQube server URL (e.g., `https://sonarqube.example.com`)
|
||||||
|
- `SONAR_LOGIN`: Your SonarQube authentication token
|
||||||
|
|
||||||
|
### Adding Secrets in Gitea
|
||||||
|
|
||||||
|
1. Go to your repository settings
|
||||||
|
2. Navigate to "Secrets and variables" → "Actions"
|
||||||
|
3. Add the following secrets:
|
||||||
|
- `SONAR_HOST_URL`
|
||||||
|
- `SONAR_LOGIN`
|
||||||
|
|
||||||
|
## SonarQube Properties
|
||||||
|
|
||||||
|
The `sonar-project.properties` file configures:
|
||||||
|
|
||||||
|
- **Project Key**: `epage-go`
|
||||||
|
- **Sources**: `src/` directory
|
||||||
|
- **Tests**: All `*_test.go` files in `src/`
|
||||||
|
- **Coverage**: Reports from `coverage.out`
|
||||||
|
- **Exclusions**: Test files excluded from main analysis
|
||||||
|
|
||||||
|
## Workflow Triggers
|
||||||
|
|
||||||
|
- **CI Workflow** (`.gitea/workflows/ci.yml`):
|
||||||
|
- Runs on: Pull requests to `main` or `develop`
|
||||||
|
- Tests, lints, and builds the application
|
||||||
|
|
||||||
|
- **SonarQube Workflow** (`.gitea/workflows/sonarqube.yml`):
|
||||||
|
- Runs on: Pushes to `main` branch
|
||||||
|
- Generates coverage reports and uploads to SonarQube
|
||||||
|
|
||||||
|
## Local SonarQube Scanning
|
||||||
|
|
||||||
|
To scan locally (requires SonarQube CLI):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate coverage report
|
||||||
|
go test -coverprofile=coverage.out ./src
|
||||||
|
|
||||||
|
# Run SonarQube scanner
|
||||||
|
sonar-scanner \
|
||||||
|
-Dsonar.projectKey=epage-go \
|
||||||
|
-Dsonar.sources=src \
|
||||||
|
-Dsonar.host.url=https://sonarqube.example.com \
|
||||||
|
-Dsonar.login=your_token
|
||||||
|
```
|
||||||
|
|
||||||
|
## Coverage Reports
|
||||||
|
|
||||||
|
Test coverage is automatically collected and can be viewed:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run tests with coverage
|
||||||
|
go test -v -coverprofile=coverage.out ./src
|
||||||
|
|
||||||
|
# View coverage report
|
||||||
|
go tool cover -html=coverage.out
|
||||||
|
```
|
||||||
26
sonar-project.properties
Normal file
26
sonar-project.properties
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
sonar.projectKey=epage-go
|
||||||
|
sonar.projectName=epage-go
|
||||||
|
sonar.projectVersion=1.0.0
|
||||||
|
|
||||||
|
# Source code location
|
||||||
|
sonar.sources=src
|
||||||
|
sonar.sourceEncoding=UTF-8
|
||||||
|
|
||||||
|
# Exclude test files from analysis
|
||||||
|
sonar.exclusions=**/*_test.go
|
||||||
|
|
||||||
|
# Test configuration
|
||||||
|
sonar.tests=src
|
||||||
|
sonar.test.inclusions=**/*_test.go
|
||||||
|
|
||||||
|
# Coverage reports
|
||||||
|
sonar.go.coverage.reportPaths=coverage.out
|
||||||
|
|
||||||
|
# Code coverage exclusions
|
||||||
|
sonar.coverage.exclusions=**/*_test.go
|
||||||
|
|
||||||
|
# Quality gates
|
||||||
|
sonar.qualitygate.wait=true
|
||||||
|
|
||||||
|
# Language
|
||||||
|
sonar.language=go
|
||||||
Reference in New Issue
Block a user