-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
main.ts
106 lines (86 loc) · 3.92 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var path = require("path");
import * as tl from "azure-pipelines-task-lib/task";
import * as nutil from "packaging-common/nuget/Utility";
import * as telemetry from "utility-common/telemetry";
import { PackageUrlsBuilder } from "./packagebuilder";
import { PackageFile } from "./packagefile";
import { getConnection } from "./connections";
import { Retry } from "./retry";
import { downloadUniversalPackage } from "./universal";
import { getProjectAndFeedIdFromInputParam } from "packaging-common/util"
tl.setResourcePath(path.join(__dirname, "task.json"));
async function main(): Promise<void> {
// Getting inputs.
let packageType = tl.getInput("packageType");
let projectFeed = tl.getInput("feed");
let viewId = tl.getInput("view");
let packageId = tl.getInput("definition");
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let filesPattern = tl.getInput("files");
let extractPackage = tl.getInput("extract") === "true" && (packageType === "npm" || packageType === "nuget");
// Getting variables.
const collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
const retryLimitValue: string = tl.getVariable("VSTS_HTTP_RETRY");
const retryLimit: number = !!retryLimitValue && !isNaN(parseInt(retryLimitValue)) ? parseInt(retryLimitValue) : 4;
const skipDownload = tl.getVariable("Packaging.SkipDownload") === "true";
try {
if (skipDownload) {
tl.debug("Download Package skipped.");
return Promise.resolve();
}
var feed = getProjectAndFeedIdFromInputParam("feed");
if (packageType === "upack") {
return await downloadUniversalPackage(downloadPath, feed.feedId, packageId, version, filesPattern);
}
if (viewId && viewId.replace(/\s/g, "") !== "") {
feed.feedId = feed.feedId + "@" + viewId;
}
let files: string[] = [];
if (filesPattern) {
files = nutil.getPatternsArrayFromInput(filesPattern);
}
const feedConnection = await getConnection("7AB4E64E-C4D8-4F50-AE73-5EF2E21642A5", collectionUrl);
const pkgsConnection = await getConnection("B3BE7473-68EA-4A81-BFC7-9530BAAA19AD", collectionUrl);
var p = await new PackageUrlsBuilder()
.ofType(packageType)
.withPkgsConnection(pkgsConnection)
.withFeedsConnection(feedConnection)
.matchingPattern(files)
.withRetries(Retry(retryLimit))
.build();
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
if(!regexGuid.test(packageId)){
tl.debug("Trying to resolve package name " + packageId + " to id.");
packageId = await p.resolvePackageId(feed.feedId, feed.projectId, packageId);
tl.debug("Resolved package id: " + packageId);
}
const packageFiles: PackageFile[] = await p.download(feed.feedId, feed.projectId, packageId, version, downloadPath, extractPackage);
packageFiles.forEach(packageFile => {
packageFile.process();
});
return Promise.resolve();
} finally {
logTelemetry({
PackageType: packageType,
FeedId : feed.feedId,
Project: feed.projectId,
ViewId : viewId,
PackageId: packageId,
Version: version,
SkipDownload: skipDownload,
ExtractPackage: extractPackage,
IsTriggeringArtifact: tl.getInput("isTriggeringArtifact")
});
}
}
function logTelemetry(params: any) {
try {
telemetry.emitTelemetry("Packaging", "DownloadPackagev1", params);
} catch (err) {
tl.debug(`Unable to log DownloadPackageV1 task telemetry. Err:( ${err} )`);
}
}
main()
.then(result => tl.setResult(tl.TaskResult.Succeeded, ""))
.catch(error => tl.setResult(tl.TaskResult.Failed, error));