From 0883c1831ba7a609aec4f51d61447413a63959f6 Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Mon, 20 Jan 2025 16:05:35 +0100 Subject: [PATCH] Update package scripts --- .../Buttons/StandardButtonType.swift | 6 ++++ package_version.sh | 11 +++---- scripts/build.sh | 4 ++- scripts/docc.sh | 23 ++++++++++--- scripts/framework.sh | 6 ++-- scripts/package_docc.sh | 29 ++++++++++++++++ scripts/package_framework.sh | 29 ++++++++++++++++ scripts/package_name.sh | 11 +++++++ scripts/package_version.sh | 28 ++++++++++++++++ scripts/sync_from.sh | 33 +++++++++++++++++++ scripts/version.sh | 10 +++--- scripts/version_validate_git.sh | 3 +- ..._project.sh => version_validate_target.sh} | 10 +++--- 13 files changed, 179 insertions(+), 24 deletions(-) create mode 100755 scripts/package_docc.sh create mode 100755 scripts/package_framework.sh create mode 100755 scripts/package_version.sh create mode 100755 scripts/sync_from.sh rename scripts/{version_validate_project.sh => version_validate_target.sh} (80%) diff --git a/Sources/SwiftUIKit/Buttons/StandardButtonType.swift b/Sources/SwiftUIKit/Buttons/StandardButtonType.swift index a9b557db12..28ce62a2a1 100644 --- a/Sources/SwiftUIKit/Buttons/StandardButtonType.swift +++ b/Sources/SwiftUIKit/Buttons/StandardButtonType.swift @@ -73,12 +73,14 @@ public extension ButtonType { } } + #if os(iOS) || os(macOS) var keyboardShortcut: KeyEquivalent? { switch self { case .search: "f" default: nil } } + #endif var keyboardShortcutModifier: EventModifiers? { switch self { @@ -124,6 +126,7 @@ public extension View { func keyboardShortcut( _ button: ButtonType ) -> some View { + #if os(iOS) || os(macOS) if let shortcut = button.keyboardShortcut { if let modifier = button.keyboardShortcutModifier { self.keyboardShortcut(shortcut, modifiers: modifier) @@ -133,6 +136,9 @@ public extension View { } else { self } + #else + self + #endif } } diff --git a/package_version.sh b/package_version.sh index ec270bbc3f..c0316d9899 100755 --- a/package_version.sh +++ b/package_version.sh @@ -1,13 +1,10 @@ #!/bin/bash # Documentation: -# This script creates a new project version for the current project. -# You can customize this to fit your project when you copy these scripts. -# You can pass in a custom branch if you don't want to use the default one. +# This script creates a new project version for the package. +# You can pass in a BRANCH to not use the default git branch. -NAME="SwiftUIKit" DEFAULT_BRANCH="main" BRANCH=${1:-$DEFAULT_BRANCH} -SCRIPT="scripts/version.sh" -chmod +x $SCRIPT -bash $SCRIPT $NAME $BRANCH +SCRIPT="scripts/package_version.sh" +chmod +x $SCRIPT && bash $SCRIPT $BRANCH diff --git a/scripts/build.sh b/scripts/build.sh index 11aa13d9ae..2a3a19038a 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,6 +2,8 @@ # Documentation: # This script builds a for all provided . +# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default. +# You can pass in a list of if you want to customize the build. # Usage: # build.sh [ default:iOS macOS tvOS watchOS xrOS] @@ -62,4 +64,4 @@ done # Complete successfully echo "" echo "Building $TARGET completed successfully!" -echo "" \ No newline at end of file +echo "" diff --git a/scripts/docc.sh b/scripts/docc.sh index 41b825666c..1b58f866c4 100755 --- a/scripts/docc.sh +++ b/scripts/docc.sh @@ -1,7 +1,9 @@ #!/bin/bash # Documentation: -# This script builds DocC for a for all provided . +# This script builds DocC for a and certain . +# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default. +# You can pass in a list of if you want to customize the build. # The documentation ends up in to .build/docs-. # Usage: @@ -11,6 +13,9 @@ # Exit immediately if a command exits with a non-zero status set -e +# Fail if any command in a pipeline fails +set -o pipefail + # Verify that all required arguments are provided if [ $# -eq 0 ]; then echo "Error: This script requires at least one argument" @@ -38,8 +43,9 @@ swift package resolve; # A function that builds $TARGET for a specific platform build_platform() { - # Define a local $PLATFORM variable + # Define a local $PLATFORM variable and set an exit code local PLATFORM=$1 + local EXIT_CODE=0 # Define the build folder name, based on the $PLATFORM case $PLATFORM in @@ -66,19 +72,26 @@ build_platform() { # Build $TARGET docs for the $PLATFORM echo "Building $TARGET docs for $PLATFORM..." - xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination 'generic/platform='$PLATFORM; + if ! xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination "generic/platform=$PLATFORM"; then + echo "Error: Failed to build documentation for $PLATFORM" >&2 + return 1 + fi # Transform docs for static hosting - $(xcrun --find docc) process-archive \ + if ! $(xcrun --find docc) process-archive \ transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH/$TARGET.doccarchive \ --output-path .build/docs-$PLATFORM \ - --hosting-base-path "$TARGET"; + --hosting-base-path "$TARGET"; then + echo "Error: Failed to transform documentation for $PLATFORM" >&2 + return 1 + fi # Inject a root redirect script on the root page echo "" > .build/docs-$PLATFORM/index.html; # Complete successfully echo "Successfully built $TARGET docs for $PLATFORM" + return 0 } # Start script diff --git a/scripts/framework.sh b/scripts/framework.sh index 2b8f6bb03b..fab9263506 100755 --- a/scripts/framework.sh +++ b/scripts/framework.sh @@ -1,7 +1,9 @@ #!/bin/bash # Documentation: -# This script generates an XCFramework for a certain for all provided . +# This script builds DocC for a and certain . +# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default. +# You can pass in a list of if you want to customize the build. # Important: # This script doesn't work on packages, only on .xcproj projects that generate a framework. @@ -111,4 +113,4 @@ echo "" # Complete successfully echo "" echo "$TARGET XCFramework created successfully!" -echo "" \ No newline at end of file +echo "" diff --git a/scripts/package_docc.sh b/scripts/package_docc.sh new file mode 100755 index 0000000000..30a343813e --- /dev/null +++ b/scripts/package_docc.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Documentation: +# This script builds DocC documentation for `Package.swift`. +# This script targets iOS by default, but you can pass in custom . + +# Usage: +# package_docc.sh [ default:iOS] +# e.g. `bash scripts/package_docc.sh iOS macOS` + +# Exit immediately if a command exits with non-zero status +set -e + +# Use the script folder to refer to other scripts. +FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh" +SCRIPT_DOCC="$FOLDER/docc.sh" + +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS +fi +PLATFORMS=$@ + +# Get package name +PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; } + +# Build package documentation +bash $SCRIPT_DOCC $PACKAGE_NAME $PLATFORMS || { echo "DocC script failed"; exit 1; } diff --git a/scripts/package_framework.sh b/scripts/package_framework.sh new file mode 100755 index 0000000000..1e9f711293 --- /dev/null +++ b/scripts/package_framework.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Documentation: +# This script generates an XCFramework for `Package.swift`. +# This script targets iOS by default, but you can pass in custom . + +# Usage: +# package_framework.sh [ default:iOS] +# e.g. `bash scripts/package_framework.sh iOS macOS` + +# Exit immediately if a command exits with non-zero status +set -e + +# Use the script folder to refer to other scripts. +FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh" +SCRIPT_FRAMEWORK="$FOLDER/framework.sh" + +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS +fi +PLATFORMS=$@ + +# Get package name +PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; } + +# Build package framework +bash $SCRIPT_FRAMEWORK $PACKAGE_NAME $PLATFORMS diff --git a/scripts/package_name.sh b/scripts/package_name.sh index f2972a7af6..2e750a5e7e 100755 --- a/scripts/package_name.sh +++ b/scripts/package_name.sh @@ -1,5 +1,16 @@ #!/bin/bash +# Documentation: +# This script finds the main target name in `Package.swift`. + +# Usage: +# package_name.sh +# e.g. `bash scripts/package_name.sh` + +# Exit immediately if a command exits with non-zero status +set -e + +# Check that a Package.swift file exists if [ ! -f "Package.swift" ]; then echo "Error: Package.swift not found in current directory" exit 1 diff --git a/scripts/package_version.sh b/scripts/package_version.sh new file mode 100755 index 0000000000..9f4cd8b990 --- /dev/null +++ b/scripts/package_version.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Documentation: +# This script creates a new version for `Package.swift`. +# You can pass in a to validate any non-main branch. + +# Usage: +# package_version.sh +# e.g. `bash scripts/package_version.sh master` + +# Exit immediately if a command exits with non-zero status +set -e + +# Use the script folder to refer to other scripts. +FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +SCRIPT_BRANCH_NAME="$FOLDER/git_default_branch.sh" +SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh" +SCRIPT_VERSION="$FOLDER/version.sh" + +# Get branch name +DEFAULT_BRANCH=$("$SCRIPT_BRANCH_NAME") || { echo "Failed to get branch name"; exit 1; } +BRANCH_NAME=${1:-$DEFAULT_BRANCH} + +# Get package name +PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; } + +# Build package version +bash $SCRIPT_VERSION $PACKAGE_NAME $BRANCH_NAME diff --git a/scripts/sync_from.sh b/scripts/sync_from.sh new file mode 100755 index 0000000000..5ebf1e6296 --- /dev/null +++ b/scripts/sync_from.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Documentation: +# This script syncs Swift Package Scripts from a . +# This script will overwrite the existing "scripts" folder. +# Only pass in the full path to a Swift Package Scripts root. + +# Usage: +# package_name.sh +# e.g. `bash sync_from.sh ../SwiftPackageScripts` + +# Define argument variables +SOURCE=$1 + +# Define variables +FOLDER="scripts/" +SOURCE_FOLDER="$SOURCE/$FOLDER" + +# Start script +echo "" +echo "Syncing scripts from $SOURCE_FOLDER..." +echo "" + +# Remove existing folder +rm -rf $FOLDER + +# Copy folder +cp -r "$SOURCE_FOLDER/" "$FOLDER/" + +# Complete successfully +echo "" +echo "Script syncing from $SOURCE_FOLDER completed successfully!" +echo "" diff --git a/scripts/version.sh b/scripts/version.sh index bd3aaf5edc..54ec6b2acc 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,7 +1,9 @@ #!/bin/bash # Documentation: -# This script creates a new version for the provided , git and . +# This script creates a new version for the provided and . +# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default. +# You can pass in a list of if you want to customize the build. # Usage: # version.sh [ default:iOS macOS tvOS watchOS xrOS]" @@ -9,7 +11,7 @@ # This script will: # * Call version_validate_git.sh to validate the git repo. -# * Call version_validate_project to run tests, swiftlint, etc. +# * Call version_validate_target to run tests, swiftlint, etc. # * Call version_bump.sh if all validation steps above passed. # Exit immediately if a command exits with a non-zero status @@ -39,7 +41,7 @@ fi # Use the script folder to refer to other scripts. FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" SCRIPT_VALIDATE_GIT="$FOLDER/version_validate_git.sh" -SCRIPT_VALIDATE_PROJECT="$FOLDER/version_validate_project.sh" +SCRIPT_VALIDATE_TARGET="$FOLDER/version_validate_target.sh" SCRIPT_VERSION_BUMP="$FOLDER/version_bump.sh" # A function that run a certain script and checks for errors @@ -67,7 +69,7 @@ echo "" # Validate git and project echo "Validating..." run_script "$SCRIPT_VALIDATE_GIT" "$BRANCH" -run_script "$SCRIPT_VALIDATE_PROJECT" "$TARGET" +run_script "$SCRIPT_VALIDATE_TARGET" "$TARGET" # Bump version echo "Bumping version..." diff --git a/scripts/version_validate_git.sh b/scripts/version_validate_git.sh index 8b7899c791..5aba411402 100755 --- a/scripts/version_validate_git.sh +++ b/scripts/version_validate_git.sh @@ -1,7 +1,8 @@ #!/bin/bash # Documentation: -# This script validates the Git repository for a . +# This script validates the Git repository for release. +# You can pass in a to validate any non-main branch. # Usage: # version_validate_git.sh " diff --git a/scripts/version_validate_project.sh b/scripts/version_validate_target.sh similarity index 80% rename from scripts/version_validate_project.sh rename to scripts/version_validate_target.sh index cd4299aecc..7287390580 100755 --- a/scripts/version_validate_project.sh +++ b/scripts/version_validate_target.sh @@ -1,11 +1,13 @@ #!/bin/bash # Documentation: -# This script validates the project for a . +# This script validates a for release. +# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default. +# You can pass in a list of if you want to customize the build. # Usage: -# version_validate_project.sh [ default:iOS macOS tvOS watchOS xrOS]" -# e.g. `bash scripts/version_validate_project.sh iOS macOS` +# version_validate_target.sh [ default:iOS macOS tvOS watchOS xrOS]" +# e.g. `bash scripts/version_validate_target.sh iOS macOS` # This script will: # * Validate that swiftlint passes. @@ -70,4 +72,4 @@ run_script "$SCRIPT_TEST" "$TARGET" "$PLATFORMS" # Complete successfully echo "" echo "Project successfully validated!" -echo "" \ No newline at end of file +echo ""