Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit b9b5474

Browse files
authored
add chmod plugin (#2)
1 parent 1c4b4fb commit b9b5474

File tree

8 files changed

+65
-4
lines changed

8 files changed

+65
-4
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ install-openapi:
3131

3232
run-clean:
3333
swift package --disable-sandbox run-clean
34+
35+
chmod:
36+
swift package --disable-sandbox run-chmod
3437

3538
server:
3639
swift package --disable-sandbox run-openapi-server

Package.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let package = Package(
1616
.plugin(name: "GenerateContributorsListPlugin", targets: ["GenerateContributorsListPlugin"]),
1717
.plugin(name: "InstallSwiftFormatPlugin", targets: ["InstallSwiftFormatPlugin"]),
1818
.plugin(name: "InstallSwiftOpenApiGeneratorPlugin", targets: ["InstallSwiftOpenApiGeneratorPlugin"]),
19+
.plugin(name: "RunChmodPlugin", targets: ["RunChmodPlugin"]),
1920
.plugin(name: "RunCleanPlugin", targets: ["RunCleanPlugin"]),
2021
.plugin(name: "RunOpenApiServerPlugin", targets: ["RunOpenApiServerPlugin"]),
2122
.plugin(name: "RunSwiftFormatPlugin", targets: ["RunSwiftFormatPlugin"]),
@@ -112,6 +113,16 @@ let package = Package(
112113
),
113114
dependencies: []
114115
),
116+
.plugin(
117+
name: "RunChmodPlugin",
118+
capability: .command(
119+
intent: .custom(
120+
verb: "run-chmod",
121+
description: "runs run-chmod.sh"
122+
)
123+
),
124+
dependencies: []
125+
),
115126
.plugin(
116127
name: "RunCleanPlugin",
117128
capability: .command(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// File.swift
3+
//
4+
// Created by gerp83 on 21/06/2024
5+
//
6+
7+
import PackagePlugin
8+
9+
@main
10+
struct RunChmodPlugin: CommandPlugin {
11+
12+
func performCommand(
13+
context: PackagePlugin.PluginContext,
14+
arguments: [String]
15+
) async throws {
16+
try context.runScript(RunChmodScript())
17+
}
18+
19+
}

Plugins/RunChmodPlugin/Shared

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Shared

Plugins/Shared/ScriptEnum.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ enum ScriptEnum: String {
1717

1818
case directories = """
1919
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20-
chmod -R oug+x "${CURRENT_SCRIPT_DIR}"
2120
REPO_ROOT="$(git -C "$PWD" rev-parse --show-toplevel)"
2221
"""
2322

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// File.swift
3+
//
4+
// Created by gerp83 on 21/06/2024
5+
//
6+
7+
struct RunChmodScript: ScriptProtocol {
8+
9+
func shFile() -> String {
10+
return "run-chmod.sh"
11+
}
12+
13+
func scriptToRun() -> String {
14+
return """
15+
\(ScriptEnum.head.rawValue)
16+
\(ScriptEnum.log.rawValue)
17+
\(ScriptEnum.directories.rawValue)
18+
19+
chmod -R oug+x "${REPO_ROOT}/.build/plugins/"
20+
"""
21+
}
22+
23+
}

Plugins/Shared/scripts/RunSwiftFormatScript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct RunSwiftFormatScript: ScriptProtocol {
5656
if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then
5757
log "❌ Running swift-format produced errors."
5858
log "To fix, run the following command:"
59-
log "swift package run-swift-format --fix --disable-sandbox"
59+
log "swift package --disable-sandbox run-swift-format --fix"
6060
exit 1
6161
fi
6262
log "✅ Ran swift-format with no errors."

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This repository contains a set of Swift plugins designed to streamline various t
77
Add the repository as a dependency:
88

99
```swift
10-
.package(url: "https://github.com/BinaryBirds/swift-plugins", from: "0.0.1"),
10+
.package(url: "https://github.com/BinaryBirds/swift-plugins", from: "0.0.2"),
1111
```
1212

1313
Update the packages and you are ready.
@@ -61,13 +61,18 @@ Usage: `swift package --disable-sandbox install-swift-format`
6161
This plugin installs the Swift OpenAPI generator tool, the version can be optionally defined using the `-v` parameter.
6262

6363
Usage: `swift package --disable-sandbox install-swift-openapi-generator`
64+
65+
### RunChmodPlugin
66+
It runs `chmod` on the `.build/plugins` directory to make sure the Bash scripts are executable.
67+
68+
Usage: `swift package --disable-sandbox run-chmod`
6469

6570
### RunCleanPlugin
6671
This plugin cleans up build artifacts and other temporary files from the repository.
6772

6873
Usage: `swift package --disable-sandbox run-clean`
6974

70-
### RunOpenApiServerPlugin
75+
### RunOpenApiServerPlugin
7176
This plugin serves the OpenAPI documentation using an Nginx server.
7277

7378
Usage: `swift package --disable-sandbox run-openapi-server`

0 commit comments

Comments
 (0)