Skip to content
Open
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
42 changes: 37 additions & 5 deletions Tasks/CopyFilesV2/copyfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs = require('fs');
import path = require('path');
import tl = require('azure-pipelines-task-lib/task');
import { RetryOptions, RetryHelper } from './retrylogichelper';
import fastGlob from 'fast-glob';

/**
* Shows timestamp change operation results
Expand Down Expand Up @@ -105,12 +106,43 @@ async function main(): Promise<void> {
// normalize the source folder path. this is important for later in order to accurately
// determine the relative path of each found file (substring using sourceFolder.length).
sourceFolder = path.normalize(sourceFolder);
let allPaths: string[] = tl.find(sourceFolder, findOptions);
let sourceFolderPattern = sourceFolder.replace('[', '[[]'); // directories can have [] in them, and they have special meanings as a pattern, so escape them
let matchedPaths: string[] = tl.match(allPaths, contents, sourceFolderPattern); // default match options
let matchedFiles: string[] = filterOutDirectories(matchedPaths);
// Normalize patterns: if patterns were given as absolute rooted under sourceFolder, make them relative.
const globPatterns = contents.map(p => {
let pattern = p.trim();
if (!pattern) return pattern;
// If absolute and starts with sourceFolder, strip the prefix
if (path.isAbsolute(pattern) && pattern.startsWith(sourceFolder)) {
pattern = pattern.substring(sourceFolder.length).replace(/^[/\\]/, '');
}
// fast-glob handles forward slashes best
return pattern.split(path.sep).join('/');
}).filter(p => !!p);

// If no patterns, default to all files
if (globPatterns.length === 0) {
globPatterns.push('**/*');
}

tl.debug(`Using fast-glob with patterns: ${globPatterns.join(', ')}`);

// copy the files to the target folder
const fgOptions: fastGlob.Options = {
cwd: sourceFolder,
dot: true,
onlyFiles: true,
followSymbolicLinks: findOptions.followSymbolicLinks,
unique: true,
suppressErrors: true,
markDirectories: false,
};

let matchedFiles: string[] = [];
try {
const relFiles: string[] = await fastGlob(globPatterns, fgOptions);
matchedFiles = relFiles.map(r => path.join(sourceFolder, r));
} catch (e) {
tl.setResult(tl.TaskResult.Failed, `fast-glob failed: ${e}`);
return;
}
console.log(tl.loc('FoundNFiles', matchedFiles.length));

if (matchedFiles.length > 0) {
Expand Down
228 changes: 227 additions & 1 deletion Tasks/CopyFilesV2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Tasks/CopyFilesV2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"@types/node": "^20.11.0",
"@types/mocha": "^5.2.7",
"@types/uuid": "^8.3.0",
"azure-pipelines-task-lib": "^5.2.0"
"azure-pipelines-task-lib": "^5.2.0",
"fast-glob": "^3.3.2"
},
"devDependencies": {
"typescript": "5.1.6"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/CopyFilesV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 256,
"Minor": 257,
"Patch": 0
},
"releaseNotes": "Match pattern consistency.",
Expand Down