@@ -15,26 +15,28 @@ jobs:
1515 ports :
1616 - 2375:2375
1717 steps :
18- - name : Checkout code
18+ - name : Checkout base commit
19+ uses : actions/checkout@v4
20+ with :
21+ ref : ${{ github.event.pull_request.base.sha }}
22+ - name : Run tests on base commit and calculate previous coverage
23+ run : |
24+ POSTGRES_CONTAINER=1 VERNEMQ_CONTAINER=1 go test -v -coverpkg=./internal/... -coverprofile=base_profile.cov ./internal/...
25+ PREVIOUS_COVERAGE=$(go tool cover -func base_profile.cov | grep total | awk '{print $3}' | tr -d '%')
26+ echo "PREVIOUS_COVERAGE=$PREVIOUS_COVERAGE" >> $GITHUB_ENV
27+ - name : Checkout PR code
1928 uses : actions/checkout@v4
2029 - name : Set up Go
2130 uses : actions/setup-go@v5
2231 with :
2332 go-version : 1.24.2
2433 - name : Run tests and calculate coverage
2534 run : |
26- POSTGRES_CONTAINER=1 VERNEMQ_CONTAINER=1 go test -v -coverpkg=./... -coverprofile=profile.cov ./...
27- CURRENT_COVERAGE=$(go tool cover -func profile.cov | grep total | awk '{print $3}' | tr -d '%')
28- echo "CURRENT_COVERAGE=$CURRENT_COVERAGE" >> $GITHUB_ENV
29- if [ -f previous_coverage.txt ]; then
30- PREVIOUS_COVERAGE=$(cat previous_coverage.txt)
31- else
32- PREVIOUS_COVERAGE=0
33- fi
34- echo "PREVIOUS_COVERAGE=$PREVIOUS_COVERAGE" >> $GITHUB_ENV
35+ POSTGRES_CONTAINER=1 VERNEMQ_CONTAINER=1 go test -v -coverpkg=./internal/... -coverprofile=pr_profile.cov ./internal/...
36+ CURRENT_COVERAGE=$(go tool cover -func pr_profile.cov | grep total | awk '{print $3}' | tr -d '%')
3537 CHANGE=$(echo "$CURRENT_COVERAGE - $PREVIOUS_COVERAGE" | bc)
38+ echo "CURRENT_COVERAGE=$CURRENT_COVERAGE" >> $GITHUB_ENV
3639 echo "CHANGE=$CHANGE" >> $GITHUB_ENV
37- echo "$CURRENT_COVERAGE" > previous_coverage.txt
3840 - name : Delete old coverage comments
3941 uses : actions/github-script@v7
4042 with :
6365 const change = process.env.CHANGE || 'unknown';
6466 const commentBody = `
6567 <!-- coverage-comment -->
66- Coverage : **${currentCoverage}%** (${change >= 0 ? '+' : ''}${change}%)
68+ `internal/` coverage : **${currentCoverage}%** (${change >= 0 ? '+' : ''}${change}%)
6769 `;
6870 await github.rest.issues.createComment({
6971 issue_number: context.issue.number,
0 commit comments