This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DryRun option to RestoreCache (#27)
* Add dry run flag * Emit debug output * Remove unused logging * Add failing unit test for dryrun option * Unit test new dryrun functionality * Throw error if unable to parse collection uri for instance * Remove unused logging
- Loading branch information
Showing
23 changed files
with
869 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Tasks/Common/packaging-common/Tests/FeedUtilityMockHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import tmrm = require("azure-pipelines-task-lib/mock-run"); | ||
import Axios from "axios"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
|
||
export interface IMockResponse { | ||
responseCode: number; | ||
data?: any; | ||
} | ||
|
||
export function registerFeedUtilityMock( | ||
tmr: tmrm.TaskMockRunner, | ||
response: IMockResponse | ||
) { | ||
tmr.setInput("feedlist", "node-package-feed"); | ||
tmr.setInput("verbosity", "verbose"); | ||
|
||
process.env.BUILD_DEFINITIONNAME = "build definition"; | ||
process.env.AGENT_HOMEDIRECTORY = "/users/home/directory"; | ||
process.env.BUILD_SOURCESDIRECTORY = "/users/home/sources"; | ||
process.env.SYSTEM_SERVERTYPE = "hosted"; | ||
process.env.ENDPOINT_AUTH_SYSTEMVSSCONNECTION = | ||
'{"parameters":{"AccessToken":"token"},"scheme":"OAuth"}'; | ||
process.env.ENDPOINT_URL_SYSTEMVSSCONNECTION = | ||
"https://example.visualstudio.com/defaultcollection"; | ||
process.env.SYSTEM_DEFAULTWORKINGDIRECTORY = "/users/home/directory"; | ||
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = | ||
"https://example.visualstudio.com/defaultcollection"; | ||
|
||
const mock = new MockAdapter(Axios); | ||
console.log("mocking this out"); | ||
|
||
mock.onAny().reply(response.responseCode, response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as pkgLocationUtils from "../locationUtilities"; | ||
import * as tl from "azure-pipelines-task-lib"; | ||
import Axios, { AxiosRequestConfig } from "axios"; | ||
|
||
interface IPackage { | ||
id: string; | ||
name: string; | ||
version: string; | ||
} | ||
|
||
export async function doesPackageExist(hash: string): Promise<boolean> { | ||
const feedId = tl.getInput("feedList"); | ||
// Getting package name from hash | ||
const packageId = tl | ||
.getVariable("Build.DefinitionName") | ||
.replace(/\s/g, "") | ||
.substring(0, 255) | ||
.toLowerCase(); | ||
|
||
const version = `1.0.0-${hash}`; | ||
const accessToken = pkgLocationUtils.getSystemAccessToken(); | ||
const collectionUri = process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI; | ||
|
||
let instance: string = ""; | ||
const legacyRegex = /https:\/\/(\S+).visualstudio.com\S+/g; | ||
const newRegex = /https:\/\/dev.azure.com\/(\S+)\//g; | ||
|
||
const legacyUrl = legacyRegex.exec(collectionUri); | ||
const newUrl = newRegex.exec(collectionUri); | ||
|
||
if (legacyUrl) { | ||
instance = legacyUrl[1]; | ||
} else if (newUrl) { | ||
instance = newUrl[1]; | ||
} else { | ||
throw `Unable to parse collection uri: '${collectionUri}'`; | ||
} | ||
|
||
const url = `https://pkgs.dev.azure.com/${instance}/_apis/packaging/feeds/${feedId}/upack/packages/${packageId}/versions/${version}?api-version=5.1-preview.1`; | ||
|
||
const config: AxiosRequestConfig = { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
Accept: "application/json" | ||
} | ||
}; | ||
try { | ||
const result = await Axios.get<IPackage>(url, config); | ||
|
||
tl.debug(JSON.stringify(result.data)); | ||
|
||
return result.data.version === version; | ||
} catch (err) { | ||
tl.debug(err.toString()); | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.