|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Recursively checks if all openapi specs within a local osparc-simcore revision are backwards compatible with a remote base |
4 | | -# Example: bash osparc-simcore/ci/github/helpers/openapi-specs-backwards-compatibility.bash \ |
5 | | -# https://raw.githubusercontent.com/ITISFoundation/osparc-simcore/refs/heads/master |
6 | | -# ./osparc-simcore/ |
| 3 | +# Recursively checks if all openapi specs within a local osparc-simcore revision are different/backwards compatible with a remote base |
| 4 | +# Example: |
| 5 | +# bash osparc-simcore/ci/github/helpers/openapi-specs-backwards-compatibility.bash diff \ |
| 6 | +# https://raw.githubusercontent.com/ITISFoundation/osparc-simcore/refs/heads/master \ |
| 7 | +# ./osparc-simcore/ |
| 8 | +# or |
| 9 | +# bash osparc-simcore/ci/github/helpers/openapi-specs-backwards-compatibility.bash breaking \ |
| 10 | +# https://raw.githubusercontent.com/ITISFoundation/osparc-simcore/refs/heads/master \ |
| 11 | +# ./osparc-simcore/ |
| 12 | +# |
| 13 | +# The script generates github error annotations for better being able to locate issues. |
7 | 14 |
|
8 | | -base_remote=$1 |
9 | | -revision_local=$2 |
| 15 | +operation=$1 |
| 16 | +base_remote=$2 |
| 17 | +revision_local=$3 |
10 | 18 |
|
11 | 19 | repo_base_dir=$(realpath "$(dirname "${BASH_SOURCE[0]}")/../../..") |
12 | 20 | openapi_specs=$(find "${revision_local}" -type f \( -name 'openapi.json' -o -name 'openapi.yaml' \) -not -path '*/.*' -exec realpath --relative-to="${revision_local}" {} \;) |
13 | 21 |
|
14 | 22 | cd "${revision_local}" || exit 1 # required to mount correct dir for diff tool |
15 | 23 |
|
16 | | -exit_status=0 |
17 | | -for spec in ${openapi_specs}; do |
18 | | - echo "Comparing ${spec}" |
19 | | - if ! "${repo_base_dir}/scripts/openapi-diff.bash" breaking --fail-on ERR "${base_remote}/${spec}" "/specs/${spec}"; then |
20 | | - echo "::error file=${spec}::${spec} is not backwards compatible with ${base_remote}/${spec}" |
21 | | - exit_status=$(("${exit_status}" + "1")) |
22 | | - fi |
23 | | - printf "%0.s=" {1..100} && printf "\n" |
24 | | -done |
25 | | - |
26 | | -exit "${exit_status}" |
| 24 | + |
| 25 | +function run_diff_tool() { |
| 26 | + exit_status=0 |
| 27 | + for spec in ${openapi_specs}; do |
| 28 | + echo "Comparing ${spec}" |
| 29 | + if ! "${repo_base_dir}/scripts/openapi-diff.bash" "$@" "${base_remote}/${spec}" "/specs/${spec}"; then |
| 30 | + echo "::error file=${spec}:: Error when checking ${spec}" |
| 31 | + exit_status=$(("${exit_status}" + "1")) |
| 32 | + fi |
| 33 | + printf "%0.s=" {1..100} && printf "\n" |
| 34 | + done |
| 35 | + |
| 36 | + exit "${exit_status}" |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +if [[ "${operation}" == "diff" ]]; then |
| 41 | + run_diff_tool "diff" "--fail-on-diff" |
| 42 | +elif [[ "${operation}" == "breaking" ]]; then |
| 43 | + run_diff_tool "breaking" "--fail-on" "ERR" |
| 44 | +else |
| 45 | + echo "the operation '${operation}' is not supported" |
| 46 | + exit 1 |
| 47 | +fi |
0 commit comments