-
Notifications
You must be signed in to change notification settings - Fork 3
96 lines (92 loc) · 3.5 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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