-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix hard coded version applied to user-agent string by adding an expl…
…icit file, add new github action for bump-version allowing us to easily bump a semver version with a prereleaseSuffix if desired, add new release github workflow to facillitate triggering releases for the Go sdk using git tags and updating the version.go file
- Loading branch information
1 parent
aee839b
commit 627e89a
Showing
12 changed files
with
4,171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const core = require("./core"); | ||
|
||
function bumpVersion(currentVersion, bumpType, prerelease) { | ||
let newVersion = calculateNewVersion(currentVersion, bumpType); | ||
|
||
if (prerelease) { | ||
newVersion = `${newVersion}.${prerelease}`; | ||
} | ||
core.setOutput("previous_version", currentVersion); | ||
core.setOutput("previous_version_tag", `v${currentVersion}`); | ||
core.setOutput("version", newVersion); | ||
core.setOutput("version_tag", `v${newVersion}`); | ||
} | ||
|
||
function calculateNewVersion(currentVersion, bumpType) { | ||
const [major, minor, patch] = currentVersion.split("."); | ||
let newVersion; | ||
|
||
switch (bumpType) { | ||
case "major": | ||
newVersion = `${parseInt(major) + 1}.0.0`; | ||
break; | ||
case "minor": | ||
newVersion = `${major}.${parseInt(minor) + 1}.0`; | ||
break; | ||
case "patch": | ||
newVersion = `${major}.${minor}.${parseInt(patch) + 1}`; | ||
break; | ||
default: | ||
throw new Error(`Invalid bumpType: ${bumpType}`); | ||
} | ||
|
||
return newVersion; | ||
} | ||
|
||
module.exports = { bumpVersion }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const action = require("./action"); | ||
const core = require("./core"); | ||
|
||
jest.mock("./core"); | ||
|
||
describe("bump-version", () => { | ||
test("bump major", () => { | ||
action.bumpVersion("1.2.3", "major", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.2.3"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.2.3" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "2.0.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v2.0.0"); | ||
}); | ||
|
||
test("bump minor: existing minor and patch", () => { | ||
action.bumpVersion("1.2.3", "minor", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.2.3"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.2.3" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.3.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.3.0"); | ||
}); | ||
|
||
test("bump minor: with no patch", () => { | ||
action.bumpVersion("1.2.0", "minor", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.2.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.2.0" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.3.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.3.0"); | ||
}); | ||
|
||
test("bump minor: from existing patch", () => { | ||
action.bumpVersion("2.2.3", "minor", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "2.2.3"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v2.2.3" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "2.3.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v2.3.0"); | ||
}); | ||
|
||
test("bump patch: existing patch", () => { | ||
action.bumpVersion("1.2.3", "patch", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.2.3"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.2.3" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.2.4"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.2.4"); | ||
}); | ||
|
||
test("bump patch: minor with no patch", () => { | ||
action.bumpVersion("1.2.0", "patch", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.2.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.2.0" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.2.1"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.2.1"); | ||
}); | ||
|
||
test("bump patch: major with no minor or patch", () => { | ||
action.bumpVersion("1.0.0", "patch", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.0.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.0.0" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.0.1"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.0.1"); | ||
}); | ||
|
||
test("bump patch: major with minor", () => { | ||
action.bumpVersion("1.1.0", "patch", ""); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.1.0"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.1.0" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.1.1"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.1.1"); | ||
}); | ||
|
||
test("prerelease suffix provided", () => { | ||
action.bumpVersion("1.2.3", "patch", "rc1"); | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith("previous_version", "1.2.3"); | ||
expect(core.setOutput).toHaveBeenCalledWith( | ||
"previous_version_tag", | ||
"v1.2.3" | ||
); | ||
expect(core.setOutput).toHaveBeenCalledWith("version", "1.2.4.rc1"); | ||
expect(core.setOutput).toHaveBeenCalledWith("version_tag", "v1.2.4.rc1"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: 'pinecone-io/bump-version' | ||
|
||
description: 'Bumps a given semantic version number based on a bumpType and prereleaseSuffix' | ||
|
||
inputs: | ||
currentVersion: | ||
description: 'The current version of the client to bump from' | ||
required: true | ||
bumpType: | ||
description: 'The type of version bump (major, minor, patch)' | ||
required: true | ||
prereleaseSuffix: | ||
description: 'Optional prerelease identifier to append to the version number' | ||
required: false | ||
default: '' | ||
|
||
outputs: | ||
version: | ||
description: 'The new version number' | ||
version_tag: | ||
description: 'The new version tag' | ||
previous_version: | ||
description: 'The previous version number' | ||
previous_version_tag: | ||
description: 'The previous version tag' | ||
|
||
runs: | ||
using: 'node20' | ||
main: 'index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copied these commands out of the github actions toolkit | ||
// because actually depending on @actions/core requires me to check | ||
// in node_modules and 34MB of dependencies, which I don't want to do. | ||
|
||
const fs = require("fs"); | ||
const os = require("os"); | ||
|
||
function getInput(name, options) { | ||
const val = | ||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || ""; | ||
if (options && options.required && !val) { | ||
throw new Error(`Input required and not supplied: ${name}`); | ||
} | ||
|
||
if (options && options.trimWhitespace === false) { | ||
return val; | ||
} | ||
|
||
return val.trim(); | ||
} | ||
|
||
function toCommandValue(input) { | ||
if (input === null || input === undefined) { | ||
return ""; | ||
} else if (typeof input === "string" || input instanceof String) { | ||
return input; | ||
} | ||
return JSON.stringify(input); | ||
} | ||
|
||
function prepareKeyValueMessage(key, value) { | ||
const delimiter = `delimiter_${Math.floor(Math.random() * 100000)}`; | ||
const convertedValue = toCommandValue(value); | ||
|
||
// These should realistically never happen, but just in case someone finds a | ||
// way to exploit uuid generation let's not allow keys or values that contain | ||
// the delimiter. | ||
if (key.includes(delimiter)) { | ||
throw new Error( | ||
`Unexpected input: name should not contain the delimiter "${delimiter}"` | ||
); | ||
} | ||
|
||
if (convertedValue.includes(delimiter)) { | ||
throw new Error( | ||
`Unexpected input: value should not contain the delimiter "${delimiter}"` | ||
); | ||
} | ||
|
||
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`; | ||
} | ||
|
||
function setOutput(name, value) { | ||
const filePath = process.env["GITHUB_OUTPUT"] || ""; | ||
if (filePath) { | ||
return issueFileCommand("OUTPUT", prepareKeyValueMessage(name, value)); | ||
} | ||
|
||
process.stdout.write(os.EOL); | ||
issueCommand("set-output", { name }, toCommandValue(value)); | ||
} | ||
|
||
function issueFileCommand(command, message) { | ||
const filePath = process.env[`GITHUB_${command}`]; | ||
if (!filePath) { | ||
throw new Error( | ||
`Unable to find environment variable for file command ${command}` | ||
); | ||
} | ||
if (!fs.existsSync(filePath)) { | ||
throw new Error(`Missing file at path: ${filePath}`); | ||
} | ||
|
||
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { | ||
encoding: "utf8", | ||
}); | ||
} | ||
|
||
module.exports = { getInput, setOutput }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const action = require("./action"); | ||
const core = require("./core"); | ||
|
||
action.bumpVersion( | ||
core.getInput("currentVersion"), | ||
core.getInput("bumpType"), | ||
core.getInput("prereleaseSuffix") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"verbose": true | ||
} |
Oops, something went wrong.