From 7aa29d666ed3ae6f996fd004774156e55574be75 Mon Sep 17 00:00:00 2001 From: Richard Fennell Date: Thu, 7 Jan 2021 18:28:01 +0000 Subject: [PATCH] Add support for partial export (#927) * Add support for partial export * Split the clone and the export filters --- .../WikiPDFExportTask/src/ExportFunctions.ts | 11 ++++++----- .../WikiPDFExportTask/src/WikiPDFExportTask.ts | 11 ++++++++++- .../WikiPDFExport/WikiPDFExportTask/task/task.json | 10 +++++++++- .../WikiPDFExportTask/test/testrunnerForSingleFile.ts | 4 +++- .../test/testrunnerForWikiWithNoClone.ts | 5 ++++- .../test/testrunnerToCloneFromAzureDevOps.ts | 4 +++- .../test/testrunnerToCloneFromGitHub.ts | 4 +++- Extensions/WikiPDFExport/azure-pipelines-build.yml | 10 ++++++++++ Extensions/WikiPDFExport/readme.md | 3 ++- 9 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/src/ExportFunctions.ts b/Extensions/WikiPDFExport/WikiPDFExportTask/src/ExportFunctions.ts index 007fb25f9..e2f2bc654 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/src/ExportFunctions.ts +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/src/ExportFunctions.ts @@ -165,7 +165,8 @@ export async function ExportRun ( user, password, injectExtraHeader, - branch + branch, + rootExportPath ) { if (fs.existsSync(exeCmd)) { @@ -190,10 +191,10 @@ export async function ExportRun ( } if (singleFile && singleFile.length > 0) { - console.log(`A filename ${singleFile} has been passed so only processing that file `); - ExportPDF (exeCmd, localpath, singleFile, outputFile, extraParams, logInfo, logError); + console.log(`A filename ${singleFile} in the folder ${rootExportPath} has been requested so only processing that file `); + ExportPDF (exeCmd, rootExportPath, singleFile, outputFile, extraParams, logInfo, logError); } else { - console.log(`No filename has been passed so cloning the repo `); - ExportPDF (exeCmd, localpath, "" , outputFile, extraParams, logInfo, logError); + console.log(`Processing the contents of the folder ${rootExportPath} `); + ExportPDF (exeCmd, rootExportPath, "" , outputFile, extraParams, logInfo, logError); } } \ No newline at end of file diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/src/WikiPDFExportTask.ts b/Extensions/WikiPDFExport/WikiPDFExportTask/src/WikiPDFExportTask.ts index d397ae7f2..26bde5fb1 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/src/WikiPDFExportTask.ts +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/src/WikiPDFExportTask.ts @@ -26,12 +26,20 @@ var injectExtraHeader = tl.getBoolInput("injectExtraHeader"); var cloneRepo = tl.getBoolInput("cloneRepo"); var overrideExePath = tl.getInput("overrideExePath"); var workingFolder = tl.getVariable("Agent.TempDirectory"); +var rootExportPath = tl.getInput("rootExportPath"); + +// make sure that we support older configs where these two parameter were a single setting +if (!rootExportPath) { + console.log(`Defaulting variable rootExportPath as not defined`); + rootExportPath = localpath; +} console.log(`Variable: Repo [${repo}]`); console.log(`Variable: Use Agent Token [${useAgentToken}]`); console.log(`Variable: Username [${user}]`); console.log(`Variable: Password [${password}]`); console.log(`Variable: LocalPath [${localpath}]`); +console.log(`Variable: rootExportPath [${rootExportPath}]`); console.log(`Variable: SingleFile [${singleFile}]`); console.log(`Variable: OutputFile [${outputFile}]`); console.log(`Variable: Branch [${branch}]`); @@ -55,7 +63,8 @@ GetExePath( user, password, injectExtraHeader, - branch + branch, + rootExportPath ); } else { logError(`Cannot find the 'azuredevops-export-wiki.exe' tool`); diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/task/task.json b/Extensions/WikiPDFExport/WikiPDFExportTask/task/task.json index 462db2989..4852cb505 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/task/task.json +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/task/task.json @@ -97,7 +97,15 @@ "label": "Local folder", "defaultValue": "$(System.DefaultWorkingDirectory)\\repo", "required": true, - "helpMarkDown": "The Path to clone the repo into, or the folder containing the single file to export" + "helpMarkDown": "The path to clone the repo into" + }, + { + "name": "rootExportPath", + "type": "string", + "label": "Local folder", + "defaultValue": "", + "required": false, + "helpMarkDown": "The path to the root of the cloned the repo if exporting the whole repo, a folder within the repo to export part of the repo or finally the folder containing a single file to export. For this final option the filename must be specified below" }, { "name": "outputFile", diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForSingleFile.ts b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForSingleFile.ts index 36dd4f82e..e53d176e5 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForSingleFile.ts +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForSingleFile.ts @@ -12,6 +12,7 @@ function logError (msg: string) { // const singleFile = `${__dirname}\\..\\..\\..\\readme.md`; const localpath = `C:\\projects\\github\\AzurePipelines.wiki`; +const rootExportPath = `C:\\projects\\github\\AzurePipelines.wiki`; const singleFile = `C:\\projects\\github\\AzurePipelines.wiki\\ArtifactDescription-Tasks.md`; const outputFile = "c:\\tmp\\test\\new\\output.pdf"; const injectExtraHeader = false; @@ -36,5 +37,6 @@ ExportRun( user, password, injectExtraHeader, - branch + branch, + rootExportPath ); diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForWikiWithNoClone.ts b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForWikiWithNoClone.ts index 510c54257..53ce15d3e 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForWikiWithNoClone.ts +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerForWikiWithNoClone.ts @@ -11,6 +11,8 @@ function logError (msg: string) { } const localpath = `${__dirname}\\..\\..\\..\\..\\..\\..\\AzurePipelines.wiki`; +const rootExportPath = `${__dirname}\\..\\..\\..\\..\\..\\..\\AzurePipelines.wiki`; + const outputFile = "c:\\tmp\\test\\output.pdf"; const injectExtraHeader = false; const singleFile = ""; @@ -35,5 +37,6 @@ ExportRun( user, password, injectExtraHeader, - branch + branch, + rootExportPath ); diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromAzureDevOps.ts b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromAzureDevOps.ts index 2a2769e3e..25efed620 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromAzureDevOps.ts +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromAzureDevOps.ts @@ -21,6 +21,7 @@ const password = ""; const repo = "dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki"; const localpath = "c:\\tmp\\test\\repo"; +const rootExportPath = "c:\\tmp\\test\\repo"; const injectExtraHeaders = false; const branch = ""; const protocol = "https"; @@ -44,5 +45,6 @@ ExportRun( user, password, injectExtraHeader, - branch + branch, + rootExportPath ); diff --git a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromGitHub.ts b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromGitHub.ts index 89a3dd66f..c4ea72dd6 100644 --- a/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromGitHub.ts +++ b/Extensions/WikiPDFExport/WikiPDFExportTask/test/testrunnerToCloneFromGitHub.ts @@ -17,6 +17,7 @@ const password = ""; const repo = "github.com/rfennell/demorepo.wiki"; const localpath = "c:\\tmp\\test\\repo"; +const rootExportPath = "c:\\tmp\\test\\repo"; const injectExtraHeaders = false; const branch = ""; const protocol = "https"; @@ -40,5 +41,6 @@ ExportRun( user, password, injectExtraHeader, - branch + branch, + rootExportPath ); diff --git a/Extensions/WikiPDFExport/azure-pipelines-build.yml b/Extensions/WikiPDFExport/azure-pipelines-build.yml index 661b0728e..6a4776037 100644 --- a/Extensions/WikiPDFExport/azure-pipelines-build.yml +++ b/Extensions/WikiPDFExport/azure-pipelines-build.yml @@ -168,6 +168,16 @@ stages: repo: 'https://dev.azure.com/richardfennell/GitHub/_git/GitHub.wiki' useAgentToken: true outputFile: '$(Build.ArtifactStagingDirectory)\PDF\Azrepo.pdf' + - task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1 + displayName: 'Export part of the Azure DevOps WIKI' + condition: succeededOrFailed() + inputs: + cloneRepo: true + repo: 'https://dev.azure.com/richardfennell/GitHub/_git/GitHub.wiki' + useAgentToken: true + outputFile: '$(Build.ArtifactStagingDirectory)\PDF\AzrepoFilter.pdf' + localpath: '$(System.DefaultWorkingDirectory)\repopartial' + rootExportPath: '$(System.DefaultWorkingDirectory)\repopartial\folder' - task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1 displayName: 'Export Azure DevOps WIKI without downloading tool' condition: succeededOrFailed() diff --git a/Extensions/WikiPDFExport/readme.md b/Extensions/WikiPDFExport/readme.md index 175742382..e192a75ba 100644 --- a/Extensions/WikiPDFExport/readme.md +++ b/Extensions/WikiPDFExport/readme.md @@ -18,7 +18,8 @@ __Note:__ If you see problems such as `Error: spawn git ENOENT` when cloning a r #### General - CloneRepo - a boolean flag whether to clone the repo or not - Repo - The repo URL to update e.g in the form **https://dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki** (see the URL section below as to how to find this URL) -- LocalPath - The Path to clone the repo into and hence the folder structure containing the file(s) to export +- LocalPath - The path to clone the repo into +- RootExportPath - The path to the root of the cloned the repo if exporting the whole repo, a folder within the repo to export part of the repo or finally the folder containing a single file to export. For this final option the filename must be specified below - SingleFile - Optional single file to export in the localPath folder e.g. page.md - ExtraParameters - Any optional extra as defined at [WikiPDFExport](https://github.com/MaxMelcher/AzureDevOps.WikiPDFExport/) you wish to pass to the command line tool - the task automatically managed the -p, -s, -c and -v parameters #### Git Clone Specific