Tests and Quality Analysis triggered by stonedu1011 #126
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: | |
# Workflow runs when manually triggered using the UI or API. | |
workflow_dispatch: | |
inputs: | |
reason: | |
description: 'Reason of manually triggering this workflow' | |
default: 'Unspecified' | |
required: false | |
type: string | |
branch: | |
description: 'Target Branch' | |
default: 'main' | |
required: true | |
type: string | |
low_cov: | |
description: 'Coverage percentage to pass' | |
default: 50 | |
required: false | |
type: number | |
high_cov: | |
description: 'Coverage percentage to warn' | |
default: 70 | |
required: false | |
type: number | |
# Workflow runs on scheduled time | |
schedule: | |
- cron: '0 6 * * 1,3,5' | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
main: | |
name: Test, Analyze Code & Report | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Context" | |
shell: bash | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: "Checkout Actions" | |
uses: actions/checkout@v4 | |
with: | |
# For security reasons, we only uses actions in "main" branch | |
ref: ${{ github.event.repository.default_branch }} | |
sparse-checkout: .github/actions | |
path: .tmp | |
- name: "Prepare" | |
uses: ./.tmp/.github/actions/prepare | |
with: | |
branch: ${{ github.head_ref || inputs.branch || 'main' }} | |
- name: "Test & Code Quality" | |
uses: ./.tmp/.github/actions/verify | |
- name: "Generate Code Coverage Badge" | |
if: ${{ !cancelled() && github.event_name != 'pull_request' }} | |
run: | | |
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: "Generate 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: "Upload Badges" | |
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 | |