Skip to content
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

chore(tools): script to bump openapi spec dependency versions #2340

Merged

Conversation

aldousalvarez
Copy link
Contributor

@aldousalvarez aldousalvarez commented Mar 24, 2023

  1. Adds a new script that can be executed in order to bump all release
    versions of the open API specs. These are one of two main categories:
    1.1. The top level .info.version property of the OpenAPI spec JSON object
    1.2. Any schema component references embedded anywhere deep inside the
    JSON object that we define our specs as, for example when a connector
    plugin's endpoint returns a response object whose schema is defined in
    another package's OpenAPI spec file such as the core-api package's.
  2. Fixed a bug in the "prettier" npm script which was pointing to a non-
    existent configuration file. This was necessary to be fixed in this commit
    because tests had to be carried out whether the auto-formatting applied
    by the version bumping script is consistent with the auto-formatting that
    is applied when we run prettier via the CLI (there was some struggle here
    to figure out that we have to pre-format the JSON string held in-memory
    via JSON.stringify() first otherwise the formatted version would diverge
    from what the CLI does to the .json files on-disk)
  3. We had to exclude the tag called v2.0.0-alpha-prerelease because it
    was incorrectly named unfortunately: it is considered newer than
    v2.0.0-alpha.1 by the semver-parser package but it is actually older,
    e.g. we've issued v2.0.0-alpha-prerelease before we issued v2.0.0-alpha.1
    (which is our mistake and this is the workaround to rectify that after
    the fact without having to force delete the tag that we've already
    pushed to the upstream main branch).
    This exclusion is applied by default which might turn out to be a mistake
    later but right now it does not look like there would be an edge case
    where we need to handle this in any different way.
  4. The script is re-entrant and will save a thorough report of what it did
    to temporary .json files whose names are date and timestamped within the
    project root's ./build/ subfolder.
  5. The target version to bump to can be specified explicitly via the
    --target-version CLI parameter but if it not provided then will default
    to whatever is the latest sem-ver compatibly named tag in the git log.

Example to specify target version explicitly:
yarn tools:bump-openapi-spec-dep-versions --target-version=v3.2.1

Example to let the script figure out what the target version should be:
yarn tools:bump-openapi-spec-dep-versions

Fixes https://github.com/hyperledger/cacti/issues/2206

Co-authored-by: Peter Somogyvari peter.somogyvari@accenture.com

Signed-off-by: aldousalvarez aldousss.alvarez@gmail.com
Signed-off-by: Peter Somogyvari peter.somogyvari@accenture.com

Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldousalvarez Mostly LGTM but I have a few nits as usual. Please see the comments above for the details!

tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
tools/custom-checks/bump-openapi-spec-dep-version.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldousalvarez FYI: I've pushed some changes that were easier to make then explain. Please make the following changes on top of what I had just pushed:

  1. There are still nested functions, that point was never addressed.
  2. Don't use regular expression search & replace to perform the version bumps. The files need to be parsed and then the versions need to be updated based on the parsed data not via regex so that the replacements are deterministic and immune to bugs that will later stem from the content of the files changing in a way that will break the regex.

@aldousalvarez
Copy link
Contributor Author

@petermetz Thank you for the update, I have now addressed the changes that you have requested and I already fixed the nested functions and also I have implemented prettier as the one that will format the JSONs.

1. Adds a new script that can be executed in order to bump all release
versions of the open API specs. These are one of two main categories:
1.1. The top level .info.version property of the OpenAPI spec JSON object
1.2. Any schema component references embedded anywhere deep inside the
JSON object that we define our specs as, for example when a connector
plugin's endpoint returns a response object whose schema is defined in
another package's OpenAPI spec file such as the core-api package's.
2. Fixed a bug in the "prettier" npm script which was pointing to a non-
existent configuration file. This was necessary to be fixed in this commit
because tests had to be carried out whether the auto-formatting applied
by the version bumping script is consistent with the auto-formatting that
is applied when we run prettier via the CLI (there was some struggle here
to figure out that we have to pre-format the JSON string held in-memory
via JSON.stringify() first otherwise the formatted version would diverge
from what the CLI does to the .json files on-disk)
3. We had to exclude the tag called v2.0.0-alpha-prerelease because it
was incorrectly named unfortunately: it is considered newer than
v2.0.0-alpha.1 by the semver-parser package but it is actually older,
e.g. we've issued v2.0.0-alpha-prerelease before we issued v2.0.0-alpha.1
(which is our mistake and this is the workaround to rectify that after
the fact without having to force delete the tag that we've already
pushed to the upstream main branch).
This exclusion is applied by default which might turn out to be a mistake
later but right now it does not look like there would be an edge case
where we need to handle this in any different way.
4. The script is re-entrant and will save a thorough report of what it did
to temporary .json files whose names are date and timestamped within the
project root's ./build/ subfolder.
5. The target version to bump to can be specified explicitly via the
--target-version CLI parameter but if it not provided then will default
to whatever is the latest sem-ver compatibly named tag in the git log.

Example to specify target version explicitly:
`yarn tools:bump-openapi-spec-dep-versions --target-version=v3.2.1`

Example to let the script figure out what the target version should be:
`yarn tools:bump-openapi-spec-dep-versions`

Fixes hyperledger-cacti#2206

Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com>

Signed-off-by: aldousalvarez <aldousss.alvarez@gmail.com>
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@petermetz petermetz merged commit 15ab85f into hyperledger-cacti:main Jul 12, 2023
@petermetz petermetz deleted the aldousalvarez/issue2206 branch July 12, 2023 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore(tools): script to bump openapi spec dependency versions
3 participants