Skip to content

again, optimizing badges. Added coverage. #15

again, optimizing badges. Added coverage.

again, optimizing badges. Added coverage. #15

Workflow file for this run

name: Go Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch: # Allows manual trigger
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Secrets
run: |
if [ -z "${{ secrets.DYNAMIC_GIST_ACTION }}" ]; then
echo "Error: GIST_SECRET is not set"
exit 1
fi
if [ -z "${{ secrets.DYNA_GIST_ID }}" ]; then
echo "Error: DYNA_GIST_ID is not set"
exit 1
fi
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run Tests and Count
run: |
cd go-app
# Run tests and store the pass/fail status
go test -v ./... 2>&1 | tee test_output.txt
TEST_COUNT=$(grep -c "^=== RUN" test_output.txt)
echo "TEST_COUNT=$TEST_COUNT" >> $GITHUB_ENV
- name: Generate Coverage
run: |
cd go-app
go test -race -coverprofile=coverage.out -covermode=atomic ./...
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%')
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
go-app/test_output.txt
go-app/coverage.out
- name: Create Test Count Badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.DYNAMIC_GIST_ACTION }}
gistID: ${{ secrets.DYNA_GIST_ID }}
filename: minion-testresults.json
label: Tests
message: ${{ env.TEST_COUNT }} ${{ job.status == 'success' && 'passed' || 'failed' }}
color: ${{ job.status == 'success' && 'green' || 'red' }}
if: always()
- name: Create Coverage Badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.DYNAMIC_GIST_ACTION }}
gistID: ${{ secrets.DYNA_GIST_ID }}
filename: minion-coverage.json
label: Coverage
message: ${{ env.COVERAGE }}%
color: ${{ env.COVERAGE >= 80 && 'green' || env.COVERAGE >= 60 && 'yellow' || 'red' }}
if: always()