Skip to content

wip

wip #11

Workflow file for this run

name: Build
permissions:
contents: write
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go:
- "stable"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
persist-credentials: true
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Go generate
run: go generate ./...
- name: Test
run: go test -tags debug -bench=. -coverprofile=coverage.out ./...
- name: Coverage
id: coverage
run: |
echo "COVERAGE=$(go tool cover -func=coverage.out | tail -n 1 | tr -s '\t' | cut -f 3)" >> $GITHUB_OUTPUT
go tool cover -html=coverage.out -o=coveragereport.out
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
- name: Build
run: go build .
- name: Go report card
uses: creekorful/goreportcard-action@v1.0
- name: Publish badge (and optional report)
uses: ./.github/actions/gitcoverage
with:
coverage: ${{ steps.coverage.outputs.coverage }}
report: "coveragereport.out"
# Generate code coverage badge and push it to the 'coverage' branch.
# Reference it in your README.md like this:
#
# [![coverage](https://github.com/USERNAME/REPO/blob/coverage/BRANCH/badge.svg)](#)
#
# If you have a detailed HTML report of the coverage (here called report.html), replace the '#' with:
#
# https://htmlpreview.github.io/?https://github.com/USERNAME/REPO/blob/coverage/BRANCH/report.html
#
# You need to have given write permissions for the for the workflow:
#
# permissions:
# contents: write
#
# To create the 'coverage' branch for the repository (replace 'main' with the branch you want to publish for):
#
# git checkout main
# git checkout --orphan coverage && git rm --cached $(git ls-files) && echo '# Coverage branch' > README.md
# git add README.md && git commit -m 'Add README.md' && git push origin coverage
# git checkout --force main
# - name: Extract branch name
# run: echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
# id: extract_branch
# - uses: actions/checkout@v3
# with:
# ref: coverage
# path: coverage
# - name: Ensure directories for this branch exist
# env:
# BRANCH: ${{ steps.extract_branch.outputs.branch }}
# run: mkdir -p coverage/${BRANCH}
# - name: Extract code coverage
# id: coverage
# env:
# BRANCH: ${{ steps.extract_branch.outputs.branch }}
# # Change this to extract the coverage percentage (without the percent sign) for your language into COVERAGE.
# # Here we are using a 'coverage.out' file generated by 'go test -coverprofile=coverage.out ./...'
# # You may also generate a HTML report and place at 'coverage/${BRANCH}/report.html'.
# run: |
# echo "COVERAGE=$(go tool cover -func=coverage.out | tail -n 1 | tr -s '\t' | cut -f 3 | rev | cut -c2- | rev)" >> $GITHUB_OUTPUT
# go tool cover -html=coverage.out -o=coverage/${BRANCH}/report.html
# - name: Generate the badge SVG image
# uses: emibcn/badge-action@v2.0.3
# with:
# label: 'coverage'
# status: ${{ steps.coverage.outputs.coverage }}%
# path: coverage/${{ steps.extract_branch.outputs.branch }}/badge.svg
# color: ${{
# steps.coverage.outputs.coverage > 95 && 'green' ||
# steps.coverage.outputs.coverage > 90 && 'yellow,green,green' ||
# steps.coverage.outputs.coverage > 80 && 'yellow,green' ||
# steps.coverage.outputs.coverage > 70 && 'yellow' ||
# steps.coverage.outputs.coverage > 60 && 'orange,yellow' ||
# steps.coverage.outputs.coverage > 50 && 'orange' ||
# steps.coverage.outputs.coverage > 40 && 'red,orange' ||
# steps.coverage.outputs.coverage > 30 && 'red,red,orange' ||
# steps.coverage.outputs.coverage > 20 && 'red,red,red,orange' ||
# 'red' }}
# - name: Commit coverage files
# env:
# BRANCH: ${{ steps.extract_branch.outputs.branch }}
# run: |
# pushd coverage
# git config --local user.email "action@github.com"
# git config --local user.name "GitHub Action"
# test ! -f "${BRANCH}/badge.svg" || git add "${BRANCH}/badge.svg"
# test ! -f "${BRANCH}/report.html" || git add "${BRANCH}/report.html"
# test -z "$(git status --porcelain)" || git commit -m "update"
# git push
# popd