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

Commit

Permalink
add chmod plugin (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
GErP83 authored Jun 24, 2024
1 parent 1c4b4fb commit b9b5474
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ install-openapi:

run-clean:
swift package --disable-sandbox run-clean

chmod:
swift package --disable-sandbox run-chmod

server:
swift package --disable-sandbox run-openapi-server
Expand Down
11 changes: 11 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let package = Package(
.plugin(name: "GenerateContributorsListPlugin", targets: ["GenerateContributorsListPlugin"]),
.plugin(name: "InstallSwiftFormatPlugin", targets: ["InstallSwiftFormatPlugin"]),
.plugin(name: "InstallSwiftOpenApiGeneratorPlugin", targets: ["InstallSwiftOpenApiGeneratorPlugin"]),
.plugin(name: "RunChmodPlugin", targets: ["RunChmodPlugin"]),
.plugin(name: "RunCleanPlugin", targets: ["RunCleanPlugin"]),
.plugin(name: "RunOpenApiServerPlugin", targets: ["RunOpenApiServerPlugin"]),
.plugin(name: "RunSwiftFormatPlugin", targets: ["RunSwiftFormatPlugin"]),
Expand Down Expand Up @@ -112,6 +113,16 @@ let package = Package(
),
dependencies: []
),
.plugin(
name: "RunChmodPlugin",
capability: .command(
intent: .custom(
verb: "run-chmod",
description: "runs run-chmod.sh"
)
),
dependencies: []
),
.plugin(
name: "RunCleanPlugin",
capability: .command(
Expand Down
19 changes: 19 additions & 0 deletions Plugins/RunChmodPlugin/RunChmodPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// File.swift
//
// Created by gerp83 on 21/06/2024
//

import PackagePlugin

@main
struct RunChmodPlugin: CommandPlugin {

func performCommand(
context: PackagePlugin.PluginContext,
arguments: [String]
) async throws {
try context.runScript(RunChmodScript())
}

}
1 change: 1 addition & 0 deletions Plugins/RunChmodPlugin/Shared
1 change: 0 additions & 1 deletion Plugins/Shared/ScriptEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum ScriptEnum: String {

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

Expand Down
23 changes: 23 additions & 0 deletions Plugins/Shared/scripts/RunChmodScript.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// File.swift
//
// Created by gerp83 on 21/06/2024
//

struct RunChmodScript: ScriptProtocol {

func shFile() -> String {
return "run-chmod.sh"
}

func scriptToRun() -> String {
return """
\(ScriptEnum.head.rawValue)
\(ScriptEnum.log.rawValue)
\(ScriptEnum.directories.rawValue)
chmod -R oug+x "${REPO_ROOT}/.build/plugins/"
"""
}

}
2 changes: 1 addition & 1 deletion Plugins/Shared/scripts/RunSwiftFormatScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct RunSwiftFormatScript: ScriptProtocol {
if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then
log "❌ Running swift-format produced errors."
log "To fix, run the following command:"
log "swift package run-swift-format --fix --disable-sandbox"
log "swift package --disable-sandbox run-swift-format --fix"
exit 1
fi
log "✅ Ran swift-format with no errors."
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This repository contains a set of Swift plugins designed to streamline various t
Add the repository as a dependency:

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

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

Usage: `swift package --disable-sandbox install-swift-openapi-generator`

### RunChmodPlugin
It runs `chmod` on the `.build/plugins` directory to make sure the Bash scripts are executable.

Usage: `swift package --disable-sandbox run-chmod`

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

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

### RunOpenApiServerPlugin
### RunOpenApiServerPlugin
This plugin serves the OpenAPI documentation using an Nginx server.

Usage: `swift package --disable-sandbox run-openapi-server`
Expand Down

0 comments on commit b9b5474

Please sign in to comment.