Skip to content

Commit

Permalink
chore(script): fix coverage setup (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Sep 12, 2024
1 parent 4fc0057 commit 8461f44
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 16 deletions.
54 changes: 40 additions & 14 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Pixa Continuous Integration
name: Arcadia Continuous Integration

on:
push:

Expand All @@ -7,24 +8,31 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
- uses: actions/setup-go@v4
with:
go-version: 1.22
- uses: actions/checkout@v4
go-version: 1.23
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v3
with:
version: v1.56.2
version: v1.60.3
args: --verbose

test:
strategy:
matrix:
go-version: [1.22]
go-version: [1.23]
platform: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.platform }}

env:
COVER_DIR: ${{ github.workspace }}/coverage
COVER_FILE: coverage.out
COVER_OUT_PATH: ${{ github.workspace }}/coverage/coverage.out
COVER_HTML_PATH: ${{ github.workspace }}/coverage/coverage.html
GINKGO_REPORT: ginkgo.report

steps:
- name: Install Go
uses: actions/setup-go@v5
Expand All @@ -34,16 +42,34 @@ jobs:
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest

- name: Install ginkgo
run: go install github.com/onsi/ginkgo/v2/[email protected]

- name: Checkout code
uses: actions/checkout@v4

- run: go test -v -coverprofile=coverage.out ./...
- name: Ensure coverage directory exists
run: |
mkdir -p ${{ github.workspace }}/coverage
- name: Run tests and generate coverage profile with Ginkgo
run: |
ginkgo run -r -json-report {{env.GINKGO_REPORT}} -coverpkg=./... -coverprofile=coverage.out
- uses: shogo82148/actions-goveralls@v1
- name: Apply coverage exclusions
run: |
${{ github.workspace }}/scripts/apply-coverage-exclusions.sh
- name: Check coverage directory contents
run: |
echo "Contents of ${{ github.workspace }}/coverage:"
ls -la ${{ github.workspace }}/coverage
- name: Generate HTML coverage report
run: |
go tool cover -html=coverage.out -o ${{ github.workspace }}/coverage/coverage.html
- name: Upload coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.out -service=github
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
coverage
coverage.out
ginkgo.report
report.json
coverage.html

dist/
.task/

Expand Down
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
],
"cSpell.words": [
"bodyclose",
"cmds",
"cobrass",
"coverpkg",
"coverprofile",
"cubiest",
"deadcode",
"depguard",
"dogsled",
"dotenv",
"dupl",
"errcheck",
"exportloopref",
"extendio",
"fieldalignment",
"GOARCH",
"goconst",
"gocritic",
"gocyclo",
Expand All @@ -39,6 +43,7 @@
"nolintlint",
"nosec",
"onsi",
"outdir",
"pixa",
"prealloc",
"repotoken",
Expand All @@ -54,6 +59,7 @@
"typecheck",
"unconvert",
"unparam",
"varcheck"
"varcheck",
"watchv"
]
}
35 changes: 34 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ vars:
ACTIVE_US: "{{.BINARY_NAME}}.active.en-US.{{.FORMAT}}"
TRANSLATE_US: "{{.BINARY_NAME}}.translate.en-US.{{.FORMAT}}"
TRANSLATE_US_FILE: "{{.US_OUT_DIR}}/{{.TRANSLATE_US}}"
#
COVER_DIR: "./"
COVER_FILE: "coverage.out"
COVER_HTML_PATH: "./coverage.html"
GINKGO_REPORT: "ginkgo.report"

tasks:
# === build =================================================
Expand Down Expand Up @@ -160,10 +165,38 @@ tasks:

# === coverage =============================================

cover:
cover-clean:
cmds:
- rm -rf ./coverage

cover-publish:
cmds:
- goveralls -repotoken {{.COVERALLS_TOKEN}}

cover-setup:
cmds:
- mkdir -p ./coverage

cover-ginkgo:
cmds:
- ginkgo run -r -json-report {{.GINKGO_REPORT}} -coverpkg=./... -coverprofile={{.COVER_FILE}} --output-dir {{.COVER_DIR}}

cover-show:
cmds:
- open {{.COVER_HTML_PATH}}

cover-exclude:
cmds:
- ./scripts/apply-coverage-exclusions.sh

cover:
cmds:
- task: cover-setup
- task: cover-ginkgo
- task: cover-exclude
- go tool cover -html=./coverage.out -o {{.COVER_HTML_PATH}}
- open {{.COVER_HTML_PATH}}

# === i18n =================================================

clear:
Expand Down
34 changes: 34 additions & 0 deletions scripts/apply-coverage-exclusions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Define paths relative to the root directory
ROOT_DIR="$(git rev-parse --show-toplevel)"
COVERAGE_FILE="$ROOT_DIR/coverage.out"
EXCLUSIONS_FILE="$ROOT_DIR/scripts/coverage-exclusion-list.txt"

# Check if required files exist
if [ ! -f "$COVERAGE_FILE" ]; then
echo "Error: Coverage file not found at $COVERAGE_FILE"
exit 1
fi

if [ ! -f "$EXCLUSIONS_FILE" ]; then
echo "Error: Exclusions file not found at $EXCLUSIONS_FILE"
exit 1
fi

# Create a temporary file
TEMP_FILE=$(mktemp)

# Process the exclusions
while IFS= read -r line || [[ -n "$line" ]]; do
# Escape special characters in the line for use in sed
escaped_line=$(echo "$line" | sed 's/[\/&]/\\&/g')

# Remove matching lines from the coverage file
sed "/${escaped_line}/d" "$COVERAGE_FILE" > "$TEMP_FILE"

# Replace the original file with the modified content
mv "$TEMP_FILE" "$COVERAGE_FILE"
done < "$EXCLUSIONS_FILE"

echo "Coverage exclusions have been applied successfully."
3 changes: 3 additions & 0 deletions scripts/coverage-exclusion-list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github.com/snivilised/traverse/enums
github.com/snivilised/traverse/internal/third
github.com/snivilised/traverse/internal/laboratory/

0 comments on commit 8461f44

Please sign in to comment.