From 4433775e87054bf82a7bb307c66035d17900f751 Mon Sep 17 00:00:00 2001 From: Divyendu Singh Date: Mon, 4 May 2020 13:45:46 +0530 Subject: [PATCH] feat(versioning-scheme): derive extension version from prisma version Fixes https://github.com/prisma/vscode/issues/121 --- package-lock.json | 53 +++++++++++ package.json | 10 +- scripts/check-update.sh | 5 +- scripts/extension-version.js | 56 +++++++++++ scripts/extension-version.test.js | 149 ++++++++++++++++++++++++++++++ 5 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 scripts/extension-version.js create mode 100644 scripts/extension-version.test.js diff --git a/package-lock.json b/package-lock.json index fbd05fe6d5..5000342572 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,6 +56,12 @@ "sprintf-js": "~1.0.2" } }, + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, "azure-devops-node-api": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/azure-devops-node-api/-/azure-devops-node-api-7.2.0.tgz", @@ -123,6 +129,20 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true }, + "chai": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", + "dev": true, + "requires": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.1.0", + "type-detect": "^4.0.5" + } + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -134,6 +154,12 @@ "supports-color": "^5.3.0" } }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true + }, "cheerio": { "version": "1.0.0-rc.3", "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.3.tgz", @@ -263,6 +289,15 @@ "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", "dev": true }, + "deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, + "requires": { + "type-detect": "^4.0.0" + } + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -434,6 +469,12 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -940,6 +981,12 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true + }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -1126,6 +1173,12 @@ "integrity": "sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=", "dev": true }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true + }, "typed-rest-client": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.2.0.tgz", diff --git a/package.json b/package.json index 5275f7f918..9153b0fb59 100644 --- a/package.json +++ b/package.json @@ -71,17 +71,19 @@ "vsce:publish": "sh scripts/publish.sh", "vsce:check": "yarn shell:lint && sh scripts/check-update.sh", "shell:lint": "shellcheck -x scripts/*.sh", - "test": "sh ./scripts/e2e.sh" + "test": "sh ./scripts/e2e.sh", + "test-scripts": "mocha scripts/extension-version.test.js" }, "activationEvents": [ "onLanguage:prisma" ], "devDependencies": { + "@types/mocha": "5.2.7", "@types/node": "12.12.0", + "chai": "4.2.0", + "mocha": "7.1.1", "semver": "7.3.2", "typescript": "3.8.3", - "vsce": "1.75.0", - "@types/mocha": "5.2.7", - "mocha": "7.1.1" + "vsce": "1.75.0" } } diff --git a/scripts/check-update.sh b/scripts/check-update.sh index 4fd91b439b..8c2f801089 100644 --- a/scripts/check-update.sh +++ b/scripts/check-update.sh @@ -24,7 +24,10 @@ echo "CURRENT_VERSION: $CURRENT_VERSION" NPM_VERSION=$(sh scripts/prisma-version.sh "$CHANNEL") echo "NPM_VERSION: $NPM_VERSION" -NEXT_EXTENSION_VERSION=$(sh scripts/extension-version.sh "$CHANNEL" "patch") +EXTENSION_VERSION=$(sh scripts/extension-version.sh "$CHANNEL" "") +echo "EXTENSION_VERSION: $EXTENSION_VERSION" + +NEXT_EXTENSION_VERSION=$(node scripts/extension-version.js "$NPM_VERSION" "$EXTENSION_VERSION") echo "NEXT_EXTENSION_VERSION: $NEXT_EXTENSION_VERSION" # Setup the repo with GH_TOKEN to avoid running jobs when CI commits diff --git a/scripts/extension-version.js b/scripts/extension-version.js new file mode 100644 index 0000000000..bbc7c7572b --- /dev/null +++ b/scripts/extension-version.js @@ -0,0 +1,56 @@ +function nextExtensionVersion({ prismaVersion, extensionVersion }) { + const derivedExtensionVersion = getDerivedExtensionVersion( + stripPreReleaseText(prismaVersion), + ) //? + + const derivedExistingExtensionVersion = getDerivedExtensionVersion( + extensionVersion, + ) //? + + if (derivedExtensionVersion === derivedExistingExtensionVersion) { + // Extension only publish + return bumpExtensionOnlyVersion(derivedExtensionVersion) + } + return derivedExtensionVersion +} + +function stripPreReleaseText(version) { + return version.replace('-alpha', '').replace('-beta', '').replace('-dev', '') +} + +function getDerivedExtensionVersion(version) { + const tokens = version.split('.') + if (tokens.length === 4) { + return tokens.slice(1).join('.') + } + if (tokens.length === 3) { + return version + } + throw new Error( + `Version ${version} must have 3 or 4 tokens separated by "." character`, + ) +} + +function bumpExtensionOnlyVersion(version) { + const tokens = version.split('.') + if (tokens.length === 3) { + return tokens.join('.') + '.1' + } + if (tokens.length === 4) { + return tokens.slice(0, 3).join('.') + (parseInt(tokens[4]) + 1) + } + throw new Error( + `Version ${version} must have 3 or 4 tokens separated by "." character`, + ) +} + +module.exports = { nextExtensionVersion } + +if (require.main === module) { + const args = process.argv.slice(2) + const version = nextExtensionVersion({ + prismaVersion: args[0], + extensionVersion: args[1], + }) + console.log(version) +} diff --git a/scripts/extension-version.test.js b/scripts/extension-version.test.js new file mode 100644 index 0000000000..7fe76dd402 --- /dev/null +++ b/scripts/extension-version.test.js @@ -0,0 +1,149 @@ +const { expect } = require('chai') + +const { nextExtensionVersion } = require('./extension-version') + +describe('next extension version', () => { + it('it should work with stable channel and current version to new version schema', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-beta.3', + extensionVersion: '0.0.35', + }), + ).to.eq('0.0.3') + }) + + it('it should work with stable channel and extension only push', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-beta.3', + extensionVersion: '0.0.3', + }), + ).to.eq('0.0.3.1') + }) + + it('it should work with stable channel and new prisma version', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-beta.4', + extensionVersion: '0.0.3', + }), + ).to.eq('0.0.4') + }) + + it('it should work with stable channel and new prisma version after an extension only publish', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-beta.4', + extensionVersion: '0.0.3.1', + }), + ).to.eq('0.0.4') + }) + + it('it should work with unstable channel and current version to new version schema', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-alpha.1149', + extensionVersion: '0.0.38', + }), + ).to.eq('0.0.1149') + }) + + it('it should work with unstable channel and extension only push', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-alpha.1149', + extensionVersion: '0.0.1149', + }), + ).to.eq('0.0.1149.1') + }) + + it('it should work with unstable channel and new prisma version', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-alpha.1150', + extensionVersion: '0.0.1149', + }), + ).to.eq('0.0.1150') + }) + + it('it should work with unstable channel and new prisma version after an extension only publish', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.0-alpha.1150', + extensionVersion: '0.0.1149.1', + }), + ).to.eq('0.0.1150') + }) + + it('it should work with stable channel after the ga versioning scheme and current version to new version schema', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.1', + extensionVersion: '0.0.3', + }), + ).to.eq('2.0.1') + }) + + it('it should work with stable channel after the ga versioning scheme and extension only push', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.1', + extensionVersion: '0.0.3.1', + }), + ).to.eq('2.0.1') + }) + + it('it should work with stable channel after the ga versioning scheme and new prisma version', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.2', + extensionVersion: '2.0.1', + }), + ).to.eq('2.0.2') + }) + + it('it should work with stable channel after the ga versioning scheme and new prisma version after an extension only publish', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.2', + extensionVersion: '2.0.1.1', + }), + ).to.eq('2.0.2') + }) + + it('it should work with unstable channel after the ga versioning scheme and current version to new version schema', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.1-dev.1', + extensionVersion: '0.0.1150', + }), + ).to.eq('0.1.1') + }) + + it('it should work with unstable channel after the ga versioning scheme and extension only push', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.1-dev.1', + extensionVersion: '0.1.1', + }), + ).to.eq('0.1.1.1') + }) + + it('it should work with unstable channel after the ga versioning scheme and new prisma version', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.1-dev.2', + extensionVersion: '0.1.1', + }), + ).to.eq('0.1.2') + }) + + it('it should work with unstable channel after the ga versioning scheme and new prisma version after an extension only publish', () => { + expect( + nextExtensionVersion({ + prismaVersion: '2.0.1-dev.2', + extensionVersion: '0.1.1.1', + }), + ).to.eq('0.1.2') + }) +})