Skip to content

Release v0.2.0: Promote test to main #69

Release v0.2.0: Promote test to main

Release v0.2.0: Promote test to main #69

Workflow file for this run

name: CI
on:
push:
branches: [main, test]
pull_request:
branches: [main, test]
workflow_dispatch:
inputs:
mutation_target:
description: 'Target for mutation testing (e.g., ./internal/reporter/reporter.go)'
required: false
default: './internal/...'
full_scan:
description: 'Run full scan without diff-base'
required: false
type: boolean
default: false
permissions:
contents: write
pull-requests: write
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Download dependencies
run: go mod download
- name: Build
run: go build -v ./...
- name: Run tests with coverage
run: |
go test -v -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | tee coverage.txt
- name: Run race detector
run: go test -race -short ./...
- name: Check coverage threshold
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Total coverage: ${COVERAGE}%"
if (( $(echo "$COVERAGE < 30" | bc -l) )); then
echo "Coverage ${COVERAGE}% is below 30% threshold"
exit 1
fi
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-file: 'go.mod'
- name: Run go vet
run: go vet ./...
- name: Check formatting
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "Code is not formatted. Run 'gofmt -w .'"
gofmt -l .
exit 1
fi
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Run staticcheck
run: staticcheck ./...
mutation:
name: Mutation Testing
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Download dependencies
run: go mod download
- name: Cache mutagoph data
uses: actions/cache@v4
with:
path: ~/.cache/mutagoph
key: mutagoph-${{ github.run_id }}
restore-keys: |
mutagoph-
- name: Build mutagoph
run: go build -o mutagoph ./cmd/mutagoph
- name: Run mutation testing
run: |
TARGET="${{ inputs.mutation_target || './internal/...' }}"
DIFF_BASE_FLAG=""
if [ "${{ inputs.full_scan }}" != "true" ]; then
DIFF_BASE_FLAG="--diff-base origin/main"
fi
echo "Running mutation testing on: $TARGET"
echo "Full scan mode: ${{ inputs.full_scan || 'false' }}"
./mutagoph run \
--target "$TARGET" \
$DIFF_BASE_FLAG \
--mutations mutilated \
--parallelism mutilated \
--timeout 5s \
--output html \
--output-file mutation-report.html \
--min-score 0
- name: Upload mutation report
if: always()
uses: actions/upload-artifact@v4
with:
name: mutation-report
path: mutation-report.html
retention-days: 30
- name: Commit mutation report to repo
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add mutation-report.html
git diff --staged --quiet || git commit -m "Update mutation report [skip ci]"
git push
- name: Post mutation results to PR
if: github.event_name == 'pull_request' && always()
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const body = `## Mutation Testing\n\n` +
`Mutation testing completed.\n\n` +
`📎 Download the HTML report from the workflow artifacts for detailed results.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Run govulncheck
run: govulncheck ./...