-
-
Notifications
You must be signed in to change notification settings - Fork 73
introduce QA pipeline for protobuf schemas #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e876a17
wip
jkowalleck 8b0d07e
wip
jkowalleck b67cb78
finished protobuf lint config
jkowalleck f9b68b0
docs
jkowalleck 38d75fb
docs
jkowalleck 87a3fab
docs
jkowalleck f34a21f
docs
jkowalleck fd036a2
CT
jkowalleck 17796aa
dependabot for docker
jkowalleck f733770
wip
jkowalleck 62f214e
wip
jkowalleck 9ad0ebe
wip
jkowalleck b57036c
wip
jkowalleck 13faf7d
wip
jkowalleck 975dfe1
wip
jkowalleck 6a7c6e0
wip
jkowalleck ba3fa7c
wip
jkowalleck 9117fea
wip
jkowalleck 7d2ffc3
wip
jkowalleck 441fd9e
wip
jkowalleck 7c15cf9
wip
jkowalleck 878162c
wip
jkowalleck 8dbfee7
tidy
jkowalleck 8db0967
wip
jkowalleck 405fd3e
wip
jkowalleck 2c04989
wip
jkowalleck a67922a
fix protobuf examples
jkowalleck 97abbe7
cleanup
jkowalleck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # docs: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions | ||
|
|
||
| name: CT ProtoBuf | ||
|
|
||
| on: | ||
| push: | ||
| branches: ['master', 'main'] | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: tools/src/test/proto | ||
|
|
||
| jobs: | ||
| test: | ||
| timeout-minutes: 30 | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| # see https://github.com/actions/checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Run test | ||
| run: ./test.sh | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # This is the config for "Buf" - a ProtocolBuffer linter/checker/more | ||
| # see https://buf.build/docs/configuration/v1/buf-yaml | ||
| version: v1 | ||
| breaking: # https://buf.build/docs/configuration/v1/buf-yaml#breaking | ||
| use: # see https://buf.build/docs/breaking/overview#rules-and-categories | ||
| - FILE | ||
| - WIRE_JSON |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This is the config for "Buf" - a ProtocolBuffer linter/checker/more | ||
| # see https://buf.build/docs/configuration/v1/buf-yaml | ||
| version: v1 | ||
| breaking: # https://buf.build/docs/configuration/v1/buf-yaml#breaking | ||
| use: # see https://buf.build/docs/breaking/overview#rules-and-categories | ||
| - FILE | ||
| - WIRE_JSON | ||
| except: | ||
| # scope is to detect changes from one version to the other -> so ignore "FILE_SAME_PACKAGE" | ||
| - FILE_SAME_PACKAGE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # This is the config for "Buf" - a ProtocolBuffer linter/checker/more | ||
| # see https://buf.build/docs/configuration/v1/buf-yaml | ||
| version: v1 | ||
| lint: # https://buf.build/docs/configuration/v1/buf-yaml#lint | ||
| use: # see https://buf.build/docs/lint/rules | ||
| - DEFAULT # https://buf.build/docs/lint/rules#default | ||
| except: | ||
| # directory/file layout does not match the recommendation/framework of the tool | ||
| - DIRECTORY_SAME_PACKAGE # https://buf.build/docs/lint/rules#directory_same_package | ||
| - PACKAGE_DIRECTORY_MATCH # https://buf.build/docs/lint/rules#package_lower_snake_case | ||
| - FILE_LOWER_SNAKE_CASE # https://buf.build/docs/lint/rules#file_lower_snake_case | ||
| # we do not stick to the following best-practices and recommendations: | ||
| # (shall be fixed with v2.0 of this very schema) | ||
| - PACKAGE_VERSION_SUFFIX # https://buf.build/docs/lint/rules#package_version_suffix | ||
| - FIELD_LOWER_SNAKE_CASE # https://buf.build/docs/lint/rules#field_lower_snake_case | ||
| ignore_only: | ||
| DEFAULT: # https://buf.build/docs/lint/rules#default | ||
| # legacy schema files may NOT stick to the rules -- this is acknowledged. | ||
| - "schema/bom-1.5.proto" | ||
| - "schema/bom-1.4.proto" | ||
| - "schema/bom-1.3.proto" | ||
| allow_comment_ignores: true # the so-called "baseline" is done by annotating exceptions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| #!/usr/bin/env bash | ||
| set -ue | ||
|
|
||
| THIS_PATH="$(realpath "$(dirname "$0")")" | ||
| ROOT_PATH="$(realpath "${THIS_PATH}/../../../..")" | ||
|
|
||
| # paths relative to $ROOT_PATH | ||
| SCHEMA_DIR='schema' | ||
| TEST_RES_DIR='tools/src/test/resources' | ||
|
|
||
| REMOTE="https://github.com/${GITHUB_REPOSITORY:-CycloneDX/specification}.git" | ||
|
|
||
|
|
||
| ## ---- | ||
|
|
||
|
|
||
| function schema-lint () { | ||
| echo '> lint schema files' >&2 | ||
|
|
||
| if [[ -n "${CI:-}" ]] | ||
| 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" \ | ||
| --workdir '/workspace' \ | ||
| bufbuild/buf:1.29.0 \ | ||
| lint --path "$SCHEMA_DIR" \ | ||
| --config 'buf.yaml' \ | ||
| --error-format "$LOG_FORMAT" | ||
|
|
||
| echo '>> OK.' >&2 | ||
| } | ||
|
|
||
|
|
||
| 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" | ||
| SCHEMA_DIR_OLD="${SCHEMA_DIR}_old" | ||
|
|
||
| echo ">> compare new:${NEW} -VS- old:${OLD}" >&2 | ||
| # stick with the original path of "$NEW", so the reporting makes sense... | ||
| docker run --rm \ | ||
| --volume "${ROOT_PATH}/${SCHEMA_DIR}/${NEW}:/workspace/${SCHEMA_DIR}/${NEW}:ro" \ | ||
| --volume "${ROOT_PATH}/${SCHEMA_DIR}/${OLD}:/workspace/${SCHEMA_DIR_OLD}/${NEW}:ro" \ | ||
| --volume "${THIS_PATH}/buf_breaking-version.yaml:/workspace/buf.yaml:ro" \ | ||
| --workdir '/workspace' \ | ||
| bufbuild/buf:1.29.0 \ | ||
| breaking "$SCHEMA_DIR" \ | ||
| --against "$SCHEMA_DIR_OLD" \ | ||
| --config 'buf.yaml' \ | ||
| --error-format "$LOG_FORMAT" | ||
| } | ||
|
|
||
| compare '1.6' '1.5' | ||
| echo '>> skip compare' '1.5' '1.4' >&2 # <-- had breaking changes, which is acknowledged | ||
| compare '1.4' '1.3' | ||
|
|
||
| echo '>> OK.' >&2 | ||
| } | ||
|
|
||
| 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" \ | ||
| --workdir '/workspace' \ | ||
| bufbuild/buf:1.29.0 \ | ||
| breaking "$SCHEMA_DIR" \ | ||
| --against "${REMOTE}#subdir=${SCHEMA_DIR}" \ | ||
| --config 'buf.yaml' \ | ||
| --error-format "$LOG_FORMAT" | ||
|
|
||
| echo '>> OK.' >&2 | ||
| } | ||
|
|
||
| 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" | ||
|
|
||
| echo ">> validate $(realpath --relative-to="$PWD" "$FILE") as ${MESSAGE} of ${SCHEMA_FILE}" >&2 | ||
|
|
||
| docker run --rm \ | ||
| --volume "${ROOT_PATH}/${SCHEMA_DIR}:/workspace/${SCHEMA_DIR}:ro" \ | ||
| --volume "${FILE}:/workspace/test_res:ro" \ | ||
| --workdir '/workspace' \ | ||
| bufbuild/buf:1.29.0 \ | ||
| convert "${SCHEMA_DIR}/${SCHEMA_FILE}" \ | ||
| --type "$MESSAGE" \ | ||
| --from 'test_res#format=txtpb' \ | ||
| --to /dev/null | ||
| } | ||
|
|
||
| shopt -s globstar | ||
| for test_res in "$ROOT_PATH"/"$TEST_RES_DIR"/*/valid-*.textproto | ||
| do | ||
| SCHEMA_VERS="$(basename "$(dirname "$test_res")")" | ||
| validate "$test_res" "$SCHEMA_VERS" | ||
| done | ||
|
|
||
| echo '>> OK.' >&2 | ||
| } | ||
|
|
||
|
|
||
| ## ---- | ||
|
|
||
|
|
||
| case "${1:-all}" in | ||
| 'schema-lint') | ||
| schema-lint | ||
| ;; | ||
| 'schema-breaking-version') | ||
| schema-breaking-version | ||
| ;; | ||
| 'schema-breaking-remote') | ||
| schema-breaking-remote | ||
| ;; | ||
| 'schema-breaking') | ||
| schema-breaking-version | ||
| schema-breaking-remote | ||
| ;; | ||
| 'schema-functional') | ||
| schema-functional | ||
| ;; | ||
| 'all') | ||
| # all the above | ||
| schema-lint | ||
| schema-breaking-version | ||
| schema-breaking-remote | ||
| schema-functional | ||
| ;; | ||
| *) | ||
| echo 'unexpected argument. known arguments:' \ | ||
| 'schema-lint,schema-breaking-version,schema-breaking-remote,schema-breaking,schema-functional,all' \ | ||
| >&2 | ||
| exit 1 | ||
| ;; | ||
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.