From b9b54745b9f0d5a0c3d373e564910c7447eea1ec Mon Sep 17 00:00:00 2001 From: Gabor Lengyel Date: Mon, 24 Jun 2024 11:07:03 +0200 Subject: [PATCH] add chmod plugin (#2) --- Makefile | 3 +++ Package.swift | 11 +++++++++ Plugins/RunChmodPlugin/RunChmodPlugin.swift | 19 +++++++++++++++ Plugins/RunChmodPlugin/Shared | 1 + Plugins/Shared/ScriptEnum.swift | 1 - Plugins/Shared/scripts/RunChmodScript.swift | 23 +++++++++++++++++++ .../Shared/scripts/RunSwiftFormatScript.swift | 2 +- README.md | 9 ++++++-- 8 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 Plugins/RunChmodPlugin/RunChmodPlugin.swift create mode 120000 Plugins/RunChmodPlugin/Shared create mode 100644 Plugins/Shared/scripts/RunChmodScript.swift diff --git a/Makefile b/Makefile index a82d15a..f27ee5e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/Package.swift b/Package.swift index 34f2e7c..49a9446 100644 --- a/Package.swift +++ b/Package.swift @@ -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"]), @@ -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( diff --git a/Plugins/RunChmodPlugin/RunChmodPlugin.swift b/Plugins/RunChmodPlugin/RunChmodPlugin.swift new file mode 100644 index 0000000..6feb449 --- /dev/null +++ b/Plugins/RunChmodPlugin/RunChmodPlugin.swift @@ -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()) + } + +} diff --git a/Plugins/RunChmodPlugin/Shared b/Plugins/RunChmodPlugin/Shared new file mode 120000 index 0000000..85e26c7 --- /dev/null +++ b/Plugins/RunChmodPlugin/Shared @@ -0,0 +1 @@ +../Shared \ No newline at end of file diff --git a/Plugins/Shared/ScriptEnum.swift b/Plugins/Shared/ScriptEnum.swift index dbf9e65..2fdda33 100644 --- a/Plugins/Shared/ScriptEnum.swift +++ b/Plugins/Shared/ScriptEnum.swift @@ -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)" """ diff --git a/Plugins/Shared/scripts/RunChmodScript.swift b/Plugins/Shared/scripts/RunChmodScript.swift new file mode 100644 index 0000000..197d3f1 --- /dev/null +++ b/Plugins/Shared/scripts/RunChmodScript.swift @@ -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/" + """ + } + +} diff --git a/Plugins/Shared/scripts/RunSwiftFormatScript.swift b/Plugins/Shared/scripts/RunSwiftFormatScript.swift index 6f4a888..1d0ba08 100644 --- a/Plugins/Shared/scripts/RunSwiftFormatScript.swift +++ b/Plugins/Shared/scripts/RunSwiftFormatScript.swift @@ -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." diff --git a/README.md b/README.md index 5a0294a..66748d0 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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`