Skip to content

Commit

Permalink
Extend Deployment Capabilities (#86)
Browse files Browse the repository at this point in the history
A custom output folder path can now be passed when creating a deployment folder.
Needed for GitHub Pages integration.

Co-authored-by: John Mueller <[email protected]>
Co-authored-by: John Sundell <[email protected]>
  • Loading branch information
3 people authored May 26, 2020
1 parent 4de0583 commit 0e70285
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Sources/Publish/API/PublishingContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ public extension PublishingContext {
/// After that, all output files and folders will be copied into the new folder.
/// - Parameter prefix: What prefix to apply to the folder, typically
/// the name of the current deployment method.
/// - parameter outputFolderPath: Any specific subfolder path to copy the output to.
/// If `nil`, then the output will be copied to the deployment folder itself.
/// - Parameter configure: A closure used to configure the folder.
func createDeploymentFolder(
withPrefix prefix: String,
outputFolderPath: Path? = nil,
configure: (Folder) throws -> Void
) throws -> Folder {
let path = Path(prefix + "Deploy")
Expand All @@ -157,9 +160,15 @@ public extension PublishingContext {
)
}

var outputFolder = folder

if let outputFolderPath = outputFolderPath {
outputFolder = try folder.createSubfolder(at: outputFolderPath.string)
}

do {
try folders.output.subfolders.forEach { try $0.copy(to: folder) }
try folders.output.files.forEach { try $0.copy(to: folder) }
try folders.output.subfolders.forEach { try $0.copy(to: outputFolder) }
try folders.output.files.includingHidden.forEach { try $0.copy(to: outputFolder) }
return folder
} catch {
throw FileIOError(path: path, reason: .folderCreationFailed)
Expand Down
34 changes: 33 additions & 1 deletion Tests/PublishTests/Tests/DeploymentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ final class DeploymentTests: PublishTestCase {
XCTAssertTrue(infoMessage.contains("receive.denyCurrentBranch"))
XCTAssertTrue(infoMessage.contains("[remote rejected]"))
}

func testDeployingUsingCustomOutputFolder() throws {
let container = try Folder.createTemporary()

// First generate
try publishWebsite(in: container, using: [
.addMarkdownFiles(),
.generateHTML(withTheme: .foundation)
], content: [
"one/a.md": "Text"
])

// Then deploy
CommandLine.arguments.append("--deploy")

var outputFolder: Folder?

try publishWebsite(in: container, using: [
.deploy(using: DeploymentMethod(name: "Test") { context in
outputFolder = try context.createDeploymentFolder(
withPrefix: "Test",
outputFolderPath: "CustomOutput",
configure: { _ in }
)
})
])

let folder = try require(outputFolder)
let subfolder = try folder.subfolder(named: "CustomOutput")
XCTAssertTrue(subfolder.containsSubfolder(at: "one/a"))
}
}

extension DeploymentTests {
Expand All @@ -122,7 +153,8 @@ extension DeploymentTests {
("testDeploymentSkippedByDefault", testDeploymentSkippedByDefault),
("testGenerationStepsAndPluginsSkippedWhenDeploying", testGenerationStepsAndPluginsSkippedWhenDeploying),
("testGitDeploymentMethod", testGitDeploymentMethod),
("testGitDeploymentMethodWithError",testGitDeploymentMethodWithError)
("testGitDeploymentMethodWithError", testGitDeploymentMethodWithError),
("testDeployingUsingCustomOutputFolder", testDeployingUsingCustomOutputFolder)
]
}
}

0 comments on commit 0e70285

Please sign in to comment.