@@ -352,17 +352,49 @@ void runBuild(ref Box box, string ver, bool isBranch, bool skipDocs, string ldcV
352352import std.regex ;
353353enum versionRE = regex(` ^v(\d+)\.(\d+)\.(\d+)(-.*)?$` );
354354
355+ // / Determines the latest release tagged for the Dub repository
355356string getDubTag (bool preRelease)
356357{
357358 import std.net.curl : get ;
358- import std.json : parseJSON;
359+ import std.json : parseJSON, JSONValue ;
359360
360361 // github already sorts tags in descending semantic versioning order
361- foreach (tag; get (" https://api.github.com/repos/dlang/dub/tags" ).parseJSON.array)
362+ foreach (tag; get (" https://api.github.com/repos/dlang/dub/tags" ).parseJSON.array.ifThrown(JSONValue[].init) )
362363 if (auto m = tag[" name" ].str.match(versionRE))
363364 if (preRelease || m.captures[4 ].empty)
364365 return tag[" name" ].str;
365- throw new Exception (" Failed to get dub tags" );
366+
367+ // Fallback: Use git ls-remote to list all known tags and sort them appropriatly
368+ auto re = regex(` v(\d+)\.(\d+)\.(\d+)(-[^\^]*)?$` );
369+ auto tagList = runCapture(" git ls-remote --tags https://github.com/dlang/dub.git" )
370+ .lineSplitter
371+ .map! (t => t.match(re))
372+ .filter! (m => ! m.empty && (preRelease || m.captures[4 ].empty))
373+ .array;
374+
375+ enforce(! tagList.empty, " Failed to get dub tags" );
376+
377+ // Order by version numbers as integers
378+ alias lessVer (int idx) = (a, b) => a.captures[idx].to! int < b.captures[idx].to! int ;
379+
380+ // Order by suffix
381+ alias lessSuf = (ca, cb) {
382+ const a = ca.captures[4 ];
383+ const b = cb.captures[4 ];
384+
385+ // Preference: "beta" < "rc" < ""
386+ if (a.length != b.length)
387+ return a.length > b.length;
388+
389+ // Lexical order to compare numbers "beta.1" vs "beta.2*"
390+ return a < b;
391+ };
392+
393+ // Sort entire list according to the predicates defined above
394+ tagList.multiSort! (lessVer! 1 , lessVer! 2 , lessVer! 3 , lessSuf);
395+
396+ // Maximum element denotes the most recent tag
397+ return tagList[$- 1 ].captures[0 ];
366398}
367399
368400void getCodesignCerts (string tgtDir)
0 commit comments