-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (137 loc) · 4.96 KB
/
Copy pathon-pr.yaml
File metadata and controls
153 lines (137 loc) · 4.96 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2025 NVIDIA CORPORATION
# SPDX-License-Identifier: Apache-2.0
name: KAI API - Pull Request
on:
pull_request:
types: [opened, reopened, synchronize]
merge_group:
types: [checks_requested]
concurrency:
group: ${{ github.event_name == 'merge_group' && github.ref || github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
check-build-and-test-required:
name: Check if build and test are required
runs-on: ubuntu-latest
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Check changed files
uses: dorny/paths-filter@v3
id: filter
with:
predicate-quantifier: "every"
filters: |
docs:
- '**/*.md'
- 'docs/**'
code:
- '**'
- '!**/*.md'
- '!docs/**'
validate-and-test:
needs: [ check-build-and-test-required ]
if: needs.check-build-and-test-required.outputs.code == 'true'
name: Validate & Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: '1.26.3'
cache: true
- name: Run validation
run: make validate
- name: Run tests
run: make test
- name: Archive code coverage results
uses: actions/upload-artifact@v7
with:
name: code-coverage
path: coverage/coverage.out
- name: Calculate total coverage
run: |
if [ ! -s coverage/coverage.out ]; then
exit 0
fi
COVERAGE=$(go tool cover -func=coverage/coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
echo "$COVERAGE" > coverage/total-coverage.txt
- name: Archive total coverage
if: hashFiles('coverage/total-coverage.txt') != ''
uses: actions/upload-artifact@v7
with:
name: total-coverage
path: coverage/total-coverage.txt
code-coverage-report:
name: Code Coverage Report
runs-on: ubuntu-latest
continue-on-error: true
needs: [ validate-and-test, check-build-and-test-required ]
if: github.event_name != 'merge_group' && needs.check-build-and-test-required.outputs.code == 'true' && github.base_ref == 'main'
steps:
- uses: fgrosse/go-coverage-report@cbeb2ab2e32591d690337146ba02a911cc566f3f
id: coverage_reporter
with:
coverage-artifact-name: "code-coverage"
coverage-file-name: "coverage.out"
root-package: "github.com/kai-scheduler/api"
github-baseline-workflow-ref: update-coverage-badge.yaml
skip-comment: true
- name: Download total coverage artifact
uses: actions/download-artifact@v8
with:
name: total-coverage
path: coverage-summary
- name: Download coverage badge branch
uses: actions/checkout@v7
with:
ref: coverage-badge
path: coverage-badge
- name: Calculate coverage totals
id: coverage_totals
run: |
PR_COVERAGE=$(cat coverage-summary/total-coverage.txt)
echo "pr=$PR_COVERAGE" >> $GITHUB_OUTPUT
BASELINE_COVERAGE=$(grep -oE '[0-9]+\.[0-9]+%' coverage-badge/badges/coverage.svg | head -1 | tr -d '%')
echo "baseline=$BASELINE_COVERAGE" >> $GITHUB_OUTPUT
DELTA=$(awk -v pr="$PR_COVERAGE" -v baseline="$BASELINE_COVERAGE" 'BEGIN { printf "%.2f", pr - baseline }')
echo "delta=$DELTA" >> $GITHUB_OUTPUT
- name: Save coverage report to file
env:
REPORT_BODY: ${{ steps.coverage_reporter.outputs.coverage_report }}
BASELINE_COVERAGE: ${{ steps.coverage_totals.outputs.baseline }}
PR_COVERAGE: ${{ steps.coverage_totals.outputs.pr }}
COVERAGE_DELTA: ${{ steps.coverage_totals.outputs.delta }}
run: |
{
echo "**Total coverage:** ${BASELINE_COVERAGE}% -> ${PR_COVERAGE}% (delta ${COVERAGE_DELTA}%)"
if [ -n "$REPORT_BODY" ]; then
echo ""
echo "$REPORT_BODY"
fi
} > coverage-report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v7
with:
name: coverage-report-for-comment
path: coverage-report.txt
- name: Save PR number
run: echo "${{ github.event.number }}" > pr_number.txt
- name: Upload PR number
uses: actions/upload-artifact@v7
with:
name: pr-number-for-comment
path: pr_number.txt
skip-build-and-test-message:
name: Skip Build and Test Message
needs: [ check-build-and-test-required ]
if: needs.check-build-and-test-required.outputs.code != 'true'
runs-on: ubuntu-latest
steps:
- name: Skip message
run: |
echo "Skipping build and test since only documentation files (.md or docs/) were changed."