From bea69918e03c63d19333f267f00f02916d5b67c9 Mon Sep 17 00:00:00 2001 From: Anton Wiklund Date: Thu, 18 Apr 2024 10:42:31 +0200 Subject: [PATCH 1/7] test: add openapi crlf mocks --- test/mocks/openapi-1.2.3-crlf.yaml | 12 ++++++++++++ test/mocks/openapi-1.3.0-crlf.yaml | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/mocks/openapi-1.2.3-crlf.yaml create mode 100644 test/mocks/openapi-1.3.0-crlf.yaml diff --git a/test/mocks/openapi-1.2.3-crlf.yaml b/test/mocks/openapi-1.2.3-crlf.yaml new file mode 100644 index 000000000..b5e7741ea --- /dev/null +++ b/test/mocks/openapi-1.2.3-crlf.yaml @@ -0,0 +1,12 @@ +openapi: "3.0.2" +info: + title: Mock API + description: >- + Description of Mock API + version: "1.2.3" + termsOfService: http://swagger.io/terms/ +externalDocs: + description: Find out more + url: https://example.com/foo/bar +servers: + - url: http://example.com diff --git a/test/mocks/openapi-1.3.0-crlf.yaml b/test/mocks/openapi-1.3.0-crlf.yaml new file mode 100644 index 000000000..74551f047 --- /dev/null +++ b/test/mocks/openapi-1.3.0-crlf.yaml @@ -0,0 +1,12 @@ +openapi: "3.0.2" +info: + title: Mock API + description: >- + Description of Mock API + version: "1.3.0" + termsOfService: http://swagger.io/terms/ +externalDocs: + description: Find out more + url: https://example.com/foo/bar +servers: + - url: http://example.com From 9d1b2e02c3dbff6c3d927d02428dd1acbcfc9147 Mon Sep 17 00:00:00 2001 From: Anton Wiklund Date: Thu, 18 Apr 2024 10:42:49 +0200 Subject: [PATCH 2/7] test: add openapi lf mocks --- test/mocks/openapi-1.2.3-lf.yaml | 12 ++++++++++++ test/mocks/openapi-1.3.0-lf.yaml | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/mocks/openapi-1.2.3-lf.yaml create mode 100644 test/mocks/openapi-1.3.0-lf.yaml diff --git a/test/mocks/openapi-1.2.3-lf.yaml b/test/mocks/openapi-1.2.3-lf.yaml new file mode 100644 index 000000000..19ac91bbe --- /dev/null +++ b/test/mocks/openapi-1.2.3-lf.yaml @@ -0,0 +1,12 @@ +openapi: "3.0.2" +info: + title: Mock API + description: >- + Description of Mock API + version: "1.2.3" + termsOfService: http://swagger.io/terms/ +externalDocs: + description: Find out more + url: https://example.com/foo/bar +servers: + - url: http://example.com diff --git a/test/mocks/openapi-1.3.0-lf.yaml b/test/mocks/openapi-1.3.0-lf.yaml new file mode 100644 index 000000000..21dbaeabd --- /dev/null +++ b/test/mocks/openapi-1.3.0-lf.yaml @@ -0,0 +1,12 @@ +openapi: "3.0.2" +info: + title: Mock API + description: >- + Description of Mock API + version: "1.3.0" + termsOfService: http://swagger.io/terms/ +externalDocs: + description: Find out more + url: https://example.com/foo/bar +servers: + - url: http://example.com From c4a813ade17e2391873028bd5ae70ca9a1fe4ae7 Mon Sep 17 00:00:00 2001 From: Anton Wiklund Date: Thu, 18 Apr 2024 10:44:21 +0200 Subject: [PATCH 3/7] feat: add support for openapi version bumping (almost identical to yaml-updater) --- lib/updaters/index.js | 4 ++++ lib/updaters/types/openapi.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 lib/updaters/types/openapi.js diff --git a/lib/updaters/index.js b/lib/updaters/index.js index 29521d4af..683381f94 100644 --- a/lib/updaters/index.js +++ b/lib/updaters/index.js @@ -7,6 +7,7 @@ const updatersByType = { gradle: require('./types/gradle'), csproj: require('./types/csproj'), yaml: require('./types/yaml'), + openapi: require('./types/openapi'), }; const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']; @@ -37,6 +38,9 @@ function getUpdaterByFilename(filename) { if (/\.ya?ml$/.test(filename)) { return getUpdaterByType('yaml'); } + if (/openapi.yaml/.test(filename)) { + return getUpdaterByType('openapi'); + } throw Error( `Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`, ); diff --git a/lib/updaters/types/openapi.js b/lib/updaters/types/openapi.js new file mode 100644 index 000000000..981386be8 --- /dev/null +++ b/lib/updaters/types/openapi.js @@ -0,0 +1,15 @@ +const yaml = require('yaml'); +const detectNewline = require('detect-newline'); + +module.exports.readVersion = function (contents) { + return yaml.parse(contents).info.version; +}; + +module.exports.writeVersion = function (contents, version) { + const newline = detectNewline(contents); + const document = yaml.parseDocument(contents); + + document.get('info').set('version', version); + + return document.toString().replace(/\r?\n/g, newline); +}; From 71d1dc1bc9bd41fd2804fe3109c52211fb29a23f Mon Sep 17 00:00:00 2001 From: Anton Wiklund Date: Thu, 18 Apr 2024 10:47:50 +0200 Subject: [PATCH 4/7] test: OpenAPI updater tests --- test/core.spec.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/core.spec.js b/test/core.spec.js index b64cc9c3a..880220216 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -1180,6 +1180,74 @@ describe('cli', function () { }); }); + it('bumps version in OpenAPI `openapi.yaml` file with CRLF Line Endings', async function () { + const expected = fs.readFileSync( + './test/mocks/openapi-1.3.0-crlf.yaml', + 'utf-8', + ); + const filename = 'openapi.yaml'; + mock({ + bump: 'minor', + realTestFiles: [ + { + filename, + path: './test/mocks/openapi-1.2.3-crlf.yaml', + }, + ], + }); + await exec({ + packageFiles: [{ filename, type: 'openapi' }], + bumpFiles: [{ filename, type: 'openapi' }], + }); + + // filePath is the first arg passed to writeFileSync + const packageJsonWriteFileSynchCall = findWriteFileCallForPath({ + writeFileSyncSpy, + filename, + }); + + if (!packageJsonWriteFileSynchCall) { + throw new Error(`writeFileSynch not invoked with path ${filename}`); + } + + const calledWithContentStr = packageJsonWriteFileSynchCall[1]; + expect(calledWithContentStr).toEqual(expected); + }); + + it('bumps version in OpenAPI `openapi.yaml` file with LF Line Endings', async function () { + const expected = fs.readFileSync( + './test/mocks/openapi-1.3.0-lf.yaml', + 'utf-8', + ); + const filename = 'openapi.yaml'; + mock({ + bump: 'minor', + realTestFiles: [ + { + filename, + path: './test/mocks/openapi-1.2.3-lf.yaml', + }, + ], + }); + await exec({ + packageFiles: [{ filename, type: 'openapi' }], + bumpFiles: [{ filename, type: 'openapi' }], + }); + + // filePath is the first arg passed to writeFileSync + const packageJsonWriteFileSynchCall = findWriteFileCallForPath({ + writeFileSyncSpy, + filename, + }); + + if (!packageJsonWriteFileSynchCall) { + throw new Error(`writeFileSynch not invoked with path ${filename}`); + } + + const calledWithContentStr = packageJsonWriteFileSynchCall[1]; + expect(calledWithContentStr).toEqual(expected); + }); + it('bumps version in Maven `pom.xml` file with CRLF Line Endings', async function () { const expected = fs.readFileSync( './test/mocks/pom-6.4.0-crlf.xml', From 6d35d3706a29924a1c26eae28ca2604d86ce405d Mon Sep 17 00:00:00 2001 From: Markus Schulte Date: Fri, 19 Apr 2024 05:42:34 +0200 Subject: [PATCH 5/7] fix: Add debug messages for exclusions during bump lifecycle (#131) * chore: Add debug messages for exclusions in lifecycle bump Code has been modified to include debug messages in the bump lifecycle. When a filename is ignored by Git or is not a file, the program will now log a debug-level message. * chore(#131): Update formatting * chore(#131): Improve debug messages for exclusions during bump lifecycle --- lib/lifecycles/bump.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index ad5b2386b..d0c6fb0bc 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -222,10 +222,20 @@ function updateConfigs(args, newVersion) { } const configPath = path.resolve(process.cwd(), updater.filename); try { - if (dotgit.ignore(updater.filename)) return; + if (dotgit.ignore(updater.filename)) { + console.debug( + `Not updating file '${updater.filename}', as it is ignored in Git`, + ); + return; + } const stat = fs.lstatSync(configPath); - if (!stat.isFile()) return; + if (!stat.isFile()) { + console.debug( + `Not updating '${updater.filename}', as it is not a file`, + ); + return; + } const contents = fs.readFileSync(configPath, 'utf8'); const newContents = updater.updater.writeVersion(contents, newVersion); const realNewVersion = updater.updater.readVersion(newContents); From ae2ad958745817791a7f762ea492f8dfb06d60d2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:47:12 +1000 Subject: [PATCH 6/7] chore(master): release 12.3.0 (#139) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7365e3e90..4c0933ab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [12.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.2.0...v12.3.0) (2024-04-19) + + +### Features + +* **updater:** add YAML support ([#137](https://github.com/absolute-version/commit-and-tag-version/issues/137)) ([b9dccc2](https://github.com/absolute-version/commit-and-tag-version/commit/b9dccc23ec05e4026899c676f3275d4dedf8c686)) + + +### Bug Fixes + +* Add debug messages for exclusions during bump lifecycle ([#131](https://github.com/absolute-version/commit-and-tag-version/issues/131)) ([a9191f2](https://github.com/absolute-version/commit-and-tag-version/commit/a9191f293eb9302afb1093ad37e9fa076f6b37a2)) + ## [12.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.1.0...v12.2.0) (2024-01-15) diff --git a/package-lock.json b/package-lock.json index 8f388ad9f..addec99a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "commit-and-tag-version", - "version": "12.2.0", + "version": "12.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "commit-and-tag-version", - "version": "12.2.0", + "version": "12.3.0", "license": "ISC", "dependencies": { "chalk": "^2.4.2", diff --git a/package.json b/package.json index 93a253b25..cc734052e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commit-and-tag-version", - "version": "12.2.0", + "version": "12.3.0", "description": "replacement for `npm version` with automatic CHANGELOG generation", "bin": "bin/cli.js", "scripts": { From 1551aef1e43ebc0ad2eb77f451d06ecc7f93231a Mon Sep 17 00:00:00 2001 From: Anton Wiklund Date: Fri, 19 Apr 2024 11:24:44 +0200 Subject: [PATCH 7/7] docs: add documentation about how to bump OpenAPI version --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 4c21f4f55..dceec3b8f 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ _Having problems? Want to contribute? Join us on the [node-tooling community Sla - [Maven Support (Java/Kotlin)](#maven-support-javakotlin) - [Gradle Support (Java/Kotlin)](#gradle-support-javakotlin) - [.NET Support](#net-support) + - [OpenAPI Support](#openapi-support) - [Installing `commit-and-tag-version`](#installing-commit-and-tag-version) - [As a local `npm run` script](#as-a-local-npm-run-script) - [As global `bin`](#as-global-bin) @@ -117,6 +118,14 @@ This is going to read and update only the `version:` tag in the file. commit-and-tag-version --packageFiles file.yaml --bumpFiles file.yaml ``` +### OpenAPI Support + +If you are using OpenAPI, then just point to your `openapi.yaml` file. + +```sh +commit-and-tag-version --packageFiles openapi.yaml --bumpFiles openapi.yaml +``` + ## Installing `commit-and-tag-version` ### As a local `npm run` script