-
Notifications
You must be signed in to change notification settings - Fork 31
81 lines (75 loc) · 3.03 KB
/
unit_tests.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
# Copyright 2024 The Sigstore Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Run unit tests
on:
pull_request:
branches: [main]
types: [opened, synchronize]
paths-ignore:
- '**/*.md'
- '*.md'
permissions: {}
defaults:
run:
shell: bash
jobs:
model-signing-unit-tests:
name: Signing with Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # Don't cancel other jobs if one fails
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Hatch
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
- name: Run unit tests (with coverage report at the end)
run: |
set -euxo pipefail
if [[ "${{ matrix.os }}" == "ubuntu-latest" && "${{ matrix.python-version }}" == "3.11" ]]; then
hatch test -c -py ${{ matrix.python-version }} | tee > cov.txt
else
hatch test -c -py ${{ matrix.python-version }}
fi
- name: Highlight missing lines
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
run: |
set -euxo pipefail
awk '/Name/{flag=1; next} /TOTAL/{flag=0; next} flag && !/^[-]+$/' cov.txt | while IFS= read -r line; do
# Extract file name and missing ranges
file_name=$(echo "$line" | awk '{print $1}')
missing_lines=$(echo "$line" | awk '{for (i=5; i<=NF; i++) printf $i " "; print ""}')
# Process each range
for range in $missing_lines; do
# Trim leading and trailing whitespace
range=$(echo "$range" | xargs)
line_start=""
line_end=""
message=""
if [[ "$range" == *"-"* ]]; then
# Split range into start and end
line_start=$(echo "$range" | cut -d'-' -f1)
line_end=$(echo "$range" | cut -d'-' -f2)
message="The following lines were not covered in your tests: $line_start to $line_end"
else
# Single line number
line_start=$range
line_end=$range
message="The following line was not covered in your tests: $line_start"
fi
echo "::warning file=$file_name,line=$line_start,endLine=$line_end::$message"
done
done