From 5b22fd51da54f90a7ca29bfa4e429c2822e46843 Mon Sep 17 00:00:00 2001 From: Subramanian Neelakantan Date: Thu, 25 Apr 2024 09:15:57 +0000 Subject: [PATCH] [BACKPORT 2024.1][PLAT-13690] Fix openapi bundle failure due to redocly dependency on openapi-sampler Summary: Original commit: 1333618f97454ec8f29719133df247cca77041a2 / D34498 https://yugabyte.slack.com/archives/C048Z7EDH0F/p1713971854833549 Backporting as the same issue is seen 2024.1 builds too https://jenkins.dev.yugabyte.com/job/github-yugabyte-db-alma8-master-clang17-release/512 The jenkins builds started failing with an error: ``` [2024-04-24T14:52:24.048Z] /share/jenkins/workspace/github-yugabyte-db-alma8-master-clang17-release/yugabyte-db/managed/src/main/resources/openapi /share/jenkins/workspace/github-yugabyte-db-alma8-master-clang17-release/yugabyte-db/managed/scripts [2024-04-24T14:52:24.048Z] Running bundle on openapi spec ... [2024-04-24T14:52:24.048Z] npx: installed 197 in 12.668s [2024-04-24T14:52:24.048Z] Unexpected token '?' [2024-04-24T14:52:24.048Z] cp: cannot stat 'tmp/openapi_bundle.yaml': No such file or directory ``` Could reproduce locally after switching to `nvm use v12.22.12`: ``` [sneelakantan@dev-server-sneelakantan ~]$ redocly /nfusr/dev-server/sneelakantan/.nvm/versions/node/v12.22.12/lib/node_modules/openapi-sampler/dist/openapi-sampler.js:791 pattern = ((_pattern$match = pattern.match(/\/(.+?)\//)) === null || _pattern$match === void 0 ? void 0 : _pattern$match[1]) ?? ''; // Remove frontslash from front and back of RegExp ^ SyntaxError: Unexpected token '?' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at /nfusr/dev-server/sneelakantan/.nvm/versions/node/v12.22.12/lib/node_modules/@redocly/cli/node_modules/redoc/bundles/redoc.lib.js:41:72746 at /nfusr/dev-server/sneelakantan/.nvm/versions/node/v12.22.12/lib/node_modules/@redocly/cli/node_modules/redoc/bundles/redoc.lib.js:1807:3444 at /nfusr/dev-server/sneelakantan/.nvm/versions/node/v12.22.12/lib/node_modules/@redocly/cli/node_modules/redoc/bundles/redoc.lib.js:1807:3449 ``` Figured out a recent change in openapi-sampler@1.5.0 (dependency of redocly/cli) that is causing above error (https://github.com/Redocly/openapi-sampler/pull/153). So forcing to use the older version of openapi-sampler@1.4.0 here to workaround this build error. Test Plan: Ran build locally. Will monitor jenkins phab pipeline. Reviewers: skurapati, rmadhavan, steve.varnau, dshubin, vkumar Reviewed By: skurapati, vkumar Subscribers: yugaware, dshubin Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D34524 --- managed/scripts/openapi_bundle.sh | 7 +++++-- managed/scripts/openapi_lint.sh | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/managed/scripts/openapi_bundle.sh b/managed/scripts/openapi_bundle.sh index f9c3a28074c3..f4fc6f4c5092 100755 --- a/managed/scripts/openapi_bundle.sh +++ b/managed/scripts/openapi_bundle.sh @@ -20,8 +20,11 @@ echo "Running bundle on openapi spec ..." tmp_out_file=tmp/openapi_bundle.yaml rm -f $tmp_out_file # using redocly version 1.0.2 since 1.1.0 onwards requires node version >=14.19.0 -# but jenkins runs node v12.22.12 -$NPM_BIN/npx @redocly/cli@1.0.2 bundle openapi_split.yaml --output $tmp_out_file +# but jenkins runs node v12.22.12. +# Faced an issue with a newly released openapi-sampler@1.5.0 on node v12.22.12. +# So picking the older version openapi-sampler@1.4.0 explicitly. +$NPM_BIN/npx -p openapi-sampler@1.4.0 -p @redocly/cli@1.0.2 \ + redocly bundle openapi_split.yaml --output $tmp_out_file cmp -s $tmp_out_file ../openapi.yaml if [ $? -ne 0 ]; then cp $tmp_out_file ../openapi.yaml diff --git a/managed/scripts/openapi_lint.sh b/managed/scripts/openapi_lint.sh index 50abeeb51518..3dde091d8673 100755 --- a/managed/scripts/openapi_lint.sh +++ b/managed/scripts/openapi_lint.sh @@ -10,8 +10,10 @@ for file in $OPENAPI_PATH $OPENAPI_PUBLIC_PATH do echo "Running lint on openapi spec: ${file}" # using redocly version 1.0.2 since 1.1.0 onwards requires node version >=14.19.0 - # but jenkins runs node v12.22.12 - $NPM_BIN/npx @redocly/cli@1.0.2 lint \ + # but jenkins runs node v12.22.12. + # Faced an issue with a newly released openapi-sampler@1.5.0 on node v12.22.12. + # So picking the older version openapi-sampler@1.4.0 explicitly. + $NPM_BIN/npx -p openapi-sampler@1.4.0 -p @redocly/cli@1.0.2 redocly lint \ --format=stylish --config=../src/main/resources/openapi_lint.yaml ${file} if [ $? -ne 0 ]; then