Skip to content

Commit

Permalink
v1.9.0 (#24)
Browse files Browse the repository at this point in the history
* v1.8.0

* Remove reverse feed direction change

* Port over find latest version work to not assume a feed direction (#23)

* v1.9.0
  • Loading branch information
davidknise authored Sep 25, 2023
1 parent 0ceebcf commit 8680376
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 55 deletions.
26 changes: 0 additions & 26 deletions CHANGELOG.md

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/security-devops-azdevops-task-lib",
"version": "1.7.2",
"version": "1.9.0",
"description": "Microsoft Security DevOps for Azure DevOps task library.",
"author": "Microsoft Corporation",
"license": "MIT",
Expand Down
139 changes: 113 additions & 26 deletions src/msdo-nuget-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,50 +228,137 @@ async function _resolveVersion(
let result = await requestJson(searchQueryServiceUrlWithQuery, requestOptions);
const findPreRelease = common.isLatestPreRelease(packageVersion);

resolvedVersion = findLatestVersion(result, findPreRelease);

if (resolvedVersion == null) {
throw new Error(`Package not found: ${packageName}`);
}

return resolvedVersion;
}

/**
* Finds the latest version in a SearchQueryService response.
*
* @param result A JSON object returned from the SearchQueryService
* @param findPreRelease Whether or not to find a pre-release version
* @returns The latest version of the package
*/
function findLatestVersion(
result: object,
findPreRelease: boolean): string {
let latestVersion = null;
let latestVersionParts = null;
let latestIsPreRelease = false;
let latestPreReleaseFlag = null;

if (result == null || result['items'] == null) {
return latestVersion;
}

let currentCatalogEntry = null;
let currentVersion = null;
let currentVersionParts = null;
let currentFullVersionParts = null;
let currentVersionNumbersString = null;
let currentIsLatest = false;
let currentIsPreRelease = false;
let currentPreReleaseFlag = null;

for (let packageGroup of result['items']) {
for (let packageInfo of packageGroup['items']) {
let catalogEntry = packageInfo['catalogEntry'];
if (catalogEntry['listed'] != true) {
currentCatalogEntry = packageInfo['catalogEntry'];

if (currentCatalogEntry['listed'] != true) {
// skip delisted packages
continue;
}

if (!findPreRelease && common.isPreRelease(catalogEntry['version'])) {
currentVersion = currentCatalogEntry['version'];
currentIsPreRelease = common.isPreRelease(currentVersion);

if (!findPreRelease && currentIsPreRelease) {
// skip prerelease packages if we're looking for a stable version
continue;
}

resolvedVersion = catalogEntry['version'];
break;
}
currentFullVersionParts = currentVersion.split("-");
if (currentIsPreRelease) {
currentPreReleaseFlag = currentFullVersionParts[1];
}

if (resolvedVersion != null) {
break;
}
}

if (resolvedVersion == null) {
throw new Error(`Package not found: ${packageName}`);
}
currentVersionNumbersString = currentFullVersionParts[0];
currentVersionParts = currentVersionNumbersString.split(".");
currentIsLatest = latestVersion == null;

return resolvedVersion;
}
if (!currentIsLatest) {
// Evaluate the current version against the latest version

// Handle comparisons of separate level versions
// Some packages exclude Patch or include Revisions up to two levels (Rev1 and Rev2)
let maxVersionParts = currentVersionParts.length;
if (currentVersionParts.length < maxVersionParts) {
maxVersionParts = latestVersionParts.length;
}

function rampedDeployment(
datetime: Date,
rampMinutes: number): boolean {
let ramped = false;
for (let versionPartIndex = 0; versionPartIndex < currentVersionParts.length; versionPartIndex++) {
let versionPart = 0;
let latestVersionPart = 0;

let curDate = new Date();
let isLastVersionPart = versionPartIndex == (maxVersionParts - 1);

let diff = curDate.getTime() - datetime.getTime();
if (versionPartIndex < currentVersionParts.length) {
versionPart = parseInt(currentVersionParts[versionPartIndex]);
}

datetime.setMinutes


return Math.random() > diff;
if (versionPartIndex < latestVersionParts.length) {
latestVersionPart = parseInt(latestVersionParts[versionPartIndex]);
}

if (versionPart > latestVersionPart) {
currentIsLatest = true;
} else if (versionPart == latestVersionPart) {
currentIsLatest = isLastVersionPart
&&
(
(currentIsPreRelease && latestIsPreRelease && currentPreReleaseFlag > latestPreReleaseFlag)
||
(!currentIsPreRelease && latestIsPreRelease)
);
} else {
// Current version is less than latest found
break;
}

if (currentIsLatest) {
break;
}
}
}

if (currentIsLatest) {
latestVersion = currentVersion;
latestVersionParts = currentVersionParts;
latestIsPreRelease = currentIsPreRelease;
latestPreReleaseFlag = currentPreReleaseFlag;
}
}
}

tl.debug(`latestVersion = ${latestVersion}`);
return latestVersion;
}

// function rampedDeployment(
// datetime: Date,
// rampMinutes: number): boolean {
// let ramped = false;
// let curDate = new Date();
// let diff = curDate.getTime() - datetime.getTime();
// datetime.setMinutes
// return Math.random() > diff;
// }

/**
* Top level service call to download a package from a NuGet server.
*
Expand Down

0 comments on commit 8680376

Please sign in to comment.