Skip to content

Commit 143789b

Browse files
committed
fix: sanitize versions passed from github actions
1 parent 88fe425 commit 143789b

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

dist/npm/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ const requestHeaders = {
6262
};
6363
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
6464

65+
const sanitizeVersion = function(version) {
66+
if (version == null) {
67+
return "latest"
68+
}
69+
70+
if (version === "") {
71+
return "latest"
72+
}
73+
74+
if (version.startsWith("v")) {
75+
return version.slice(1)
76+
}
77+
78+
return version
79+
}
80+
6581
const getLatestVersion = function (callback) {
6682
const releasesURL = "https://github.com/loft-sh/devspace/releases/latest";
6783

@@ -104,7 +120,7 @@ const getLatestVersion = function (callback) {
104120
};
105121

106122
if (action === "update-version") {
107-
packageJson.version = "" + process.env.RELEASE_VERSION;
123+
packageJson.version = sanitizeVersion("" + process.env.RELEASE_VERSION);
108124

109125
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4));
110126
process.exit(0);
@@ -120,7 +136,7 @@ if (action === "get-latest") {
120136
}
121137

122138
if (action === "get-tag") {
123-
let latestVersion = "" + process.env.RELEASE_VERSION;
139+
let latestVersion = sanitizeVersion("" + process.env.RELEASE_VERSION);
124140
let tagRegex = /^.*-([a-z]*)(\.)?([0-9]*)?$/i
125141
let tag = "latest"
126142

@@ -152,7 +168,7 @@ function rimraf(dir_path) {
152168
}
153169

154170
let continueProcess = function (askRemoveGlobalFolder) {
155-
let version = packageJson.version;
171+
let version = sanitizeVersion("" + packageJson.version);
156172
let platform = PLATFORM_MAPPING[process.platform];
157173
let arch = ARCH_MAPPING[process.arch];
158174
let downloadExtension = ".dl";

0 commit comments

Comments
 (0)