Skip to content

Commit

Permalink
Merge pull request #979 from rfennell/issue978-wiki-pdf-spaces
Browse files Browse the repository at this point in the history
Add quotes incase the exe path includes spaces
  • Loading branch information
rfennell authored Mar 18, 2021
2 parents 287ec9c + abbb41e commit db8c31b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 95 deletions.
30 changes: 20 additions & 10 deletions Extensions/WikiPDFExport/WikiPDFExportTask/src/ExportFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ export async function ExportPDF(
}
}

// add quotes in case of spaces
command = `"${command}"`;

var args = "";
if (wikiRootPath.length > 0) {
if (!fs.existsSync(`${wikiRootPath}`)) {
logError(`Cannot find wiki folder ${wikiRootPath}`);
return;
} else {
args += ` -p ${wikiRootPath}`;
args += ` -p "${wikiRootPath}"`;
}
}

Expand All @@ -81,7 +84,7 @@ export async function ExportPDF(
logError(`Cannot find the requested file ${singleFile} to export`);
return;
} else {
args += ` -s ${singleFile}`;
args += ` -s "${singleFile}"`;
}
} else {
if (!fs.existsSync(`${wikiRootPath}/.order`)) {
Expand All @@ -90,7 +93,7 @@ export async function ExportPDF(
}

if (outputFile.length > 0) {
args += ` -o ${outputFile}`;
args += ` -o "${outputFile}"`;
} else {
logError("No output file name provided");
return;
Expand Down Expand Up @@ -130,11 +133,12 @@ export async function ExportPDF(
export async function GetExePath (
overrideExePath,
workingFolder,
isWindows: boolean
) {
if (overrideExePath && overrideExePath.length > 0) {
if (fs.existsSync(overrideExePath)) {
logInfo(`Using the overrideExePath`);
return overrideExePath;
return `${overrideExePath}`;
} else {
logWarning(`Attempting to use the overrideExePath of ${overrideExePath} but cannot find the file`);
return "";
Expand All @@ -149,7 +153,13 @@ export async function GetExePath (
// This is a nasty solution but appears to work
await new Promise(resolve => setTimeout(resolve, 5000));

return exeCmd;
if (!isWindows) {
// swap the slashes
exeCmd = exeCmd.replace(/\\/g, "/");
fs.chmodSync(exeCmd, 700);
}

return `${exeCmd}`;
}
}

Expand All @@ -170,13 +180,13 @@ export async function ExportRun (
) {

if (fs.existsSync(exeCmd)) {
logInfo(`Using the EXE path of ${exeCmd} for AzureDevOps.WikiPDFExport`);
logInfo(`Using the EXE path of '${exeCmd}' for AzureDevOps.WikiPDFExport`);
} else {
logError(`Cannot find the the AzureDevOps.WikiPDFExport tool in ${exeCmd}`);
logError(`Cannot find the AzureDevOps.WikiPDFExport tool in '${exeCmd}'`);
return;
}

if (cloneRepo) {
if (cloneRepo) {
console.log(`Cloning Repo`);
if (useAgentToken === true) {
console.log(`Using OAUTH Agent Token, overriding username and password`);
Expand All @@ -191,10 +201,10 @@ export async function ExportRun (
}

if (singleFile && singleFile.length > 0) {
console.log(`A filename ${singleFile} in the folder ${rootExportPath} has been requested so only processing that file `);
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(`Processing the contents of the folder ${rootExportPath} `);
console.log(`Processing the contents of the folder '${rootExportPath}' `);
ExportPDF (exeCmd, rootExportPath, "" , outputFile, extraParams, logInfo, logError);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ console.log(`Variable: OverrideExePath [${overrideExePath}]`);

GetExePath(
overrideExePath,
workingFolder
workingFolder,
tl.getVariable("AGENT.OS") === "Windows_NT"
).then((exePath) => {
if (exePath.length > 0) {
ExportRun(
Expand Down
19 changes: 12 additions & 7 deletions Extensions/WikiPDFExport/WikiPDFExportTask/test/getExe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import { GetExePath } from "../src/ExportFunctions";
const del = require("del");

describe("Get Exe Path ", () => {
it("should be able download the release", async () => {
var actual = await GetExePath("", ".\\testdata");
expect(actual).to.equal(".\\testdata\\azuredevops-export-wiki.exe");
it("should be able download the release on windows", async () => {
var actual = await GetExePath("", ".\\testdata", true);
expect(actual).to.equal(`.\\testdata\\azuredevops-export-wiki.exe`);
}).timeout(20000); // the default is 2000ms and that is too fast or the download

it("should be able download the release on non-windows", async () => {
var actual = await GetExePath("", ".\\testdata", false);
expect(actual).to.equal(`./testdata/azuredevops-export-wiki.exe`);
}).timeout(20000); // the default is 2000ms and that is too fast or the download

it("should be able to override the release download", async () => {
var actual = await GetExePath(".\\testdata\\dummy.exe.txt", "");
expect(actual).to.equal(".\\testdata\\dummy.exe.txt");
var actual = await GetExePath(".\\testdata\\dummy.exe.txt", "", true);
expect(actual).to.equal(`.\\testdata\\dummy.exe.txt`);
});

it("should be able to override the release download", async () => {
var actual = await GetExePath(".\\testdata\\dummy.exe.txt", "");
expect(actual).to.equal(".\\testdata\\dummy.exe.txt");
var actual = await GetExePath(".\\testdata\\dummy.exe.txt", "", true);
expect(actual).to.equal(`.\\testdata\\dummy.exe.txt`);
});

after(() => {
Expand Down
103 changes: 26 additions & 77 deletions Extensions/WikiPDFExport/azure-pipelines-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,90 +108,39 @@ stages:
- stage: Test
dependsOn: Private
jobs:
- deployment: Private_Tests
- deployment: Private_Tests_Windows
timeoutInMinutes: 0
environment: 'Azure DevOps Marketplace (WIKIPDFExport)'
pool:
name: default
# vmImage: '$(vmImage)'
# name: default
vmImage: 'windows-latest'
strategy:
runOnce:
deploy:
steps:
- checkout: VSTSBuildTaskValidation
clean: false
fetchDepth: 0
lfs: false

- task: richardfennellBM.BM-VSTS-XplatGenerateReleaseNotes-DEV1.XplatGenerate-Release-Notes.XplatGenerateReleaseNotes@2
displayName: 'Generate Release Notes based on Release Comparision API'
inputs:
outputfile: '$(System.DefaultWorkingDirectory)\inline.md'
outputVariableName: OutputText
templateLocation: InLine
inlinetemplate: |
# Release notes
**Build Number** : ${buildDetails.buildNumber}
**Build started** : ${buildDetails.startTime}
**Source Branch** : ${buildDetails.sourceBranch}
### Associated work items
@@WILOOP@@
* ** ${widetail.fields['System.WorkItemType']} ${widetail.id} ** Assigned by: ${widetail.fields['System.AssignedTo']} ${widetail.fields['System.Title']}
@@WILOOP@@
### Associated commits
@@CSLOOP@@
* **ID ${csdetail.commitId} ** ${csdetail.comment}
@@CSLOOP@@
- task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1
displayName: 'Export Single File'
inputs:
cloneRepo: false
localpath: '$(System.DefaultWorkingDirectory)'
singleFile: 'inline.md'
outputFile: '$(Build.ArtifactStagingDirectory)\PDF\singleFile.pdf'
- task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1
displayName: 'Export Public GitHub WIKI'
condition: succeededOrFailed()
inputs:
cloneRepo: true
repo: 'https://github.com/rfennell/AzurePipelines.wiki.git'
useAgentToken: false
localpath: '$(System.DefaultWorkingDirectory)\GitHubRepo'
outputFile: '$(Build.ArtifactStagingDirectory)\PDF\publicGitHub.pdf'
- task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1
displayName: 'Export Azure DevOps WIKI'
condition: succeededOrFailed()
inputs:
cloneRepo: true
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()
inputs:
cloneRepo: true
overrideExePath: '$(System.DefaultWorkingDirectory)/tools/azuredevops-export-wiki.exe'
repo: 'https://dev.azure.com/richardfennell/GitHub/_git/GitHub.wiki'
useAgentToken: true
outputFile: '$(Build.ArtifactStagingDirectory)\PDF\Azrepo-nodownload.pdf'
- task: PublishPipelineArtifact@0
condition: succeededOrFailed()
inputs:
artifactName: 'PDFs'
targetPath: '$(Build.ArtifactStagingDirectory)\PDF'
- template: test-stage.yml
- deployment: Private_Tests_Linux
condition: eq (1,2) # this is currently commented out as the AzureDevOps.WikiPDFExport.exe is not formally supported on this platform
timeoutInMinutes: 0
environment: 'Azure DevOps Marketplace (WIKIPDFExport)'
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- template: test-stage.yml
- deployment: Private_Tests_Mac
condition: eq (1,2) # this is currently commented out as the AzureDevOps.WikiPDFExport.exe is not formally supported on this platform
timeoutInMinutes: 0
environment: 'Azure DevOps Marketplace (WIKIPDFExport)'
pool:
vmImage: 'macOS-latest'
strategy:
runOnce:
deploy:
steps:
- template: test-stage.yml
- stage: Documentation
dependsOn: Test
pool:
Expand Down
75 changes: 75 additions & 0 deletions Extensions/WikiPDFExport/test-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
steps:
- checkout: VSTSBuildTaskValidation
clean: false
fetchDepth: 0
lfs: false

- task: richardfennellBM.BM-VSTS-XplatGenerateReleaseNotes-DEV1.XplatGenerate-Release-Notes.XplatGenerateReleaseNotes@2
displayName: 'Generate Release Notes based on Release Comparision API'
inputs:
outputfile: '$(System.DefaultWorkingDirectory)\inline.md'
outputVariableName: OutputText
templateLocation: InLine
inlinetemplate: |
# Release notes
**Build Number** : ${buildDetails.buildNumber}
**Build started** : ${buildDetails.startTime}
**Source Branch** : ${buildDetails.sourceBranch}
### Associated work items
@@WILOOP@@
* ** ${widetail.fields['System.WorkItemType']} ${widetail.id} ** Assigned by: ${widetail.fields['System.AssignedTo']} ${widetail.fields['System.Title']}
@@WILOOP@@
### Associated commits
@@CSLOOP@@
* **ID ${csdetail.commitId} ** ${csdetail.comment}
@@CSLOOP@@
- task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1
displayName: 'Export Single File'
inputs:
cloneRepo: false
localpath: '$(System.DefaultWorkingDirectory)'
singleFile: 'inline.md'
outputFile: '$(Build.ArtifactStagingDirectory)\PDF\singleFile.pdf'
- task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1
displayName: 'Export Public GitHub WIKI'
condition: succeededOrFailed()
inputs:
cloneRepo: true
repo: 'https://github.com/rfennell/AzurePipelines.wiki.git'
useAgentToken: false
localpath: '$(System.DefaultWorkingDirectory)\GitHubRepo'
outputFile: '$(Build.ArtifactStagingDirectory)\PDF\publicGitHub.pdf'
- task: richardfennellBM.BM-VSTS-WikiPDFExport-Tasks-DEV.WikiPDFExportTask.WikiPdfExportTask@1
displayName: 'Export Azure DevOps WIKI'
condition: succeededOrFailed()
inputs:
cloneRepo: true
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()
inputs:
cloneRepo: true
overrideExePath: '$(System.DefaultWorkingDirectory)/tools/azuredevops-export-wiki.exe'
repo: 'https://dev.azure.com/richardfennell/GitHub/_git/GitHub.wiki'
useAgentToken: true
outputFile: '$(Build.ArtifactStagingDirectory)\PDF\Azrepo-nodownload.pdf'
- task: PublishPipelineArtifact@0
condition: succeededOrFailed()
inputs:
artifactName: 'PDFs'
targetPath: '$(Build.ArtifactStagingDirectory)\PDF'

0 comments on commit db8c31b

Please sign in to comment.