Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Remove the need for type of artifact and alias from Install/Checkout Tasks #151

Merged
merged 11 commits into from Sep 19, 2020
2 changes: 2 additions & 0 deletions README.md
@@ -1,3 +1,5 @@
[![DeepScan grade](https://deepscan.io/api/teams/10234/projects/12959/branches/208838/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=10234&pid=12959&bid=208838) [![Build Status](https://dev.azure.com/dxatscale/sfpowerscripts/_apis/build/status/Release?branchName=develop)](https://dev.azure.com/dxatscale/sfpowerscripts/_build/latest?definitionId=40&branchName=develop) ![npm](https://img.shields.io/npm/v/@dxatscale/sfpowerscripts)![NPM](https://img.shields.io/npm/l/@dxatscale/sfpowerscripts) ![Visual Studio Marketplace Installs - Azure DevOps Extension](https://img.shields.io/visual-studio-marketplace/azure-devops/installs/total/AzlamSalam.sfpowerscripts?label=visualstudio%20marketplace%20installations)

<p align="center">
<img alt="sfpowerscripts" src="https://repository-images.githubusercontent.com/248449736/5d08c600-728e-11ea-8267-ae1aceebea60" width="480" height="400">
</p>
Expand Down
@@ -1,72 +1,75 @@
import tl = require("azure-pipelines-task-lib/task");
var fs = require("fs-extra");
const path = require("path");
import simplegit from "simple-git/promise";
import { isNullOrUndefined } from "util";
var shell = require("shelljs");
import ArtifactFilePathFetcher from "../Common/ArtifactFilePathFetcher";
import ArtifactFilePathFetcher from "@dxatscale/sfpowerscripts.core/lib/artifacts/ArtifactFilePathFetcher";
import PackageMetadata from "@dxatscale/sfpowerscripts.core/lib/PackageMetadata";
import ArtifactHelper from "../Common/ArtifactHelper";

const fs = require("fs-extra");
const path = require("path");

async function run() {
try {


let artifact_directory = tl.getVariable("system.artifactsDirectory");
const artifact = tl.getInput("artifact", true);
const artifactProvider = tl.getInput("artifactProvider", true);
let sfdx_package = tl.getInput("package", false);
let skip_on_missing_artifact: boolean = tl.getBoolInput("skip_on_missing_artifact",false);

let artifactDir = tl.getInput("aritfactDir",false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo on the artifact directory input

let skip_on_missing_artifact: boolean = tl.getBoolInput(
"skip_on_missing_artifact",
false
);

let version_control_provider: string;
let token: string;
let username: string;

//Read Git User Endpoint
version_control_provider = tl.getInput("versionControlProvider", true);
version_control_provider = tl.getInput("versionControlProvider", true);

let connection: string;
let vcsAuthDetails = getVCSAuthDetails(version_control_provider, connection);
token=vcsAuthDetails.token;
username=vcsAuthDetails.username;
let connection: string;
let vcsAuthDetails = getVCSAuthDetails(
version_control_provider,
connection
);
token = vcsAuthDetails.token;
username = vcsAuthDetails.username;

//Fetch Artifact
//Fetch Artifact
let artifactFilePaths = ArtifactFilePathFetcher.fetchArtifactFilePaths(
artifact,
artifactProvider,
ArtifactHelper.getArtifactDirectory(artifactDir),
sfdx_package
);

ArtifactFilePathFetcher.missingArtifactDecider(
artifactFilePaths[0].packageMetadataFilePath,
skip_on_missing_artifact
ArtifactHelper.skipTaskWhenArtifactIsMissing(
ArtifactFilePathFetcher.missingArtifactDecider(
artifactFilePaths[0].packageMetadataFilePath,
skip_on_missing_artifact
)
);

//Read package metadata
let packageMetadataFromArtifact: PackageMetadata = JSON.parse(
fs.readFileSync(artifactFilePaths[0].packageMetadataFilePath, "utf8")
);

//Read package metadata
let packageMetadataFromArtifact: PackageMetadata = JSON.parse(fs.readFileSync(artifactFilePaths[0].packageMetadataFilePath, "utf8"));


console.log("##[command]Package Metadata:"+JSON.stringify(packageMetadataFromArtifact,(key:string,value:any)=>{
if(key=="payload")
return undefined;
else
return value;
}));


console.log(
"##[command]Package Metadata:" +
JSON.stringify(
packageMetadataFromArtifact,
(key: string, value: any) => {
if (key == "payload") return undefined;
else return value;
}
)
);

//Create Location

//For Backward Compatibility, packageName could be null when upgraded
let local_source_directory = isNullOrUndefined(sfdx_package)
? path.join(artifact_directory, artifact, "source")
: path.join(artifact_directory, artifact, sfdx_package, "source");
let local_source_directory = path.join(ArtifactHelper.getArtifactDirectory(artifactDir), sfdx_package, "source");

shell.mkdir("-p", local_source_directory);
fs.ensureDirSync(local_source_directory);

console.log(`Source Directory created at ${local_source_directory}`);


console.log(`Source Directory created at ${local_source_directory}`);

if (
packageMetadataFromArtifact.package_type === "source" ||
Expand All @@ -75,7 +78,9 @@ async function run() {
//Strinp https
const removeHttps = (input) => input.replace(/^https?:\/\//, "");

let repository_url = removeHttps(packageMetadataFromArtifact.repository_url);
let repository_url = removeHttps(
packageMetadataFromArtifact.repository_url
);

const git = simplegit(local_source_directory);

Expand All @@ -101,19 +106,22 @@ async function run() {
if (version_control_provider == "hostedAgentGit")
await git
.silent(false)
.clone(packageMetadataFromArtifact.repository_url, local_source_directory);
.clone(
packageMetadataFromArtifact.repository_url,
local_source_directory
);
else await git.silent(false).clone(remote, local_source_directory);

//Checkout the particular commit
await git.checkout(packageMetadataFromArtifact.sourceVersion);

console.log(`Checked Out ${packageMetadataFromArtifact.sourceVersion} sucessfully`);
console.log(
`Checked Out ${packageMetadataFromArtifact.sourceVersion} sucessfully`
);
} else if (packageMetadataFromArtifact.package_type === "delta") {

let delta_artifact_location;
if(!isNullOrUndefined(artifactFilePaths[0].sourceDirectoryPath))
{
delta_artifact_location=artifactFilePaths[0].sourceDirectoryPath;
if (!isNullOrUndefined(artifactFilePaths[0].sourceDirectoryPath)) {
delta_artifact_location = artifactFilePaths[0].sourceDirectoryPath;
}

tl.debug("Copying Files to a source directory");
Expand All @@ -131,12 +139,13 @@ async function run() {
} catch (err) {
tl.setResult(tl.TaskResult.Failed, err.message);
}

}

function getVCSAuthDetails(version_control_provider: string, connection: string) {

let token,username;
function getVCSAuthDetails(
version_control_provider: string,
connection: string
) {
let token, username;
switch (version_control_provider) {
case "github":
connection = tl.getInput("github_connection", true);
Expand All @@ -151,28 +160,26 @@ function getVCSAuthDetails(version_control_provider: string, connection: string)

if (version_control_provider == "azureRepo") {
token = tl.getVariable("system.accessToken");
}
else if (version_control_provider == "github" ||
version_control_provider == "githubEnterprise") {
} else if (
version_control_provider == "github" ||
version_control_provider == "githubEnterprise"
) {
token = tl.getEndpointAuthorizationParameter(
connection,
"AccessToken",
true
);
}
else if (version_control_provider == "bitbucket") {
} else if (version_control_provider == "bitbucket") {
token = tl.getEndpointAuthorizationParameter(
connection,
"AccessToken",
true
);
}
else if (version_control_provider == "otherGit") {
} else if (version_control_provider == "otherGit") {
username = tl.getInput("username", true);
token = tl.getInput("password", true);
}
return {token, username };
return { token, username };
}


run();
Expand Up @@ -16,8 +16,6 @@
"@dxatscale/sfpowerscripts.core": "^2.0.0",
"azure-pipelines-task-lib": "^2.8.0",
"fs-extra": "^8.1.0",
"glob": "^7.1.6",
"shelljs": "^0.8.3",
"simple-git": "2.0.0"
}
}
Expand Up @@ -16,14 +16,7 @@
],
"instanceNameFormat": "Checkout $(artifact) from associated build pipeline",
"inputs": [
{
"name": "artifact",
"type": "string",
"label": "Name of the artifact (alias) attached to this pipeline that needs to be checked out",
"defaultValue": "_source",
"required": true,
"helpMarkDown": "Name of the artifact that is generated from the build pipeline for checking out source, Please note this is not a generic utility and will only work for artifacts created by sfpowerscripts"
},

{
"name": "package",
"type": "string",
Expand All @@ -33,17 +26,13 @@
"helpMarkDown": "Name of the package that generated this artifact, Leave blank to support artifacts generated by older version of Create Tasks"
},
{
"name": "artifactProvider",
"type": "pickList",
"label": "Artifact Provider for the attached artifact",
"defaultValue": "BuildArtifact",
"options": {
"BuildArtifact": "Build Artifact",
"AzureArtifact": "Azure Artifact",
"PipelineArtifact":"Pipeline Artifact"
},
"required": true,
"helpMarkDown": "Select the artifact provider for the artifact that is attached to the pipeline"
"name": "aritfactDir",
"type": "string",
"label": "Path to the directory where artifacts are downloaded",
"defaultValue": "",
"required": false,
"helpMarkDown": "Path to the artifact directory where the artifacts are downloaded, If not provided, the default values will be automatically used"

},
{
"name": "versionControlProvider",
Expand Down