Rate limiter #126
Workflow file for this run
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: CI build | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.26' | |
| cache: true | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| cache-dependency-path: webapp/package-lock.json | |
| - name: Generate API client | |
| run: npx --yes @hey-api/openapi-ts -i ./api/taronja-gateway-api.yaml -o webapp/src/apiclient -c @hey-api/client-fetch | |
| - name: Build React App | |
| run: | | |
| cd webapp | |
| npm install | |
| npm run build | |
| cd .. | |
| - name: Build Go | |
| run: go build -v ./... | |
| - name: Set environment variable | |
| run: echo "RUNNING_ON_CI=true" >> $GITHUB_ENV | |
| - name: Test | |
| run: | | |
| go test -v -coverprofile=coverage.out ./... | |
| go tool cover -func=coverage.out > coverage_full.txt | |
| # Extract per-package coverage, excluding lines with "total:" | |
| awk '!/^total:/ { pkg_and_file = $1; sub(/\/[^\/]+:[0-9]+:$/, "", pkg_and_file); current_pkg = pkg_and_file; raw_coverage = $NF; sub(/%/, "", raw_coverage); numeric_coverage = raw_coverage + 0.0; coverage[current_pkg]+=numeric_coverage; count[current_pkg]++ } END { for (pkg in coverage) { if (count[pkg] > 0) { printf "%s %.1f%\n", pkg, coverage[pkg]/count[pkg] } else { printf "%s 0.0%\n", pkg } } }' coverage_full.txt > package_coverage.txt | |
| # Extract total coverage | |
| grep total: coverage_full.txt | awk '{print "Total " $3}' >> package_coverage.txt | |
| echo "Tests completed" | |
| - name: Post Coverage Comment | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const report = fs.readFileSync('package_coverage.txt', 'utf8'); | |
| const lines = report.trim().split('\n'); | |
| let table = `<!-- coverage_comment -->\n`; | |
| table += `**Code Coverage Report**\n\n`; | |
| table += `| Package | Coverage |\n`; | |
| table += `|------------------|----------|\n`; | |
| let totalCoverageLine = ""; // Store the full line for total coverage | |
| for (const line of lines) { | |
| if (line.startsWith('Total ')) { | |
| totalCoverageLine = line; // Save the total line to be added last | |
| continue; // Skip processing for the table body | |
| } | |
| // Attempt to split the line into package name and coverage percentage | |
| const lastSpaceIndex = line.lastIndexOf(' '); | |
| if (lastSpaceIndex === -1 || lastSpaceIndex === 0 || lastSpaceIndex === line.length - 1) { | |
| console.warn(`Skipping malformed line: ${line}`); | |
| continue; // Skip lines that don't have a clear space separation | |
| } | |
| const pkgName = line.substring(0, lastSpaceIndex); | |
| const coverage = line.substring(lastSpaceIndex + 1); | |
| // Validate coverage format (e.g., ends with %, and the part before % is a number) | |
| if (!coverage.endsWith('%') || isNaN(parseFloat(coverage.slice(0, -1)))) { | |
| console.warn(`Skipping line with invalid coverage format: ${line}`); | |
| continue; | |
| } | |
| table += `| ${pkgName} | ${coverage} |\n`; | |
| } | |
| // Add the total coverage line at the end | |
| if (totalCoverageLine) { | |
| const parts = totalCoverageLine.split(' '); // "Total" and "xx.x%" | |
| if (parts.length === 2 && parts[1].endsWith('%') && !isNaN(parseFloat(parts[1].slice(0,-1)))) { | |
| table += `| **${parts[0]}** | **${parts[1]}** |\n`; | |
| } else { | |
| console.warn(`Malformed total line: ${totalCoverageLine}`); | |
| table += `| **Total** | **Error** |\n`; // Indicate an error in total line | |
| } | |
| } else { | |
| console.warn('Total coverage line not found in package_coverage.txt'); | |
| table += `| **Total** | **N/A** |\n`; // Fallback if total line is missing | |
| } | |
| const commentBody = table; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existingComment = comments.find(c => c.body.includes('<!-- coverage_comment -->')); | |
| if (existingComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existingComment.id, | |
| body: commentBody, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: commentBody, | |
| }); | |
| } | |
| - name: Check GoReleaser Config | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| version: "~> v2" | |
| args: check |