-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearchAndReplace.swift
64 lines (64 loc) · 2.13 KB
/
SearchAndReplace.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//import Foundation
//import SwiftCICDCore
//
//public struct SearchAndReplace: Action {
// public struct Output {
// let updatedFiles: [String]
// }
//
// let searchForAndReplaceWith: [String: String]
// let filePaths: [String]
//
// init(
// searchForAndReplaceWith: [String: String],
// filePaths: [String]
// ) {
// self.searchForAndReplaceWith = searchForAndReplaceWith
// self.filePaths = filePaths
// }
//
// public func run() async throws -> Output {
// var updatedFiles = [String]()
// for filePath in filePaths {
// try await updateFile(filePath) { (file: inout String) in
// for (occurrence, replacement) in searchForAndReplaceWith {
// if file.contains(occurrence) {
// file = file.replacingOccurrences(of: occurrence, with: replacement)
// updatedFiles.append(filePath)
// }
// }
// }
// }
// return Output(updatedFiles: updatedFiles)
// }
//
// public func cleanUp(error: Error?) async throws {
// // No-op. We're using the updateFile action which will automatically
// // clean up and revert any changes to the files.
// }
//}
//
//public extension Action {
// @discardableResult
// func searchForAndReplaceWith(
// _ replaceOccurrenceWith: [String: String],
// in filePaths: [String]
// ) async throws -> SearchAndReplace.Output {
// try await run(SearchAndReplace(
// searchForAndReplaceWith: replaceOccurrenceWith,
// filePaths: filePaths
// ))
// }
//
// @discardableResult
// func injectSecrets(
// byReplacingOccurrencesWithSecrets occurrencesAndSecrets: [String: Secret],
// in filePaths: [String]
// ) async throws -> SearchAndReplace.Output {
// let searchAndReplace = try await Dictionary(uniqueKeysWithValues: occurrencesAndSecrets.concurrentMap {
// try await ($0.key, $0.value.get().string)
// })
//
// return try await searchForAndReplaceWith(searchAndReplace, in: filePaths)
// }
//}