Skip to content

Commit c2bcfe2

Browse files
committed
feat: support v prefix in CLI GH release name
From Arduino CLI `>=0.35.0-rc.1`, the `v` prefix is expected in the GitHub release name. Ref: arduino/arduino-cli#2374 Signed-off-by: dankeboy36 <[email protected]>
1 parent 072d71c commit c2bcfe2

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ardunno-cli-gen",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Generates nice-grpc API for the Arduino CLI",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

Diff for: src/__tests__/generate.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ describe('generate', () => {
188188
assert.equal(parseSemver('v0.29.1'), '0.29.1'));
189189
it("should parse valid semver '>=0.29.0' as a semver [arduino/arduino-cli#1931]", () =>
190190
assert.equal(parseSemver('0.29.0'), '0.29.0'));
191+
describe("should trim the 'v' prefix in semver if '<v0.35.0-rc.1' [arduino/arduino-cli#2374]", () => {
192+
[
193+
['v0.34.2', '0.34.2'],
194+
['v0.35.0-rc.0', '0.35.0-rc.0'],
195+
['v0.35.0-rc.1', 'v0.35.0-rc.1'],
196+
['v0.35.0', 'v0.35.0'],
197+
['v0.35.1', 'v0.35.1'],
198+
].forEach(([toParse, expected]) =>
199+
it(`from '${toParse}' to ${expected}`, () =>
200+
assert.equal(parseSemver(toParse), expected))
201+
);
202+
});
191203
it("should parse to GitHub ref when version is not greater than '0.28.0'", () =>
192204
assert.deepEqual(parseSemver('0.28.0'), {
193205
owner: 'arduino',

Diff for: src/generate.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,15 @@ export function parseSemver(src: string): string | GitHub | undefined {
315315
return undefined;
316316
}
317317
const semver = new SemVer(src, true);
318-
const version = semver.version;
318+
let version = semver.version;
319+
if (hasSemverPrefix(version)) {
320+
log(
321+
'parsed semver %s is >=v0.35.0-rc.1. using raw version %s',
322+
version,
323+
semver.raw
324+
);
325+
version = semver.raw;
326+
}
319327
if (canDownloadProtos(semver)) {
320328
log('parsed semver %s is >=0.29.0', version);
321329
return version;
@@ -333,12 +341,19 @@ export function parseSemver(src: string): string | GitHub | undefined {
333341
}
334342

335343
/**
336-
* The `.proto` files were not part of the Arduino CLI release before version 0.29.0 ([`arduino/arduino-cli#1931`](https://github.com/arduino/arduino-cli/pull/1931)).
344+
* The `.proto` files were not part of the Arduino CLI release before version `0.29.0` ([`arduino/arduino-cli#1931`](https://github.com/arduino/arduino-cli/pull/1931)).
337345
*/
338346
function canDownloadProtos(semver: SemVer | string): boolean {
339347
return gte(semver, new SemVer('0.29.0'));
340348
}
341349

350+
/**
351+
* The Arduino CLI GitHub release has the `'v'` prefix from version `>=v0.35.0-rc.1` ([`arduino/arduino-cli#2374`](https://github.com/arduino/arduino-cli/pull/2374)).
352+
*/
353+
function hasSemverPrefix(semver: SemVer | string): boolean {
354+
return gte(semver, new SemVer('0.35.0-rc.1'));
355+
}
356+
342357
// Taken from https://github.com/microsoft/TypeScript/issues/32098#issuecomment-1212501932
343358
type RegExpGroups<T extends string[]> =
344359
| (RegExpMatchArray & {

0 commit comments

Comments
 (0)