ci(pr-validation): replace manual badge/gate logic with vociferate actions
- Remove manual changelog validation shell script - Remove AWS CLI install and jq tooling steps - Remove hand-rolled SVG badge generation, S3 upload, and PR comment steps - Replace with coverage-badge@v1.1.0 for coverage artefact upload - Replace with decorate-pr@v1.1.0 for PR comment and changelog gate (enable-changelog-gate: true, changelog-gate-mode: strict) - Retain per-package coverage gate awk logic (Aether threshold enforcement)
This commit is contained in:
@@ -26,6 +26,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
@@ -53,20 +55,6 @@ jobs:
|
||||
git diff --exit-code go.mod go.sum
|
||||
go mod verify
|
||||
|
||||
- name: Install AWS CLI v2
|
||||
uses: ankurk91/install-aws-cli-action@v1
|
||||
|
||||
- name: Ensure tooling is available
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
aws --version
|
||||
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
apt-get update
|
||||
apt-get install -y jq
|
||||
fi
|
||||
|
||||
- name: Prepare test runtime
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -81,11 +69,6 @@ jobs:
|
||||
set -euo pipefail
|
||||
|
||||
go test -covermode=atomic -coverprofile=coverage.out ./... | tee go-test-coverage.log
|
||||
go tool cover -html=coverage.out -o coverage.html
|
||||
|
||||
total="$(go tool cover -func=coverage.out | awk '/^total:/ {sub(/%/, "", $3); print $3}')"
|
||||
printf '{\n "total": "%s"\n}\n' "$total" > coverage-summary.json
|
||||
printf 'total=%s\n' "$total" >> "$GITHUB_OUTPUT"
|
||||
|
||||
set +e
|
||||
awk '
|
||||
@@ -164,106 +147,29 @@ jobs:
|
||||
env:
|
||||
GOTOOLCHAIN: auto
|
||||
|
||||
- name: Generate coverage badge
|
||||
env:
|
||||
COVERAGE_TOTAL: ${{ steps.coverage.outputs.total }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
- name: Upload coverage badge
|
||||
id: badge
|
||||
uses: https://git.hrafn.xyz/aether/vociferate/coverage-badge@v1.1.0
|
||||
with:
|
||||
artefact-bucket-name: ${{ vars.ARTEFACT_BUCKET_NAME }}
|
||||
artefact-bucket-endpoint: ${{ vars.ARTEFACT_BUCKET_ENDPONT }}
|
||||
|
||||
color="$(awk -v total="$COVERAGE_TOTAL" 'BEGIN {
|
||||
if (total >= 80) print "brightgreen";
|
||||
else if (total >= 70) print "green";
|
||||
else if (total >= 60) print "yellowgreen";
|
||||
else if (total >= 50) print "yellow";
|
||||
else print "red";
|
||||
}')"
|
||||
|
||||
cat > coverage-badge.svg <<EOF
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="126" height="20" role="img" aria-label="coverage: ${COVERAGE_TOTAL}%">
|
||||
<linearGradient id="smooth" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<clipPath id="round">
|
||||
<rect width="126" height="20" rx="3" fill="#fff"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#round)">
|
||||
<rect width="63" height="20" fill="#555"/>
|
||||
<rect x="63" width="63" height="20" fill="${color}"/>
|
||||
<rect width="126" height="20" fill="url(#smooth)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="32.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
||||
<text x="32.5" y="14">coverage</text>
|
||||
<text x="93.5" y="15" fill="#010101" fill-opacity=".3">${COVERAGE_TOTAL}%</text>
|
||||
<text x="93.5" y="14">${COVERAGE_TOTAL}%</text>
|
||||
</g>
|
||||
</svg>
|
||||
EOF
|
||||
|
||||
- name: Upload PR coverage artefacts
|
||||
id: upload
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
aws configure set default.s3.addressing_style path
|
||||
|
||||
repo_name="${GITHUB_REPOSITORY##*/}"
|
||||
prefix="${repo_name}/pull-requests/${{ github.event.pull_request.number }}"
|
||||
report_url="${ARTEFACT_BUCKET_ENDPONT%/}/${ARTEFACT_BUCKET_NAME}/${prefix}/coverage.html"
|
||||
badge_url="${ARTEFACT_BUCKET_ENDPONT%/}/${ARTEFACT_BUCKET_NAME}/${prefix}/coverage-badge.svg"
|
||||
|
||||
aws --endpoint-url "${ARTEFACT_BUCKET_ENDPONT}" s3 cp coverage.html "s3://${ARTEFACT_BUCKET_NAME}/${prefix}/coverage.html" --content-type text/html
|
||||
aws --endpoint-url "${ARTEFACT_BUCKET_ENDPONT}" s3 cp coverage-badge.svg "s3://${ARTEFACT_BUCKET_NAME}/${prefix}/coverage-badge.svg" --content-type image/svg+xml
|
||||
aws --endpoint-url "${ARTEFACT_BUCKET_ENDPONT}" s3 cp coverage-summary.json "s3://${ARTEFACT_BUCKET_NAME}/${prefix}/coverage-summary.json" --content-type application/json
|
||||
|
||||
printf 'report_url=%s\n' "$report_url" >> "$GITHUB_OUTPUT"
|
||||
printf 'badge_url=%s\n' "$badge_url" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Comment coverage report on pull request
|
||||
env:
|
||||
COVERAGE_BADGE_URL: ${{ steps.upload.outputs.badge_url }}
|
||||
COVERAGE_REPORT_URL: ${{ steps.upload.outputs.report_url }}
|
||||
COVERAGE_TOTAL: ${{ steps.coverage.outputs.total }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
marker='<!-- gosick-coverage-report -->'
|
||||
api_base="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
|
||||
payload="$(jq -n \
|
||||
--arg marker "$marker" \
|
||||
--arg total "$COVERAGE_TOTAL" \
|
||||
--arg report "$COVERAGE_REPORT_URL" \
|
||||
--arg badge "$COVERAGE_BADGE_URL" \
|
||||
'{body: ($marker + "\n## Coverage Report\n\nCoverage total: **" + $total + "%**\n\n[HTML report](" + $report + ")\n\n")}')"
|
||||
|
||||
comments="$(curl -sS -H "Authorization: token ${GITHUB_TOKEN}" "${api_base}/issues/${{ github.event.pull_request.number }}/comments")"
|
||||
comment_id="$(printf '%s' "$comments" | jq -r '.[] | select(.body | contains("<!-- gosick-coverage-report -->")) | .id' | tail -n 1)"
|
||||
|
||||
if [[ -n "$comment_id" ]]; then
|
||||
curl -sS -X PATCH \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$payload" \
|
||||
"${api_base}/issues/comments/${comment_id}" >/dev/null
|
||||
else
|
||||
curl -sS -X POST \
|
||||
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$payload" \
|
||||
"${api_base}/issues/${{ github.event.pull_request.number }}/comments" >/dev/null
|
||||
fi
|
||||
- name: Decorate PR
|
||||
uses: https://git.hrafn.xyz/aether/vociferate/decorate-pr@v1.1.0
|
||||
with:
|
||||
coverage-percentage: ${{ steps.badge.outputs.total }}
|
||||
badge-url: ${{ steps.badge.outputs.badge-url }}
|
||||
enable-changelog-gate: 'true'
|
||||
changelog-gate-mode: strict
|
||||
|
||||
- name: Add coverage summary
|
||||
run: |
|
||||
{
|
||||
echo '## Coverage'
|
||||
echo
|
||||
echo '- Total: `${{ steps.coverage.outputs.total }}%`'
|
||||
echo '- Report: ${{ steps.upload.outputs.report_url }}'
|
||||
echo '- Badge: ${{ steps.upload.outputs.badge_url }}'
|
||||
echo '- Total: `${{ steps.badge.outputs.total }}%`'
|
||||
echo '- Report: ${{ steps.badge.outputs.report-url }}'
|
||||
echo '- Badge: ${{ steps.badge.outputs.badge-url }}'
|
||||
echo
|
||||
echo '### Package Coverage'
|
||||
cat coverage-packages.md
|
||||
|
||||
Reference in New Issue
Block a user