Skip to content

Commit 0e70285

Browse files
jhonatnjohn-muellerJohnSundell
authored
Extend Deployment Capabilities (#86)
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]>
1 parent 4de0583 commit 0e70285

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Sources/Publish/API/PublishingContext.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ public extension PublishingContext {
138138
/// After that, all output files and folders will be copied into the new folder.
139139
/// - Parameter prefix: What prefix to apply to the folder, typically
140140
/// the name of the current deployment method.
141+
/// - parameter outputFolderPath: Any specific subfolder path to copy the output to.
142+
/// If `nil`, then the output will be copied to the deployment folder itself.
141143
/// - Parameter configure: A closure used to configure the folder.
142144
func createDeploymentFolder(
143145
withPrefix prefix: String,
146+
outputFolderPath: Path? = nil,
144147
configure: (Folder) throws -> Void
145148
) throws -> Folder {
146149
let path = Path(prefix + "Deploy")
@@ -157,9 +160,15 @@ public extension PublishingContext {
157160
)
158161
}
159162

163+
var outputFolder = folder
164+
165+
if let outputFolderPath = outputFolderPath {
166+
outputFolder = try folder.createSubfolder(at: outputFolderPath.string)
167+
}
168+
160169
do {
161-
try folders.output.subfolders.forEach { try $0.copy(to: folder) }
162-
try folders.output.files.forEach { try $0.copy(to: folder) }
170+
try folders.output.subfolders.forEach { try $0.copy(to: outputFolder) }
171+
try folders.output.files.includingHidden.forEach { try $0.copy(to: outputFolder) }
163172
return folder
164173
} catch {
165174
throw FileIOError(path: path, reason: .folderCreationFailed)

Tests/PublishTests/Tests/DeploymentTests.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,37 @@ final class DeploymentTests: PublishTestCase {
114114
XCTAssertTrue(infoMessage.contains("receive.denyCurrentBranch"))
115115
XCTAssertTrue(infoMessage.contains("[remote rejected]"))
116116
}
117+
118+
func testDeployingUsingCustomOutputFolder() throws {
119+
let container = try Folder.createTemporary()
120+
121+
// First generate
122+
try publishWebsite(in: container, using: [
123+
.addMarkdownFiles(),
124+
.generateHTML(withTheme: .foundation)
125+
], content: [
126+
"one/a.md": "Text"
127+
])
128+
129+
// Then deploy
130+
CommandLine.arguments.append("--deploy")
131+
132+
var outputFolder: Folder?
133+
134+
try publishWebsite(in: container, using: [
135+
.deploy(using: DeploymentMethod(name: "Test") { context in
136+
outputFolder = try context.createDeploymentFolder(
137+
withPrefix: "Test",
138+
outputFolderPath: "CustomOutput",
139+
configure: { _ in }
140+
)
141+
})
142+
])
143+
144+
let folder = try require(outputFolder)
145+
let subfolder = try folder.subfolder(named: "CustomOutput")
146+
XCTAssertTrue(subfolder.containsSubfolder(at: "one/a"))
147+
}
117148
}
118149

119150
extension DeploymentTests {
@@ -122,7 +153,8 @@ extension DeploymentTests {
122153
("testDeploymentSkippedByDefault", testDeploymentSkippedByDefault),
123154
("testGenerationStepsAndPluginsSkippedWhenDeploying", testGenerationStepsAndPluginsSkippedWhenDeploying),
124155
("testGitDeploymentMethod", testGitDeploymentMethod),
125-
("testGitDeploymentMethodWithError",testGitDeploymentMethodWithError)
156+
("testGitDeploymentMethodWithError", testGitDeploymentMethodWithError),
157+
("testDeployingUsingCustomOutputFolder", testDeployingUsingCustomOutputFolder)
126158
]
127159
}
128160
}

0 commit comments

Comments
 (0)