Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update symlinkSync to copy method due to permission error #4304

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/azuredevops/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ From `setupAzd` folder, run `npm test`
## Release

- Update `setupAzd/task.json` with the `version` number.
- Update `vss-extension.json` with the `version` to release.
- Update `vss-extension.json`, `package.json` and `package-lock.json` with the `version` to release.
- Run the `build` steps to produce the `vsix` release artifact.
- Follow [publish steps](https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops#5-publish-your-extension) to update the Marketplace.
185 changes: 91 additions & 94 deletions ext/azuredevops/setupAzd/index.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,106 @@
import * as task from 'azure-pipelines-task-lib/task';
import * as cp from 'child_process'
import path from 'path';
import * as fs from 'fs'
import download from 'download';
import decompress from 'decompress';
import * as task from "azure-pipelines-task-lib/task";
import path from "path";
import * as fs from "fs";
import download from "download";
import decompress from "decompress";

export async function runMain(): Promise<void> {
try {
task.setTaskVariable('hasRunMain', 'true');
const version = task.getInput('version') || 'latest'

console.log("using version: " + version)

// get architecture and os
const architecture = process.arch
const os = process.platform

// map for different platform and arch
const extensionMap = {
linux: '.tar.gz',
darwin: '.zip',
win32: '.zip'
}

const exeMap = {
linux: '',
darwin: '',
win32: '.exe'
}

const arm64Map = {
x64: 'amd64',
arm64: 'arm64-beta'
}

const platformMap = {
linux: 'linux',
darwin: 'darwin',
win32: 'windows'
}

// get install url
const installArray = installUrlForOS(
os,
architecture,
platformMap,
arm64Map,
extensionMap,
exeMap
)

const url = `https://azdrelease.azureedge.net/azd/standalone/release/${version}/${installArray[0]}`

console.log(`The Azure Developer CLI collects usage data and sends that usage data to Microsoft in order to help us improve your experience.
try {
task.setTaskVariable("hasRunMain", "true");
const version = task.getInput("version") || "latest";

console.log("using version: " + version);

// get architecture and os
const architecture = process.arch;
const os = process.platform;

// map for different platform and arch
const extensionMap = {
linux: ".tar.gz",
darwin: ".zip",
win32: ".zip",
};

const exeMap = {
linux: "",
darwin: "",
win32: ".exe",
};

const arm64Map = {
x64: "amd64",
arm64: "arm64-beta",
};

const platformMap = {
linux: "linux",
darwin: "darwin",
win32: "windows",
};

// get install url
const installArray = installUrlForOS(
os,
architecture,
platformMap,
arm64Map,
extensionMap,
exeMap
);

const url = `https://azdrelease.azureedge.net/azd/standalone/release/${version}/${installArray[0]}`;

console.log(`The Azure Developer CLI collects usage data and sends that usage data to Microsoft in order to help us improve your experience.
You can opt-out of telemetry by setting the AZURE_DEV_COLLECT_TELEMETRY environment variable to 'no' in the shell you use.

Read more about Azure Developer CLI telemetry: https://github.com/Azure/azure-dev#data-collection`)

console.log(`Installing azd from ${url}`)
const buffer = await download(url);
const extractedTo = path.join(task.cwd(), 'azd-install');
await decompress(buffer, extractedTo);

let binName
if (os !== 'win32') {
binName = 'azd';
} else {
binName = 'azd.exe';
}
const binPath = path.join(extractedTo, binName);

fs.symlinkSync(
path.join(extractedTo, installArray[1]),
binPath
)
task.prependPath(extractedTo)
console.log(`azd installed to ${extractedTo}`)

task.exec(binPath, 'version')
} catch (err: any) {
task.setResult(task.TaskResult.Failed, err.message);
Read more about Azure Developer CLI telemetry: https://github.com/Azure/azure-dev#data-collection`);

console.log(`Installing azd from ${url}`);
const buffer = await download(url);
const extractedTo = path.join(task.cwd(), "azd-install");
await decompress(buffer, extractedTo);

let binName;
if (os !== "win32") {
binName = "azd";
} else {
binName = "azd.exe";
}
const binPath = path.join(extractedTo, binName);

// This is not symlinkSync as setup-azd GitHub Action due to Self-Host Agent permission error
fs.copyFileSync(path.join(extractedTo, installArray[1]), binPath);
task.prependPath(extractedTo);
console.log(`azd installed to ${extractedTo}`);

task.execSync(binPath, "version");
} catch (err: any) {
task.setResult(task.TaskResult.Failed, err.message);
}
}

function installUrlForOS(
os: string,
architecture: string,
platformMap: Record<string, string>,
archMap: Record<string, string>,
extensionMap: Record<string, string>,
exeMap: Record<string, string>
os: string,
architecture: string,
platformMap: Record<string, string>,
archMap: Record<string, string>,
extensionMap: Record<string, string>,
exeMap: Record<string, string>
): [string, string] {
const platformPart = `${platformMap[os]}`
const archPart = `${archMap[architecture]}`
const platformPart = `${platformMap[os]}`;
const archPart = `${archMap[architecture]}`;

if (platformPart === `undefined` || archPart === `undefined`) {
throw new Error(
`Unsupported platform and architecture: ${architecture} ${os}`
)
}
if (platformPart === `undefined` || archPart === `undefined`) {
throw new Error(
`Unsupported platform and architecture: ${architecture} ${os}`
);
}

const installUrl = `azd-${platformPart}-${archPart}${extensionMap[os]}`
const installUrlForRename = `azd-${platformPart}-${archPart}${exeMap[os]}`
const installUrl = `azd-${platformPart}-${archPart}${extensionMap[os]}`;
const installUrlForRename = `azd-${platformPart}-${archPart}${exeMap[os]}`;

return [installUrl, installUrlForRename]
return [installUrl, installUrlForRename];
}

runMain();
Loading