Skip to content

fix: dws-3657 vanta security fixes (#36) #88

fix: dws-3657 vanta security fixes (#36)

fix: dws-3657 vanta security fixes (#36) #88

Workflow file for this run

name: Go Build and Test
on:
push:
branches:
- main
pull_request:
branches:
- main
types: [opened, closed, reopened]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
test:
runs-on: ubuntu-latest
outputs:
coverage: ${{ steps.coverage-check.outputs.coverage }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'
- name: Checkout code
uses: actions/checkout@v3
- name: Run golang test
run: go test -v ./... -coverprofile ./coverage.out
- name: Coverage check
id: coverage-check
run: |
echo "Quality Gate: checking test coverage is above threshold"
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "coverage=$totalCoverage" >> "$GITHUB_OUTPUT"
echo "Threshold: ${{ vars.TEST_COVERAGE_THRESHOLD }}"
echo "Current total coverage: $totalCoverage %"
if (($(echo "$totalCoverage ${{ vars.TEST_COVERAGE_THRESHOLD }}" | awk '{print ($1 >= $2)}') )); then
echo 'Passed'
else
echo "Current test coverage is below threshold. Please add more unit tests."
echo "Fail"
exit 1
fi
- uses: actions/github-script@v7
if: ${{ success() && steps.coverage-check.conclusion == 'success' && (github.event.action == 'opened' || github.event.action == 'reopened') }}
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Current total test coverage: ${{ steps.coverage-check.outputs.coverage }}%
Quality gate passed :white_check_mark:`
})
- uses: actions/github-script@v7
if: ${{ failure() && steps.coverage-check.conclusion == 'failure' && (github.event.action == 'opened' || github.event.action == 'reopened') }}
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Current total test coverage: ${{ steps.coverage-check.outputs.coverage }}%
Coverage threshold: ${{ vars.TEST_COVERAGE_THRESHOLD }}%.
Quality gate check failed :x:
Current test coverage is below threshold. Please add more unit tests.`
})