Skip to content

Commit 02880ac

Browse files
authored
Merge pull request #118 from wei18/feat/wei/dependabot-mintfile
Feat dependabot-mintfile
2 parents 3f4505a + f3e147c commit 02880ac

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// MintfileBuilder.swift
3+
// GitHubRestAPISwiftOpenAPI
4+
//
5+
// Created by zwc on 2025/5/11.
6+
//
7+
8+
import Foundation
9+
10+
struct MintfileBuilder {
11+
12+
struct Dependency {
13+
let name: String
14+
let baseURL: String
15+
let path: String
16+
let version: String
17+
var urlString: String { "\(baseURL)/\(path)" }
18+
}
19+
20+
let dependencies = [
21+
Dependency(
22+
name: "Mint",
23+
baseURL: "https://github.com",
24+
path: "yonaskolb/Mint",
25+
version: "0.17.5"
26+
),
27+
Dependency(
28+
name: "swift-openapi-generator",
29+
baseURL: "https://github.com",
30+
path: "apple/swift-openapi-generator",
31+
version: "1.7.2"
32+
)
33+
]
34+
35+
func addVersionUpdatesManifests() {
36+
for dependency in dependencies {
37+
let manifestPath = ".github/dependabot-mintfile/manifest-\(dependency.name)"
38+
shell("mkdir -p \(manifestPath); swift package --package-path \(manifestPath) init --type empty")
39+
shell("mkdir -p \(manifestPath); swift package --package-path \(manifestPath) add-dependency \(dependency.urlString) --exact \(dependency.version)")
40+
}
41+
}
42+
43+
/// provided from ChatGPT
44+
func write(to path: String = "Mintfile") throws {
45+
var lines: [String] = []
46+
47+
for dependency in dependencies {
48+
let manifestPath = ".github/dependabot-mintfile/manifest-\(dependency.name)" + "/Package.swift"
49+
let contents = try String(contentsOfFile: manifestPath, encoding: .utf8)
50+
51+
let pattern = #"\.package\(url:\s*"(.*?)",\s*exact:\s*"(.*?)"\)"#
52+
let regex = try NSRegularExpression(pattern: pattern)
53+
54+
if let match = regex.firstMatch(in: contents, range: NSRange(contents.startIndex..., in: contents)),
55+
let versionRange = Range(match.range(at: 2), in: contents),
56+
let urlRange = Range(match.range(at: 1), in: contents) {
57+
58+
let version = String(contents[versionRange])
59+
let path = URL(string: String(contents[urlRange]))?
60+
.path
61+
.split(separator: "/")
62+
.joined(separator: "/")
63+
64+
if let path {
65+
lines.append("\(path)@\(version)")
66+
}
67+
}
68+
}
69+
let content = lines.joined(separator: "\n") + "\n"
70+
try content.write(toFile: path, atomically: true, encoding: .utf8)
71+
}
72+
73+
@discardableResult
74+
private func shell(_ command: String) -> Int32 {
75+
let task = Process()
76+
task.launchPath = "/bin/bash"
77+
task.arguments = ["-c", command]
78+
task.launch()
79+
task.waitUntilExit()
80+
return task.terminationStatus
81+
}
82+
}
83+
84+
// MintfileBuilder().addVersionUpdatesManifests()
85+
do {
86+
try MintfileBuilder().write()
87+
} catch {
88+
print(error)
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// swift-tools-version: 6.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "manifest-Mint",
8+
dependencies: [
9+
.package(url: "https://github.com/yonaskolb/Mint", exact: "0.17.5"),
10+
]
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// swift-tools-version: 6.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "manifest-swift-openapi-generator",
8+
dependencies: [
9+
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.7.2"),
10+
]
11+
)

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ updates:
1414
directory: "/"
1515
schedule:
1616
interval: "weekly"
17+
18+
- package-ecosystem: "swift"
19+
directories:
20+
- "/.github/dependabot-mintfile/**/"
21+
schedule:
22+
interval: "weekly"

.github/workflows/CI-Dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jobs:
2929
with:
3030
swift: ${{ matrix.swift }}
3131
os: ${{ matrix.os }}
32+
33+
- name: "Update Mintfile"
34+
run: |
35+
swift .github/dependabot-mintfile/MintfileBuilder.swift
36+
git add Mintfile
37+
3238
- name: "Sync code base"
3339
env:
3440
PR_URL: ${{ github.event.pull_request.html_url }}

0 commit comments

Comments
 (0)