Skip to content

Commit 55fc0d5

Browse files
committed
add more yaml inputs
1 parent 07854ff commit 55fc0d5

7 files changed

Lines changed: 112 additions & 20 deletions

File tree

.github/workflows/CI.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ on:
2727
required: false
2828
default: "Release"
2929

30+
define:
31+
description: "Define constants to pass to the compiler"
32+
type: string
33+
default: ""
34+
required: false
35+
36+
verbose:
37+
description: "Whether to enable verbose logging"
38+
type: boolean
39+
default: false
40+
required: false
41+
3042
test-project:
3143
description: "Path to test project"
3244
type: string
@@ -89,6 +101,8 @@ jobs:
89101
os: ${{ inputs.os || vars.MATRIX_OS || '["ubuntu-latest"]' }}
90102
test-project: ${{ inputs.test-project || vars.TEST_PROJECT || './test/UlidType.Tests/UlidType.Tests.csproj' }}
91103
configuration: ${{ inputs.build-configuration ||vars.BUILD_CONFIGURATION || 'Release' }}
104+
define: ${{ inputs.define || vars.DEFINE || '' }}
105+
verbose: ${{ inputs.verbose || vars.VERBOSE || false }}
92106
min_coverage_pct: ${{ inputs.min_coverage_pct || fromJSON(vars.MIN_COVERAGE_PCT) || 75 }}
93107

94108
benchmarks:
@@ -101,5 +115,7 @@ jobs:
101115
os: ${{ inputs.os || vars.MATRIX_OS || '["ubuntu-latest"]' }}
102116
benchmark-project: ${{ inputs.benchmark-project || vars.BENCHMARK_PROJECT || './benchmarks/UlidType.Benchmarks/UlidType.Benchmarks.csproj' }}
103117
configuration: ${{ inputs.build-configuration ||vars.BUILD_CONFIGURATION || 'Release' }}
104-
force-new-baseline: ${{ inputs.force-new-baseline || fromJSON(vars.FORCE_NEW_BASELINE) || false }}
118+
define: ${{ inputs.define || vars.DEFINE || '' }}
119+
verbose: ${{ inputs.verbose || vars.VERBOSE || false }}
105120
max-regression-pct: ${{ inputs.max-regression-pct || fromJSON(vars.MAX_REGRESSION_PCT) || 10 }}
121+
force-new-baseline: ${{ inputs.force-new-baseline || fromJSON(vars.FORCE_NEW_BASELINE) || false }}

.github/workflows/benchmarks.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ on:
2020
required: false
2121
default: "Release"
2222

23+
define:
24+
description: "Define constants to pass to the compiler"
25+
type: string
26+
default: ""
27+
required: false
28+
29+
verbose:
30+
description: "Whether to enable verbose logging"
31+
type: boolean
32+
default: false
33+
required: false
34+
2335
force-new-baseline:
2436
description: "Ignore the existing baseline and force a new baseline"
2537
type: boolean
@@ -47,7 +59,7 @@ env:
4759
ARTIFACTS_DIR: BmArtifacts
4860
SUMMARIES_DIR: BmArtifacts/summaries
4961
BASELINE_DIR: BmArtifacts/baseline
50-
FORCE_NEW_BASELINE: false
62+
FORCE_NEW_BASELINE: ${{ inputs.force-new-baseline || vars.FORCE_NEW_BASELINE || false }}
5163

5264
jobs:
5365
benchmarks:
@@ -83,9 +95,12 @@ jobs:
8395
shell: bash
8496
env:
8597
FORCE_NEW_BASELINE: ${{ inputs.force-new-baseline }}
86-
CONFIGURATION: ${{ inputs.configuration }}
8798
run: |
88-
./scripts/bash/run-benchmarks.sh ${{ inputs.benchmark-project }}
99+
./scripts/bash/run-benchmarks.sh ${{ inputs.benchmark-project }} \
100+
--verbose "${{ inputs.verbose }}" \
101+
--max_regression_pct "${{ inputs.max-regression-pct }}" \
102+
--define "${{ inputs.define }}"
103+
--configuration "${{ inputs.configuration }}"
89104
90105
- name: Upload benchmark summaries artifact
91106
uses: actions/upload-artifact@v4

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,35 @@ on:
77
type: string
88
default: "9.0.x"
99
required: true
10+
1011
test-project:
1112
description: "Path to the test project"
1213
type: string
1314
required: false
15+
1416
configuration:
1517
description: "The type of build to produce, e.g. Release vs Debug"
1618
type: string
1719
required: false
1820
default: "Release"
21+
22+
define:
23+
description: "Define constants to pass to the compiler"
24+
type: string
25+
default: ""
26+
required: false
27+
28+
verbose:
29+
description: "Whether to enable verbose logging"
30+
type: boolean
31+
default: false
32+
required: false
33+
1934
min_coverage_pct:
2035
type: number
2136
required: true
2237
default: 75
38+
2339
os:
2440
description: "Runner OS-s"
2541
type: string

scripts/bash/run-benchmarks-utils.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Switches:
5252
--short-run | -s A shortcut for '--define SHORT_RUN'. See below.
5353
Initial value from \$DEFINE.
5454
55+
--force-new-baseline | -f
56+
When specified, a new baseline will be created even
57+
if a previous baseline already exists.
58+
Initial value from \$FORCE_NEW_BASELINE or 'false'
59+
5560
Options:
5661
--define | -d Defines one or more user-defined pre-processor
5762
symbols to be used when building the benchmark
@@ -123,6 +128,8 @@ function get_arguments()
123128

124129
--trace|-x ) trace_enabled=true; set -x ;;
125130

131+
--force-new-baseline|-f ) force_new_baseline=true ;;
132+
126133
--artifacts|-a ) value="$1"; shift; ARTIFACTS_DIR=$(realpath -m "$value") ;;
127134

128135
--max-regression-pct|-r )
@@ -140,18 +147,18 @@ function get_arguments()
140147
usage "The specified pre-processor symbol '$value' is not valid."
141148
exit 2
142149
fi
143-
if [[ -z "$DEFINE" ]]; then
144-
DEFINE="$value"
145-
elif [[ ! "$DEFINE" =~ (^|;)"$value"($|;) ]]; then
146-
DEFINE="$DEFINE;$value"
150+
if [[ -z "$define" ]]; then
151+
define="$value"
152+
elif [[ ! "$define" =~ (^|;)"$value"($|;) ]]; then
153+
define="$define;$value"
147154
fi
148155
;;
149156

150157
--short-run|-s )
151-
if [[ -z "$DEFINE" ]]; then
152-
DEFINE="SHORT_RUN"
153-
elif [[ ! "$DEFINE" =~ (^|;)SHORT_RUN($|;) ]]; then
154-
DEFINE="$DEFINE;SHORT_RUN"
158+
if [[ -z "$define" ]]; then
159+
define="SHORT_RUN"
160+
elif [[ ! "$define" =~ (^|;)SHORT_RUN($|;) ]]; then
161+
define="$define;SHORT_RUN"
155162
fi
156163
;;
157164

scripts/bash/run-benchmarks.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ bm_project=$(realpath -e "$bm_project") # ensure it's an absolute path and exis
1717
declare -x ARTIFACTS_DIR=${ARTIFACTS_DIR:="$solution_dir/BmArtifacts"}
1818
ARTIFACTS_DIR=$(realpath -m "$ARTIFACTS_DIR") # ensure it's an absolute path
1919

20+
declare -x force_new_baseline=${FORCE_NEW_BASELINE:-false}
21+
2022
declare configuration=${CONFIGURATION:="Release"}
2123

24+
declare define=${DEFINE:-}
25+
2226
source "$script_dir/_common.sh"
2327
source "$script_dir/run-benchmarks-utils.sh"
2428

2529
get_arguments "$@"
2630
declare -r bm_project
2731
declare -r configuration
32+
declare -r force_new_baseline
33+
declare -r define
2834

2935
declare -x results_dir=${results_dir:="$ARTIFACTS_DIR/results"}
3036
results_dir=$(realpath -m "$results_dir") # ensure it's an absolute path
@@ -38,12 +44,12 @@ declare -x baseline_dir=${baseline_dir:="$ARTIFACTS_DIR/baseline"}
3844
baseline_dir=$(realpath -m "$baseline_dir")
3945
declare -r baseline_dir
4046

41-
renamed_artifacts_dir="$ARTIFACTS_DIR-$(date -u +"%Y%m%dT%H%M%S")"
42-
declare -r renamed_artifacts_dir
43-
4447
max_regression_pct=${MAX_REGRESSION_PCT:-10}
4548
declare -ri max_regression_pct
4649

50+
renamed_artifacts_dir="$ARTIFACTS_DIR-$(date -u +"%Y%m%dT%H%M%S")"
51+
declare -r renamed_artifacts_dir
52+
4753
dump_all_variables
4854

4955
if [[ -d "$ARTIFACTS_DIR" && -n "$(ls -A "$ARTIFACTS_DIR")" ]]; then
@@ -84,7 +90,7 @@ execute mkdir -p "$summaries_dir"
8490
trace "Running benchmark tests in project '$bm_project' with configuration '$configuration'..."
8591
execute mkdir -p "$ARTIFACTS_DIR"
8692
execute dotnet run \
87-
/p:DefineConstants="$DEFINE" \
93+
/p:DefineConstants="$define" \
8894
--project "$bm_project" \
8995
--configuration "$configuration" \
9096
--filter '*' \
@@ -157,6 +163,12 @@ flush_stdout
157163

158164
if (( pct > max_regression_pct )); then
159165
echo "Performance regression exceeds threshold" >&2
166+
if [[ $force_new_baseline == "true" ]] && is_defined "GITHUB_ENV"; then
167+
echo "Significant regression of $pct% over baseline. Updating the baseline."
168+
# shellcheck disable=SC2154
169+
echo "FORCE_NEW_BASELINE=true" >> "$GITHUB_ENV"
170+
exit 0
171+
fi
160172
echo "If this is acceptable, please update the baseline by setting the variable 'FORCE_NEW_BASELINE=true'." >&2
161173
exit 2
162174
elif (( pct > 0 )); then

scripts/bash/run-test-utils.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,24 @@ Options:
5555
percentage (0-100).
5656
Initial value from \$MIN_COVERAGE_PCT or 80
5757
58-
--configuration | -c Specifies the build configuration to use ('Debug' or
59-
'Release').
60-
Initial value from \$CONFIGURATION or 'Release'
61-
6258
--artifacts | -a Specifies the directory where to create the script's
6359
artifacts: summary, report files, etc.
6460
Initial value from \$ARTIFACTS_DIR or
6561
'\$solution_dir/TestArtifacts'
6662
($solution_dir/TestArtifacts)
6763
64+
--configuration | -c Specifies the build configuration to use ('Debug' or
65+
'Release').
66+
Initial value from \$CONFIGURATION or 'Release'
67+
68+
--define | -d Defines one or more user-defined pre-processor
69+
symbols to be used when building the benchmark
70+
project, e.g. 'SHORT_RUN'. Which generates a shorter
71+
and faster, but less accurate benchmark run. You can
72+
specify this option multiple times to define multiple
73+
symbols.
74+
Initial value from \$DEFINE or ''
75+
6876
"
6977
if [[ "${#}" -gt 0 && -n "$1" ]]; then
7078
echo "$1" >&2
@@ -129,6 +137,19 @@ function get_arguments()
129137
configuration="${value^}"
130138
;;
131139

140+
--define|-d )
141+
value="$1"; shift
142+
if ! [[ "$value" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
143+
usage "The specified pre-processor symbol '$value' is not valid."
144+
exit 2
145+
fi
146+
if [[ -z "$define" ]]; then
147+
define="$value"
148+
elif [[ ! "$define" =~ (^|;)"$value"($|;) ]]; then
149+
define="$define;$value"
150+
fi
151+
;;
152+
132153
*) value="$flag"
133154
if ! p=$(realpath -e "$value"); then
134155
usage "The specified test project file '$value' does not exist."

scripts/bash/run-tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ declare -x COVERAGE_RESULTS_DIR
2222
declare configuration=${CONFIGURATION:="Release"}
2323
declare -i min_coverage_pct=${MIN_COVERAGE_PCT:-80}
2424

25+
declare define=${DEFINE:-}
26+
2527
source "$script_dir/_common.sh"
2628
source "$script_dir/run-test-utils.sh"
2729

2830
get_arguments "$@"
2931
declare -r test_project
3032
declare -ri min_coverage_pct
33+
declare -r configuration
34+
declare -r define
3135

3236
renamed_results_dir="$ARTIFACTS_DIR-$(date -u +"%Y%m%dT%H%M%S")"
3337
declare -r renamed_results_dir
@@ -83,6 +87,7 @@ execute mkdir -p "$coverage_summary_dir"
8387

8488
trace "Running tests in project '$test_project' with configuration '$configuration'..."
8589
execute dotnet test "$test_project" \
90+
/p:DefineConstants="$define" \
8691
--configuration "$configuration" -- \
8792
--results-directory "$test_results_results_dir" \
8893
--coverage \

0 commit comments

Comments
 (0)