Skip to content

Commit

Permalink
[Deasync remove] - Remove deasync from task-lib (#1002)
Browse files Browse the repository at this point in the history
* Removed unsupported lib, added async methods (#932)

* Removed unsupported lib, added async methods

* Update 3rd party library change to async

* Format style in ThirdPartyNotice

* [Deasync remove] - Remove deasync from task-lib

- Remove deasync from node build process

* [Deasync remove] - Remove deasync from task-lib

- Remove deasync from node build process

* [Deasync remove] - Remove deasync from task-lib

- Remove deasync from node build process
- Fixed unit tests
- Updated json

* Added publish script for PowerShell SDK (#975)

* simple yampl to create pipeline

* Add additional steps into pipeline to publish nuget feed

* Upgrade net framework version

* Revert csproj changes

* Specify msbuild version for old netframework support

* Add arch argument to msbuild installation

* Bump package version

* Use nuspec version directly

* Fix downloadFileAsync

* rm committed minimatch dll

* Move publish steps to job + temp disable it

* Move version to package back. Fix encoding

* Add publish script

* Update tags

* update company metadata

* Update to publish to powershell gallery

---------

Co-authored-by: Konstantin Tyukalov <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>

* [Deasync remove] - Remove deasync from task-lib

- Code review changes

---------

Co-authored-by: İsmayıl İsmayılov <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>
  • Loading branch information
4 people authored Dec 13, 2023
1 parent 54da14d commit 59c04b5
Show file tree
Hide file tree
Showing 16 changed files with 462 additions and 620 deletions.
23 changes: 23 additions & 0 deletions ci/powershell/publish-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
jobs:
- job: Publish
displayName: Publish SDK to PowerShell gallery
pool:
vmImage: windows-2022
steps:
- powershell: |
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Verbose
displayName: Install new publish cmdlets
- powershell: |
$publishOptions = @{
Path = './VstsTaskSdk'
ApiKey = $env:API_KEY
Repository = 'PSGallery'
Verbose = $true
}
Publish-PSResource @publishOptions
displayName: Publish to gallery
workingDirectory: powershell/_build
env:
API_KEY: $(PSGalleryApiKey)
8 changes: 8 additions & 0 deletions node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ Backported from ver.`3.4.0`:
## 4.4.0

- Add `getBoolFeatureFlag` [#936](https://github.com/microsoft/azure-pipelines-task-lib/pull/936)

## 4.6.0

- Replaced deprecated "sync-request" lib and Added new Async methods - [#932](https://github.com/microsoft/azure-pipelines-task-lib/pull/932)

## 5.0.0-preview.0

- [Mockery replacement] - Replaced mockery with similar adapter - [#968](https://github.com/microsoft/azure-pipelines-task-lib/pull/968)
8 changes: 5 additions & 3 deletions node/ThirdPartyNotice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This Azure Pipelines extension (azure-pipelines-task-lib) is based on or incorpo
30. semver (git+https://github.com/npm/node-semver.git)
31. shelljs (git://github.com/arturadib/shelljs.git)
32. string_decoder (git://github.com/rvagg/string_decoder.git)
33. sync-request (git+https://github.com/ForbesLindesay/sync-request.git)
33. nodejs-file-downloader (git://github.com/ibrod83/nodejs-file-downloader.git)
34. then-request (git+https://github.com/then/then-request.git)
35. typedarray (git://github.com/substack/typedarray.git)
36. typescript (git+https://github.com/Microsoft/TypeScript.git)
Expand Down Expand Up @@ -889,7 +889,8 @@ IN THE SOFTWARE.
=========================================
END OF string_decoder NOTICES, INFORMATION, AND LICENSE

%% sync-request NOTICES, INFORMATION, AND LICENSE BEGIN HERE

%% nodejs-file-downloader NOTICES, INFORMATION, AND LICENSE BEGIN HERE
=========================================
Copyright (c) 2014 Forbes Lindesay

Expand All @@ -911,7 +912,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF sync-request NOTICES, INFORMATION, AND LICENSE
END OF nodejs-file-downloader NOTICES, INFORMATION, AND LICENSE


%% then-request NOTICES, INFORMATION, AND LICENSE BEGIN HERE
=========================================
Expand Down
129 changes: 67 additions & 62 deletions node/buildutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ var fs = require('fs');
var os = require('os');
var path = require('path');
var process = require('process');
var syncRequest = require('sync-request');
var admZip = require('adm-zip');
const Downloader = require("nodejs-file-downloader");

var downloadPath = path.join(__dirname, '_download');
var testPath = path.join(__dirname, '_test');

exports.run = function(cl) {
var run = function (cl) {
console.log('> ' + cl);
var rc = exec(cl).code;
if (rc !== 0) {
echo('Exec failed with rc ' + rc);
exit(rc);
}
}
var run = exports.run;
exports.run = run;

exports.getExternals = function () {
const getExternalsAsync = async () => {
if (process.env['TF_BUILD']) {
// skip adding node 5.10.1 to the PATH. the CI definition tests against node 5 and 6.
return;
Expand All @@ -38,16 +39,19 @@ exports.getExternals = function () {
var nodeVersion = 'v16.13.0';
switch (platform) {
case 'darwin':
var nodeArchivePath = downloadArchive(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-darwin-x64.tar.gz');
var nodeArchivePath = await downloadArchiveAsync(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-darwin-x64.tar.gz');
addPath(path.join(nodeArchivePath, 'node-' + nodeVersion + '-darwin-x64', 'bin'));
break;
case 'linux':
var nodeArchivePath = downloadArchive(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-linux-x64.tar.gz');
var nodeArchivePath = await downloadArchiveAsync(nodeUrl + '/' + nodeVersion + '/node-' + nodeVersion + '-linux-x64.tar.gz');
addPath(path.join(nodeArchivePath, 'node-' + nodeVersion + '-linux-x64', 'bin'));
break;
case 'win32':
var nodeExePath = downloadFile(nodeUrl + '/' + nodeVersion + '/win-x64/node.exe');
var nodeLibPath = downloadFile(nodeUrl + '/' + nodeVersion + '/win-x64/node.lib');
var [nodeExePath, nodeLibPath] = await Promise.all([
downloadFileAsync(nodeUrl + '/' + nodeVersion + '/win-x64/node.exe'),
downloadFileAsync(nodeUrl + '/' + nodeVersion + '/win-x64/node.lib')
]);

var nodeDirectory = path.join(testPath, 'node');
mkdir('-p', nodeDirectory);
cp(nodeExePath, path.join(nodeDirectory, 'node.exe'));
Expand All @@ -57,83 +61,84 @@ exports.getExternals = function () {
}
}

var downloadFile = function (url) {
exports.getExternalsAsync = getExternalsAsync


var downloadFileAsync = async function (url, fileName) {
// validate parameters
if (!url) {
throw new Error('Parameter "url" must be set.');
}

// short-circuit if already downloaded
// skip if already downloaded
var scrubbedUrl = url.replace(/[/\:?]/g, '_');
var targetPath = path.join(downloadPath, 'file', scrubbedUrl);
if (fileName === undefined) {
fileName = scrubbedUrl;
}
var targetPath = path.join(downloadPath, 'file', fileName);
var marker = targetPath + '.completed';
if (!test('-f', marker)) {
console.log('Downloading file: ' + url);
if (test('-f', marker)) {
console.log('File already exists: ' + targetPath);
return targetPath;
}

// delete any previous partial attempt
if (test('-f', targetPath)) {
rm('-f', targetPath);
}
console.log('Downloading file: ' + url);
// delete any previous partial attempt
if (test('-f', targetPath)) {
rm('-f', targetPath);
}

// download the file
mkdir('-p', path.join(downloadPath, 'file'));
var result = syncRequest('GET', url);
fs.writeFileSync(targetPath, result.getBody());
// download the file
mkdir('-p', path.join(downloadPath, 'file'));

// write the completed marker
fs.writeFileSync(marker, '');
}
const downloader = new Downloader({
url: url,
directory: path.join(downloadPath, 'file'),
fileName: fileName
});

return targetPath;
}
const { filePath } = await downloader.download(); // Downloader.download() resolves with some useful properties.
fs.writeFileSync(marker, '');
return filePath;
};

var downloadArchive = function (url) {
// validate platform
var platform = os.platform();
if (platform != 'darwin' && platform != 'linux') {
throw new Error('Unexpected platform: ' + platform);
}

// validate parameters
var downloadArchiveAsync = async function (url, fileName) {
if (!url) {
throw new Error('Parameter "url" must be set.');
}

if (!url.match(/\.tar\.gz$/)) {
throw new Error('Expected .tar.gz');
// skip if already downloaded and extracted
var scrubbedUrl = url.replace(/[\/\\:?]/g, '_');
if (fileName !== undefined) {
scrubbedUrl = fileName;
}

// short-circuit if already downloaded and extracted
var scrubbedUrl = url.replace(/[/\:?]/g, '_');
var targetPath = path.join(downloadPath, 'archive', scrubbedUrl);
var marker = targetPath + '.completed';
if (!test('-f', marker)) {
// download the archive
var archivePath = downloadFile(url);
console.log('Extracting archive: ' + url);

// delete any previously attempted extraction directory
if (test('-d', targetPath)) {
rm('-rf', targetPath);
}

// extract
mkdir('-p', targetPath);
var cwd = process.cwd();
process.chdir(targetPath);
try {
run('tar -xzf "' + archivePath + '"');
}
finally {
process.chdir(cwd);
}

// write the completed marker
fs.writeFileSync(marker, '');
if (test('-f', marker)) {
return targetPath;
}

// download the archive
var archivePath = await downloadFileAsync(url, scrubbedUrl);
console.log('Extracting archive: ' + url);

// delete any previously attempted extraction directory
if (test('-d', targetPath)) {
rm('-rf', targetPath);
}

// extract
mkdir('-p', targetPath);
var zip = new admZip(archivePath);
zip.extractAllTo(targetPath);

// write the completed marker
fs.writeFileSync(marker, '');

return targetPath;
}
};


var addPath = function (directory) {
var separator;
Expand Down
14 changes: 12 additions & 2 deletions node/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ target.build = function() {
rm(path.join(buildPath, 'index.*'));
}

target.test = function() {
target.test = async function() {
target.build();

buildutils.getExternals();
await buildutils.getExternalsAsync();
run('tsc -p ./test');
cp('-Rf', rp('test/scripts'), testPath);
cp('-Rf', rp('test/fakeTasks'), testPath);
Expand All @@ -65,3 +65,13 @@ target.loc = function() {
var enContents = JSON.stringify(strings, null, 2);
fs.writeFileSync(path.join(strPath, 'resources.resjson'), enContents)
}

process.on('uncaughtException', err => {
console.error(`Uncaught exception: ${err.message}`);
console.debug(err.stack);
});

process.on('unhandledRejection', err => {
console.error(`Unhandled rejection: ${err.message}`);
console.debug(err.stack);
});
Loading

0 comments on commit 59c04b5

Please sign in to comment.