Skip to content

Commit

Permalink
chore: test protobuf acknowledged BC (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowalleck authored Feb 6, 2025
2 parents 5006037 + f99dd79 commit 5868a43
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
11 changes: 10 additions & 1 deletion tools/src/test/proto/buf_breaking-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
version: v2
breaking: # https://buf.build/docs/configuration/v2/buf-yaml#breaking
use: # see https://buf.build/docs/breaking/overview#rules-and-categories
- WIRE
- WIRE
ignore_only:
# possible breaks are acknowledged for this specific findings only
FIELD_WIRE_COMPATIBLE_CARDINALITY:
# DO NOT ADD NEW VERSIONS HERE WITHOUT CONSULTING THE CDX CORE-WORKING-GROUP
- 'schema/bom-1.6.proto'
- 'schema/bom-1.5.proto'
FIELD_WIRE_COMPATIBLE_TYPE:
# DO NOT ADD NEW VERSIONS HERE WITHOUT CONSULTING THE CDX CORE-WORKING-GROUP
- 'schema/bom-1.5.proto'
46 changes: 17 additions & 29 deletions tools/src/test/proto/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ REMOTE="https://github.com/${GITHUB_REPOSITORY:-CycloneDX/specification}.git"
BUF_IMAGE_VERSION='1.50.0'
BUF_IMAGE="bufbuild/buf:$BUF_IMAGE_VERSION"

LOG_FORMAT='text' # set to 'json' to see details
if [[ -n "${GITHUB_WORKFLOW:-}" ]]
then
LOG_FORMAT='github-actions'
fi


## ----


Expand All @@ -24,13 +31,6 @@ function prepare () {
function schema-lint () {
echo '> lint schema files' >&2

if [[ -n "${GITHUB_WORKFLOW:-}" ]]
then
LOG_FORMAT='github-actions'
else
LOG_FORMAT='text'
fi

docker run --rm \
--volume "${ROOT_PATH}/${SCHEMA_DIR}:/workspace/${SCHEMA_DIR}:ro" \
--volume "${THIS_PATH}/buf_lint.yaml:/workspace/buf.yaml:ro" \
Expand All @@ -46,17 +46,11 @@ function schema-lint () {
function schema-breaking-version () {
echo '> test schema for breaking changes against previous version' >&2

if [[ -n "${GITHUB_WORKFLOW:-}" ]]
then
LOG_FORMAT='github-actions'
else
LOG_FORMAT='text'
fi

function compare() {
NEW="bom-${1}.proto"
OLD="bom-${2}.proto"
local NEW="bom-${1}.proto"
local OLD="bom-${2}.proto"

local NEW_NP OLD_NP
NEW_NP="$(mktemp)"
OLD_NP="$(mktemp)"

Expand All @@ -77,8 +71,8 @@ function schema-breaking-version () {
--error-format "$LOG_FORMAT"
}

# compare '1.6' '1.5' # <-- possible breaks are acknowledged
# compare '1.5' '1.4' # <-- possible breaks are acknowledged
compare '1.6' '1.5' || echo "possible breaks are acknowledged for this specific version only"
compare '1.5' '1.4' || echo "possible breaks are acknowledged for this specific version only"
compare '1.4' '1.3'

echo '>> OK.' >&2
Expand All @@ -87,13 +81,6 @@ function schema-breaking-version () {
function schema-breaking-remote () {
echo '> test schema for breaking changes against remote' >&2

if [[ -n "${GITHUB_WORKFLOW:-}" ]]
then
LOG_FORMAT='github-actions'
else
LOG_FORMAT='text'
fi

docker run --rm \
--volume "${ROOT_PATH}/${SCHEMA_DIR}:/workspace/${SCHEMA_DIR}:ro" \
--volume "${THIS_PATH}/buf_breaking-remote.yaml:/workspace/buf.yaml:ro" \
Expand All @@ -110,10 +97,10 @@ function schema-functional () {
echo '> test all examples against the respective schema' >&2

function validate() {
FILE="$1"
SCHEMA_VERS="$2"
SCHEMA_FILE="bom-${SCHEMA_VERS}.proto"
MESSAGE="cyclonedx.v${SCHEMA_VERS/./_}.Bom"
local FILE="$1"
local SCHEMA_VERS="$2"
local SCHEMA_FILE="bom-${SCHEMA_VERS}.proto"
local MESSAGE="cyclonedx.v${SCHEMA_VERS/./_}.Bom"

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

Expand All @@ -130,6 +117,7 @@ function schema-functional () {
--to /dev/null
}

local SCHEMA_VERS
shopt -s globstar
for test_res in "$ROOT_PATH"/"$TEST_RES_DIR"/*/valid-*.textproto
do
Expand Down

0 comments on commit 5868a43

Please sign in to comment.