Skip to content

Commit 027efd5

Browse files
allow to specify version with v semantic like v1.0.0
This will be a breaking change. Internally we will make no distinction between tags starting with `v` prefix and ones that doesn't have it. This means that for version `0.x` for the cli, because we changed the tag naming in the latest releases, the `0.x` version will be expaned to `0.36.rc2` instead of `0.34.2`.
1 parent 2ba91fa commit 027efd5

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

Diff for: __tests__/main.test.ts

+43-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,50 @@ describe("installer tests", () => {
8484
}
8585
}, 20000);
8686

87-
it("Gets latest version of Task using 0.x and no matching version is installed", async () => {
87+
it("Gets the latest version of Arduino CLI v1.0.0 using 1.0.0 with no `v` prefix", async () => {
88+
await installer.getArduinoCli("1.0.0");
89+
const bindir = path.join(toolDir, "arduino-cli", "1.0.0", os.arch());
90+
91+
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
92+
if (IS_WINDOWS) {
93+
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
94+
} else {
95+
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
96+
}
97+
}, 20000);
98+
99+
it("Gets the latest version of Arduino CLI v1.0.0 using the `v` prefix (v1.0.0)", async () => {
100+
await installer.getArduinoCli("v1.0.0");
101+
const bindir = path.join(toolDir, "arduino-cli", "1.0.0", os.arch());
102+
103+
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
104+
if (IS_WINDOWS) {
105+
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
106+
} else {
107+
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
108+
}
109+
}, 20000);
110+
111+
it("Gets the latest version of Arduino CLI using the v1.x", async () => {
112+
await installer.getArduinoCli("v1.x");
113+
const bindir = path.join(toolDir, "arduino-cli", "1.0.1", os.arch());
114+
115+
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
116+
if (IS_WINDOWS) {
117+
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
118+
} else {
119+
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
120+
}
121+
}, 20000);
122+
123+
it("Gets latest version of Arduino CLI using 0.x and no matching version is installed", async () => {
88124
await installer.getArduinoCli("0.x");
89-
const bindir = path.join(toolDir, "arduino-cli", "0.34.2", os.arch());
125+
const bindir = path.join(
126+
toolDir,
127+
"arduino-cli",
128+
"0.36.0-rc.2",
129+
os.arch(),
130+
);
90131

91132
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
92133
if (IS_WINDOWS) {

Diff for: src/installer.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ function getFileName(version: string): string {
117117
break;
118118
}
119119

120+
// Newer versions of the cli are tagged with the `v` prefix, but the artifacts
121+
// doesn't containt that prefix, se we normalize the version.
122+
if (version.startsWith("v")) {
123+
version = version.substring(1);
124+
}
120125
return util.format("arduino-cli_%s_%s_%s.%s", version, platform, arch, ext);
121126
}
122127

@@ -141,13 +146,25 @@ async function fetchVersions(): Promise<string[]> {
141146

142147
// Compute an actual version starting from the `version` configuration param.
143148
async function computeVersion(version: string): Promise<string> {
149+
// remove the v prefix. This is done for backwards compatibility reasion.
150+
// Newer releases of the cli are tagged with the v prefix, but not the older
151+
// ones.
152+
if (version.startsWith("v")) {
153+
version = version.substring(1);
154+
}
155+
144156
// strip trailing .x chars
145157
if (version.endsWith(".x")) {
146158
version = version.slice(0, version.length - 2);
147159
}
148160

149161
const allVersions = await fetchVersions();
150-
const possibleVersions = allVersions.filter((v) => v.startsWith(version));
162+
const possibleVersions = allVersions.filter(function (v) {
163+
if (v.startsWith("v")) {
164+
return v.startsWith("v" + version);
165+
}
166+
return v.startsWith(version);
167+
});
151168

152169
const versionMap = new Map();
153170
possibleVersions.forEach((v) => versionMap.set(normalizeVersion(v), v));

0 commit comments

Comments
 (0)