Skip to content

Commit 59e5441

Browse files
committed
versionCompare
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 90da24a commit 59e5441

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

tools/src/test/proto/test.sh

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ REMOTE="https://github.com/${GITHUB_REPOSITORY:-CycloneDX/specification}.git"
1313
BUF_IMAGE_VERSION='1.50.0'
1414
BUF_IMAGE="bufbuild/buf:$BUF_IMAGE_VERSION"
1515

16+
LOG_FORMAT='text' # set to 'json' to see details
17+
if [[ -n "${GITHUB_WORKFLOW:-}" ]]
18+
then
19+
LOG_FORMAT='github-actions'
20+
fi
21+
22+
1623
## ----
1724

1825

@@ -24,20 +31,13 @@ function prepare () {
2431
function schema-lint () {
2532
echo '> lint schema files' >&2
2633

27-
if [[ -n "${GITHUB_WORKFLOW:-}" ]]
28-
then
29-
LOG_FORMAT='github-actions'
30-
else
31-
LOG_FORMAT='text'
32-
fi
33-
3434
docker run --rm \
3535
--volume "${ROOT_PATH}/${SCHEMA_DIR}:/workspace/${SCHEMA_DIR}:ro" \
3636
--volume "${THIS_PATH}/buf_lint.yaml:/workspace/buf.yaml:ro" \
3737
--workdir '/workspace' \
3838
"$BUF_IMAGE" \
3939
lint --path "$SCHEMA_DIR" \
40-
--error-format "$LOG_FORMAT"
40+
--error-format "${LOG_FORMAT:-$LOG_FORMAT_DEFAULT}"
4141

4242
echo '>> OK.' >&2
4343
}
@@ -46,19 +46,12 @@ function schema-lint () {
4646
function schema-breaking-version () {
4747
echo '> test schema for breaking changes against previous version' >&2
4848

49-
if [[ -n "${GITHUB_WORKFLOW:-}" ]]
50-
then
51-
LOG_FORMAT='github-actions'
52-
else
53-
LOG_FORMAT='json'
54-
fi
55-
5649
function compare() {
57-
NEW="bom-${1}.proto"
58-
OLD="bom-${2}.proto"
50+
local NEW="bom-${1}.proto"
51+
local OLD="bom-${2}.proto"
5952

60-
NEW_NP="$(mktemp)"
61-
OLD_NP="$(mktemp)"
53+
local NEW_NP="$(mktemp)"
54+
local OLD_NP="$(mktemp)"
6255

6356
# remove package identifier -> so that the comparisson works as expected
6457
sed 's/^package .*//' "${ROOT_PATH}/${SCHEMA_DIR}/${NEW}" > "$NEW_NP"
@@ -87,13 +80,6 @@ function schema-breaking-version () {
8780
function schema-breaking-remote () {
8881
echo '> test schema for breaking changes against remote' >&2
8982

90-
if [[ -n "${GITHUB_WORKFLOW:-}" ]]
91-
then
92-
LOG_FORMAT='github-actions'
93-
else
94-
LOG_FORMAT='text'
95-
fi
96-
9783
docker run --rm \
9884
--volume "${ROOT_PATH}/${SCHEMA_DIR}:/workspace/${SCHEMA_DIR}:ro" \
9985
--volume "${THIS_PATH}/buf_breaking-remote.yaml:/workspace/buf.yaml:ro" \
@@ -110,10 +96,10 @@ function schema-functional () {
11096
echo '> test all examples against the respective schema' >&2
11197

11298
function validate() {
113-
FILE="$1"
114-
SCHEMA_VERS="$2"
115-
SCHEMA_FILE="bom-${SCHEMA_VERS}.proto"
116-
MESSAGE="cyclonedx.v${SCHEMA_VERS/./_}.Bom"
99+
local FILE="$1"
100+
local SCHEMA_VERS="$2"
101+
local SCHEMA_FILE="bom-${SCHEMA_VERS}.proto"
102+
local MESSAGE="cyclonedx.v${SCHEMA_VERS/./_}.Bom"
117103

118104
echo ">> validate $(realpath --relative-to="$PWD" "$FILE") as ${MESSAGE} of ${SCHEMA_FILE}" >&2
119105

@@ -133,7 +119,7 @@ function schema-functional () {
133119
shopt -s globstar
134120
for test_res in "$ROOT_PATH"/"$TEST_RES_DIR"/*/valid-*.textproto
135121
do
136-
SCHEMA_VERS="$(basename "$(dirname "$test_res")")"
122+
local SCHEMA_VERS="$(basename "$(dirname "$test_res")")"
137123
validate "$test_res" "$SCHEMA_VERS"
138124
done
139125

0 commit comments

Comments
 (0)