Skip to content

Commit

Permalink
feat(versioning-scheme): derive extension version from prisma version
Browse files Browse the repository at this point in the history
Fixes #121
  • Loading branch information
Divyendu Singh committed May 4, 2020
1 parent 0aeedd0 commit 4433775
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 5 deletions.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion scripts/check-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions scripts/extension-version.js
Original file line number Diff line number Diff line change
@@ -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)
}
149 changes: 149 additions & 0 deletions scripts/extension-version.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
})

0 comments on commit 4433775

Please sign in to comment.