Tests and Quality Analysis triggered by stonedu1011 #5
This file contains 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
# This is a basic workflow that is manually triggered | |
name: CI | |
run-name: Tests and Quality Analysis triggered by ${{ github.actor }} | |
# Controls when the action will run. | |
on: | |
# PR verification, we disabled it for now | |
# pull_request: | |
# branches: [ "main" ] | |
# Workflow runs when manually triggered using the UI or API. | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: 'Target Branch' | |
default: 'main' | |
required: true | |
type: string | |
reason: | |
description: 'Reason of manually triggering this workflow' | |
default: 'Unspecified' | |
required: false | |
type: string | |
low_cov: | |
description: 'Coverage percentage to pass' | |
default: '50' | |
required: false | |
type: int | |
high_cov: | |
description: 'Coverage percentage to warn' | |
default: '70' | |
required: false | |
type: int | |
env: | |
COVERAGE_EXCLUSION_REGEX: ^(.*\/test\/.*)|(.*\/cmd\/.*)|(.*\/testdata\/.*) | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
test_and_verify: | |
name: Tests & Code Quality | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Checkout" | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref || inputs.branch || 'main' }} | |
- name: "Setup Go" | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: 'go.mod' | |
cache-dependency-path: "**/*.sum" | |
- name: "Prepare" | |
run: make init SHELL=/bin/bash | |
- name: "Run Tests with Coverage" | |
run: | | |
make test report SHELL=/bin/bash ARGS="-coverpkg $(go list ./pkg/... | grep -v .*/test | grep -v .*_test | paste -sd ',' -)" | |
go tool cover -func=dist/coverage.out -o dist/coverage-func.out | |
export COVERAGE=$(grep -E '([0-9]+[0-9.]+)' -o dist/coverage-func.out | tail -1) | |
export COVERAGE_COLOR=$( \ | |
( (( $(echo "${COVERAGE} >= ${{ inputs.high_cov }}" | bc) )) && echo "green" ) || \ | |
( (( $(echo "${COVERAGE} < ${{ inputs.low_cov }}" | bc) )) && echo "red" ) || \ | |
echo "yellow" \ | |
) | |
curl https://img.shields.io/badge/Coverage-${COVERAGE}%25-${COVERAGE_COLOR} > dist/coverage-badge.svg | |
- name: "Code Quality Analysis" | |
run: make lint SHELL=/bin/bash | |
- name: "Code Coverage Report" | |
if: ${{ !cancelled() && github.event_name != 'pull_request' }} | |
uses: irongut/[email protected] | |
with: | |
filename: dist/cobertura-coverage.xml | |
badge: true | |
fail_below_min: true | |
indicators: false | |
format: markdown | |
output: both | |
thresholds: "${{ inputs.low_cov }} ${{ inputs.high_cov }}" | |
- name: "Code Coverage Badge" | |
if: ${{ !cancelled() && github.event_name != 'pull_request' }} | |
uses: exuanbo/actions-deploy-gist@v1 | |
with: | |
token: ${{ secrets.COVERAGE_BADGE_GIST_TOKEN }} | |
gist_id: 82b48469578014fc69d5aa64ef0a443f | |
gist_file_name: go-lanai-${{ github.head_ref || inputs.branch || 'main' }}-coverage.svg | |
file_path: dist/coverage-badge.svg | |
- name: "Upload Reports" | |
if: ${{ !cancelled() && github.event_name != 'pull_request' }} | |
uses: exuanbo/actions-deploy-gist@v1 | |
with: | |
token: ${{ secrets.COVERAGE_BADGE_GIST_TOKEN }} | |
gist_id: 82b48469578014fc69d5aa64ef0a443f | |
gist_file_name: go-lanai-${{ github.head_ref || inputs.branch || 'main' }}-coverage.md | |
file_path: code-coverage-results.md | |