Merge pull request #65 from Its-donkey/release/docs-20260130-085412 #163
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| push: | |
| branches: [main, test] | |
| pull_request: | |
| branches: [main, test] | |
| workflow_dispatch: | |
| inputs: | |
| full_mutation: | |
| description: 'Run full mutation testing (mutilated level, HTML report)' | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: ['1.23', '1.24'] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - run: go mod download | |
| - run: go test -v -race ./... | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.24' | |
| - uses: golangci/golangci-lint-action@v9 | |
| with: | |
| version: latest | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.24' | |
| - run: go build -v ./... | |
| coverage: | |
| name: Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.24' | |
| - run: go test -coverprofile=coverage.out ./... | |
| - run: | | |
| COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}') | |
| echo "## Coverage: $COVERAGE" >> $GITHUB_STEP_SUMMARY | |
| - name: Upload coverage | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-out | |
| path: coverage.out | |
| - name: Upload to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: coverage.out | |
| fail_ci_if_error: false | |
| mutation: | |
| name: Mutation Testing (diff-based) | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.full_mutation != 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.25' | |
| - name: Install mutagoph | |
| run: go install github.com/its-donkey/mutagoph/cmd/mutagoph@latest | |
| - name: Determine diff base | |
| id: diff | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "base=origin/${{ github.base_ref }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "base=HEAD~1" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Run mutation testing | |
| run: | | |
| mutagoph run \ | |
| -target ./... \ | |
| -parallelism dynamic \ | |
| --dynamic-level standard \ | |
| --diff-base "${{ steps.diff.outputs.base }}" \ | |
| --output json \ | |
| --output-file mutation-report.json | |
| - name: Generate summary | |
| if: always() | |
| run: | | |
| if [ -f mutation-report.json ]; then | |
| echo "## Mutation Testing Results" >> $GITHUB_STEP_SUMMARY | |
| SCORE=$(jq -r '.summary.MutationScore // 0' mutation-report.json) | |
| TOTAL=$(jq -r '.summary.TotalMutants // 0' mutation-report.json) | |
| KILLED=$(jq -r '.summary.Killed // 0' mutation-report.json) | |
| SURVIVED=$(jq -r '.summary.Survived // 0' mutation-report.json) | |
| echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Score | ${SCORE}% |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Total | ${TOTAL} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Killed | ${KILLED} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Survived | ${SURVIVED} |" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "## Mutation Testing" >> $GITHUB_STEP_SUMMARY | |
| echo "No mutations found in changed files." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Upload report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mutation-report-json | |
| path: mutation-report.json | |
| if-no-files-found: ignore | |
| full-mutation: | |
| name: Full Mutation Testing | |
| if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.full_mutation == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.25' | |
| - name: Install mutagoph | |
| run: go install github.com/its-donkey/mutagoph/cmd/mutagoph@latest | |
| - name: Run full mutation testing | |
| run: | | |
| mutagoph run \ | |
| -target ./... \ | |
| -parallelism dynamic \ | |
| --dynamic-level mutilated \ | |
| --clear-cache \ | |
| --output html \ | |
| --output-file report.html | |
| - name: Create PR with report | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add report.html | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| BRANCH="chore/mutation-report-$(date +%Y%m%d-%H%M%S)" | |
| git checkout -b "$BRANCH" | |
| git commit -m "chore: update full mutation testing report" | |
| git push origin "$BRANCH" | |
| gh pr create \ | |
| --base test \ | |
| --head "$BRANCH" \ | |
| --title "chore: update full mutation testing report" \ | |
| --body "Automated mutation testing report update." | |
| - name: Upload report artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mutation-report-html | |
| path: report.html | |
| update-results: | |
| name: Update Test Results | |
| needs: [coverage, mutation] | |
| if: ${{ github.event_name == 'pull_request' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.24' | |
| - name: Download coverage artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-out | |
| path: . | |
| continue-on-error: true | |
| - name: Download mutation artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: mutation-report-json | |
| path: . | |
| continue-on-error: true | |
| - name: Update test results | |
| run: | | |
| chmod +x scripts/update-test-results.sh | |
| ARGS="" | |
| if [ -f coverage.out ]; then | |
| ARGS="$ARGS --coverage coverage.out" | |
| fi | |
| if [ -f mutation-report.json ]; then | |
| ARGS="$ARGS --mutation mutation-report.json" | |
| fi | |
| if [ -n "$ARGS" ]; then | |
| ./scripts/update-test-results.sh $ARGS | |
| else | |
| echo "No test results to update" | |
| exit 0 | |
| fi | |
| - name: Check for changes | |
| id: changes | |
| run: | | |
| if git diff --quiet docs/test-results.json; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit test results to PR branch | |
| if: steps.changes.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add docs/test-results.json | |
| git commit -m "chore: update test results" | |
| git push origin HEAD:${{ github.head_ref }} |