gosick #1

Merged
DelphicOkami merged 162 commits from gosick into main 2026-03-21 23:08:00 +00:00
Showing only changes of commit 014b330931 - Show all commits

View File

@@ -26,6 +26,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
@@ -53,20 +55,6 @@ jobs:
git diff --exit-code go.mod go.sum git diff --exit-code go.mod go.sum
go mod verify 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 - name: Prepare test runtime
run: | run: |
set -euo pipefail set -euo pipefail
@@ -81,11 +69,6 @@ jobs:
set -euo pipefail set -euo pipefail
go test -covermode=atomic -coverprofile=coverage.out ./... | tee go-test-coverage.log 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 set +e
awk ' awk '
@@ -164,106 +147,29 @@ jobs:
env: env:
GOTOOLCHAIN: auto GOTOOLCHAIN: auto
- name: Generate coverage badge - name: Upload coverage badge
env: id: badge
COVERAGE_TOTAL: ${{ steps.coverage.outputs.total }} uses: https://git.hrafn.xyz/aether/vociferate/coverage-badge@v1.1.0
run: | with:
set -euo pipefail artefact-bucket-name: ${{ vars.ARTEFACT_BUCKET_NAME }}
artefact-bucket-endpoint: ${{ vars.ARTEFACT_BUCKET_ENDPONT }}
color="$(awk -v total="$COVERAGE_TOTAL" 'BEGIN { - name: Decorate PR
if (total >= 80) print "brightgreen"; uses: https://git.hrafn.xyz/aether/vociferate/decorate-pr@v1.1.0
else if (total >= 70) print "green"; with:
else if (total >= 60) print "yellowgreen"; coverage-percentage: ${{ steps.badge.outputs.total }}
else if (total >= 50) print "yellow"; badge-url: ${{ steps.badge.outputs.badge-url }}
else print "red"; enable-changelog-gate: 'true'
}')" changelog-gate-mode: strict
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![Coverage badge](" + $badge + ")")}')"
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: Add coverage summary - name: Add coverage summary
run: | run: |
{ {
echo '## Coverage' echo '## Coverage'
echo echo
echo '- Total: `${{ steps.coverage.outputs.total }}%`' echo '- Total: `${{ steps.badge.outputs.total }}%`'
echo '- Report: ${{ steps.upload.outputs.report_url }}' echo '- Report: ${{ steps.badge.outputs.report-url }}'
echo '- Badge: ${{ steps.upload.outputs.badge_url }}' echo '- Badge: ${{ steps.badge.outputs.badge-url }}'
echo echo
echo '### Package Coverage' echo '### Package Coverage'
cat coverage-packages.md cat coverage-packages.md