Skip to content

Commit 256b271

Browse files
committed
Fix caching not found, and 2 fixme marks
1 parent 9a30337 commit 256b271

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed
File renamed without changes.

Actions/SetUp/action.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ name: SetUp
22
runs:
33
using: composite
44
steps:
5-
- name: Setup Swift
5+
- name: "Setup Swift"
66
uses: swift-actions/setup-swift@v2
77
with:
88
swift-version: 5.10.0
99

10-
- name: Cache Packagge
11-
uses: actions/cache@v4
12-
with:
13-
path: |
14-
.build
15-
~/Library/Caches/org.swift.swiftpm/
16-
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
17-
restore-keys: |
18-
${{ runner.os }}-spm-
19-
2010
- name: "Setup Mint"
2111
uses: irgaly/setup-mint@v1
2212
with:
13+
mint-directory: ${{ github.action_path }}
2314
mint-executable-directory: "~/.mint/bin"
24-

Sources/YamlWriter/CLIYamlBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct CLIYamlBuilder {
3737
}
3838

3939
let name = String(describing: command)
40+
let repo = "Wei18/GitHubSwiftActions"
4041

4142
// Define the structure of the composite action
4243
let action: [String: Any] = [
@@ -48,12 +49,11 @@ struct CLIYamlBuilder {
4849
"steps": [
4950
[
5051
"name": "Setup Swift, Mint, Cache, etc.",
51-
"uses": "Wei18/GitHubSwiftActions/Actions/SetUp@main",
52+
"uses": "\(repo)/Actions/SetUp@main",
5253
],
5354
[
5455
"name": "Run \(name)",
55-
// FIXME: owner/repo
56-
"run": "~/.mint/bin/mint run Wei18/GitHubSwiftActions@main \(name)",
56+
"run": "~/.mint/bin/mint run \(repo)@main \(name)",
5757
"env": envDict,
5858
"shell": "bash",
5959
],

Sources/YamlWriter/FileBuilder.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import ArgumentParser
1111
struct FileBuilder {
1212
let content: String
1313
let commandName: String
14-
let basePath: String?
14+
let basePath: URL
1515
let file: String
1616

1717
/// Initializes the `FileBuilder` with the content to be written and the command name.
1818
///
1919
/// - Parameters:
2020
/// - content: The content (YAML) to be written to the file.
2121
/// - command: The ParsableCommand type to inspect.
22-
/// - basePath: Optional path to the base directory, such as the repo's root. If `nil`, defaults to current directory.
22+
/// - basePath: The path to the base directory.
2323
/// - file: Define the file path. (default: action.yml)
24-
init<T: ParsableCommand>(content: String, command: T.Type, basePath: String? = nil, file: String = "action.yml") {
24+
init<T: ParsableCommand>(content: String, command: T.Type, basePath: URL, file: String = "action.yml") {
2525
self.content = content
2626
self.commandName = String(describing: command)
2727
self.basePath = basePath
@@ -33,11 +33,10 @@ struct FileBuilder {
3333
/// - Returns: The path to the generated file.
3434
@discardableResult
3535
func build() throws -> String {
36-
// Use the base path if provided, otherwise use the current directory
37-
let rootPath = basePath ?? FileManager.default.currentDirectoryPath
38-
39-
// Define the path to the Actions directory
40-
let actionsPath = "\(rootPath)/Actions/\(commandName)"
36+
// Define the path to the action directory
37+
let actionsPath = basePath
38+
.appendingPathComponent(commandName)
39+
.path
4140

4241
// Create the directory structure if it doesn't exist
4342
try FileManager.default.createDirectory(atPath: actionsPath, withIntermediateDirectories: true)

Sources/YamlWriter/main.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by zwc on 2024/9/6.
66
//
77

8+
import Foundation
89
import ArgumentParser
910
import CommentCore
1011

@@ -22,22 +23,28 @@ struct YamlWriterCLI: ParsableCommand {
2223
command: command,
2324
description: "Runs the process of adding or updating a comment in a GitHub issue or pull request.")
2425

25-
// FIXME: basePath
2626
let actionPath = try FileBuilder(
2727
content: yaml,
2828
command: command,
29-
basePath: "/Users/zw/Documents/GitHub/GitHubSwiftActions"
30-
).build()
31-
32-
try FileBuilder(
33-
content: "Wei18/GitHubSwiftActions@main",
34-
command: command,
35-
basePath: "/Users/zw/Documents/GitHub/GitHubSwiftActions",
36-
file: "Mintfile"
29+
basePath: packDirectory().appendingPathComponent("Actions")
3730
).build()
3831

3932
print(actionPath)
4033
}
34+
35+
private func packDirectory(
36+
for file: StaticString = #file,
37+
anchorRepoPathComponent: String = "Sources"
38+
) -> URL {
39+
let packDirectory: URL = {
40+
var newValue = URL(fileURLWithPath: file.description, isDirectory: false)
41+
while newValue.lastPathComponent != anchorRepoPathComponent {
42+
newValue = newValue.deletingLastPathComponent()
43+
}
44+
return newValue.deletingLastPathComponent()
45+
}()
46+
return packDirectory
47+
}
4148
}
4249

4350
YamlWriterCLI.main()

0 commit comments

Comments
 (0)