From 8f545d717013899823e5b266f99a88f8587d506c Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Mon, 13 Jan 2025 10:11:35 +0100 Subject: [PATCH] Update scripts --- .github/workflows/docc.yml | 2 +- package_version.sh | 13 ++ scripts/build.sh | 60 +++++---- scripts/build_platform.sh | 16 --- scripts/chmod.sh | 19 +++ scripts/docc.sh | 93 ++++++++++++-- scripts/framework.sh | 114 ++++++++++++++++++ scripts/git_default_branch.sh | 11 ++ scripts/package_name.sh | 18 +++ scripts/test.sh | 86 +++++++++---- scripts/test_platform.sh | 17 --- scripts/version.sh | 79 ++++++++++++ ...version_number_bump.sh => version_bump.sh} | 41 ++++++- scripts/version_create.sh | 58 --------- scripts/version_number.sh | 6 +- scripts/version_validate_git.sh | 22 +++- scripts/version_validate_project.sh | 45 ++++--- version_create.sh | 4 - 18 files changed, 530 insertions(+), 174 deletions(-) create mode 100755 package_version.sh delete mode 100755 scripts/build_platform.sh create mode 100755 scripts/chmod.sh mode change 100644 => 100755 scripts/docc.sh create mode 100755 scripts/framework.sh create mode 100755 scripts/git_default_branch.sh create mode 100755 scripts/package_name.sh delete mode 100755 scripts/test_platform.sh create mode 100755 scripts/version.sh rename scripts/{version_number_bump.sh => version_bump.sh} (54%) delete mode 100755 scripts/version_create.sh delete mode 100755 version_create.sh diff --git a/.github/workflows/docc.yml b/.github/workflows/docc.yml index f2a651b989..e69ca78db1 100644 --- a/.github/workflows/docc.yml +++ b/.github/workflows/docc.yml @@ -36,7 +36,7 @@ jobs: with: xcode-version: '16.0' - name: Build DocC - run: bash scripts/docc.sh ${{ github.event.repository.name }} + run: bash scripts/docc.sh ${{ github.event.repository.name }} iOS - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: diff --git a/package_version.sh b/package_version.sh new file mode 100755 index 0000000000..1750c55a57 --- /dev/null +++ b/package_version.sh @@ -0,0 +1,13 @@ +#!/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. + +NAME="KeyboardKit" +DEFAULT_BRANCH="master" +BRANCH=${1:-$DEFAULT_BRANCH} +SCRIPT="scripts/version.sh" +chmod +x $SCRIPT +bash $SCRIPT $NAME $BRANCH diff --git a/scripts/build.sh b/scripts/build.sh index 50e5ab5415..11aa13d9ae 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,47 +1,65 @@ #!/bin/bash # Documentation: -# This script builds a for all supported platforms. +# This script builds a for all provided . + +# Usage: +# build.sh [ default:iOS macOS tvOS watchOS xrOS] +# e.g. `bash scripts/build.sh MyTarget iOS macOS` # Exit immediately if a command exits with a non-zero status set -e # Verify that all required arguments are provided if [ $# -eq 0 ]; then - echo "Error: This script requires exactly one argument" - echo "Usage: $0 " + echo "Error: This script requires at least one argument" + echo "Usage: $0 [ default:iOS macOS tvOS watchOS xrOS]" + echo "For instance: $0 MyTarget iOS macOS" exit 1 fi -# Create local argument variables. +# Define argument variables TARGET=$1 -# Use the script folder to refer to other scripts. -FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -SCRIPT="$FOLDER/build_platform.sh" +# Remove TARGET from arguments list +shift -# Make the script executable -chmod +x $SCRIPT +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS macOS tvOS watchOS xrOS +fi +PLATFORMS=$@ -# A function that builds a specific platform +# A function that builds $TARGET for a specific platform build_platform() { - local platform=$1 - echo "Building for $platform..." - if ! bash $SCRIPT $TARGET $platform; then - echo "Failed to build $platform" + + # Define a local $PLATFORM variable + local PLATFORM=$1 + + # Build $TARGET for the $PLATFORM + echo "Building $TARGET for $PLATFORM..." + if ! xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM; then + echo "Failed to build $TARGET for $PLATFORM" return 1 fi - echo "Successfully built $platform" + + # Complete successfully + echo "Successfully built $TARGET for $PLATFORM" } -# Array of platforms to build -platforms=("iOS" "macOS" "tvOS" "watchOS" "xrOS") +# Start script +echo "" +echo "Building $TARGET for [$PLATFORMS]..." +echo "" -# Loop through platforms and build -for platform in "${platforms[@]}"; do - if ! build_platform "$platform"; then +# Loop through all platforms and call the build function +for PLATFORM in $PLATFORMS; do + if ! build_platform "$PLATFORM"; then exit 1 fi done -echo "All platforms built successfully!" +# Complete successfully +echo "" +echo "Building $TARGET completed successfully!" +echo "" \ No newline at end of file diff --git a/scripts/build_platform.sh b/scripts/build_platform.sh deleted file mode 100755 index c7750d371b..0000000000 --- a/scripts/build_platform.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# Documentation: -# This script builds a for a specific . - -# Verify that all required arguments are provided -if [ $# -ne 2 ]; then - echo "Error: This script requires exactly two arguments" - echo "Usage: $0 " - exit 1 -fi - -TARGET=$1 -PLATFORM=$2 - -xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM diff --git a/scripts/chmod.sh b/scripts/chmod.sh new file mode 100755 index 0000000000..430feb919e --- /dev/null +++ b/scripts/chmod.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Documentation: +# This script makes all scripts in this folder executable. + +# Usage: +# scripts_chmod.sh +# e.g. `bash scripts/chmod.sh` + +# Exit immediately if a command exits with a non-zero status +set -e + +# Use the script folder to refer to other scripts. +FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# Find all .sh files in the FOLDER except chmod.sh +find "$FOLDER" -name "*.sh" ! -name "chmod.sh" -type f | while read -r script; do + chmod +x "$script" +done diff --git a/scripts/docc.sh b/scripts/docc.sh old mode 100644 new mode 100755 index ef49d2be0e..41b825666c --- a/scripts/docc.sh +++ b/scripts/docc.sh @@ -1,26 +1,99 @@ #!/bin/bash # Documentation: -# This script build DocC for a . -# The documentation ends up in to .build/docs. +# This script builds DocC for a for all provided . +# The documentation ends up in to .build/docs-. + +# Usage: +# docc.sh [ default:iOS macOS tvOS watchOS xrOS] +# e.g. `bash scripts/docc.sh MyTarget iOS macOS` + +# Exit immediately if a command exits with a non-zero status +set -e # Verify that all required arguments are provided if [ $# -eq 0 ]; then - echo "Error: This script requires exactly one argument" - echo "Usage: $0 " + echo "Error: This script requires at least one argument" + echo "Usage: $0 [ default:iOS macOS tvOS watchOS xrOS]" + echo "For instance: $0 MyTarget iOS macOS" exit 1 fi +# Define argument variables TARGET=$1 TARGET_LOWERCASED=$(echo "$1" | tr '[:upper:]' '[:lower:]') +# Remove TARGET from arguments list +shift + +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS macOS tvOS watchOS xrOS +fi +PLATFORMS=$@ + +# Prepare the package for DocC swift package resolve; -xcodebuild docbuild -scheme $1 -derivedDataPath /tmp/docbuild -destination 'generic/platform=iOS'; +# A function that builds $TARGET for a specific platform +build_platform() { + + # Define a local $PLATFORM variable + local PLATFORM=$1 + + # Define the build folder name, based on the $PLATFORM + case $PLATFORM in + "iOS") + DEBUG_PATH="Debug-iphoneos" + ;; + "macOS") + DEBUG_PATH="Debug" + ;; + "tvOS") + DEBUG_PATH="Debug-appletvos" + ;; + "watchOS") + DEBUG_PATH="Debug-watchos" + ;; + "xrOS") + DEBUG_PATH="Debug-xros" + ;; + *) + echo "Error: Unsupported platform '$PLATFORM'" + exit 1 + ;; + esac + + # Build $TARGET docs for the $PLATFORM + echo "Building $TARGET docs for $PLATFORM..." + xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination 'generic/platform='$PLATFORM; + + # Transform docs for static hosting + $(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"; + + # Inject a root redirect script on the root page + echo "" > .build/docs-$PLATFORM/index.html; + + # Complete successfully + echo "Successfully built $TARGET docs for $PLATFORM" +} + +# Start script +echo "" +echo "Building $TARGET docs for [$PLATFORMS]..." +echo "" -$(xcrun --find docc) process-archive \ - transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/$1.doccarchive \ - --output-path .build/docs \ - --hosting-base-path "$TARGET"; +# Loop through all platforms and call the build function +for PLATFORM in $PLATFORMS; do + if ! build_platform "$PLATFORM"; then + exit 1 + fi +done -echo "" > .build/docs/index.html; +# Complete successfully +echo "" +echo "Building $TARGET docs completed successfully!" +echo "" diff --git a/scripts/framework.sh b/scripts/framework.sh new file mode 100755 index 0000000000..2b8f6bb03b --- /dev/null +++ b/scripts/framework.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +# Documentation: +# This script generates an XCFramework for a certain for all provided . + +# Important: +# This script doesn't work on packages, only on .xcproj projects that generate a framework. + +# Usage: +# framework.sh [ default:iOS macOS tvOS watchOS xrOS] +# e.g. `bash scripts/framework.sh MyTarget iOS macOS` + +# Exit immediately if a command exits with a non-zero status +set -e + +# Verify that all required arguments are provided +if [ $# -eq 0 ]; then + echo "Error: This script requires exactly one argument" + echo "Usage: $0 " + exit 1 +fi + +# Define argument variables +TARGET=$1 + +# Remove TARGET from arguments list +shift + +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS macOS tvOS watchOS xrOS +fi +PLATFORMS=$@ + +# Define local variables +BUILD_FOLDER=.build +BUILD_FOLDER_ARCHIVES=.build/framework_archives +BUILD_FILE=$BUILD_FOLDER/$TARGET.xcframework +BUILD_ZIP=$BUILD_FOLDER/$TARGET.zip + +# Start script +echo "" +echo "Building $TARGET XCFramework for [$PLATFORMS]..." +echo "" + +# Delete old builds +echo "Cleaning old builds..." +rm -rf $BUILD_ZIP +rm -rf $BUILD_FILE +rm -rf $BUILD_FOLDER_ARCHIVES + + +# Generate XCArchive files for all platforms +echo "Generating XCArchives..." + +# Initialize the xcframework command +XCFRAMEWORK_CMD="xcodebuild -create-xcframework" + +# Build iOS archives and append to the xcframework command +if [[ " ${PLATFORMS[@]} " =~ " iOS " ]]; then + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=iOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-iOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=iOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-iOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-iOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-iOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" +fi + +# Build iOS archive and append to the xcframework command +if [[ " ${PLATFORMS[@]} " =~ " macOS " ]]; then + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=macOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-macOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-macOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" +fi + +# Build tvOS archives and append to the xcframework command +if [[ " ${PLATFORMS[@]} " =~ " tvOS " ]]; then + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=tvOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=tvOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" +fi + +# Build watchOS archives and append to the xcframework command +if [[ " ${PLATFORMS[@]} " =~ " watchOS " ]]; then + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=watchOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=watchOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" +fi + +# Build xrOS archives and append to the xcframework command +if [[ " ${PLATFORMS[@]} " =~ " xrOS " ]]; then + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=xrOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=xrOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" + XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" +fi + +# Genererate XCFramework +echo "Generating XCFramework..." +XCFRAMEWORK_CMD+=" -output $BUILD_FILE" +eval "$XCFRAMEWORK_CMD" + +# Genererate iOS XCFramework zip +echo "Generating XCFramework zip..." +zip -r $BUILD_ZIP $BUILD_FILE +echo "" +echo "***** CHECKSUM *****" +swift package compute-checksum $BUILD_ZIP +echo "********************" +echo "" + +# Complete successfully +echo "" +echo "$TARGET XCFramework created successfully!" +echo "" \ No newline at end of file diff --git a/scripts/git_default_branch.sh b/scripts/git_default_branch.sh new file mode 100755 index 0000000000..b076512664 --- /dev/null +++ b/scripts/git_default_branch.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Documentation: +# This script echos the default git branch name. + +# Usage: +# git_default_branch.sh +# e.g. `bash scripts/git_default_branch.sh` + +BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') +echo $BRANCH diff --git a/scripts/package_name.sh b/scripts/package_name.sh new file mode 100755 index 0000000000..f2972a7af6 --- /dev/null +++ b/scripts/package_name.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ ! -f "Package.swift" ]; then + echo "Error: Package.swift not found in current directory" + exit 1 +fi + +# Using grep and sed to extract the package name +# 1. grep finds the line containing "name:" +# 2. sed extracts the text between quotes +package_name=$(grep -m 1 'name:.*"' Package.swift | sed -n 's/.*name:[[:space:]]*"\([^"]*\)".*/\1/p') + +if [ -z "$package_name" ]; then + echo "Error: Could not find package name in Package.swift" + exit 1 +else + echo "$package_name" +fi diff --git a/scripts/test.sh b/scripts/test.sh index 20f59db96c..d4f45b367a 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,47 +1,85 @@ #!/bin/bash # Documentation: -# This script tests a for all supported platforms. +# This script tests a for all provided . + +# Usage: +# test.sh [ default:iOS macOS tvOS watchOS xrOS] +# e.g. `bash scripts/test.sh MyTarget iOS macOS` # Exit immediately if a command exits with a non-zero status set -e # Verify that all required arguments are provided if [ $# -eq 0 ]; then - echo "Error: This script requires exactly one argument" - echo "Usage: $0 " + echo "Error: This script requires at least one argument" + echo "Usage: $0 [ default:iOS macOS tvOS watchOS xrOS]" + echo "For instance: $0 MyTarget iOS macOS" exit 1 fi -# Create local argument variables. +# Define argument variables TARGET=$1 -# Use the script folder to refer to other scripts. -FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -SCRIPT="$FOLDER/test_platform.sh" +# Remove TARGET from arguments list +shift -# Make the script executable -chmod +x $SCRIPT +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS macOS tvOS watchOS xrOS +fi +PLATFORMS=$@ -# A function that tests a specific platform +# Start script +echo "" +echo "Testing $TARGET for [$PLATFORMS]..." +echo "" + +# A function that tests $TARGET for a specific platform test_platform() { - local platform=$1 - echo "Testing for $platform..." - if ! bash $SCRIPT $TARGET $platform; then - echo "Failed to test $platform" - return 1 - fi - echo "Successfully tested $platform" -} -# Array of platforms to test -platforms=("platform=iOS_Simulator,name=iPhone_16") + # Define a local $PLATFORM variable + local PLATFORM="${1//_/ }" + + # Define the destination, based on the $PLATFORM + case $PLATFORM in + "iOS") + DESTINATION="platform=iOS Simulator,name=iPhone 16" + ;; + "macOS") + DESTINATION="platform=macOS" + ;; + "tvOS") + DESTINATION="platform=tvOS Simulator,name=Apple TV" + ;; + "watchOS") + DESTINATION="platform=watchOS Simulator,name=Apple Watch" + ;; + "xrOS") + DESTINATION="platform=xrOS Simulator,name=Apple Vision Pro" + ;; + *) + echo "Error: Unsupported platform '$PLATFORM'" + exit 1 + ;; + esac + + # Test $TARGET for the $DESTINATION + echo "Testing $TARGET for $PLATFORM..." + xcodebuild test -scheme $TARGET -derivedDataPath .build -destination "$DESTINATION" -enableCodeCoverage YES; + + # Complete successfully + echo "Successfully tested $TARGET for $PLATFORM" +} -# Loop through platforms and build -for platform in "${platforms[@]}"; do - if ! test_platform "$platform"; then +# Loop through all platforms and call the test function +for PLATFORM in $PLATFORMS; do + if ! test_platform "$PLATFORM"; then exit 1 fi done -echo "All platforms tested successfully!" +# Complete successfully +echo "" +echo "Testing $TARGET completed successfully!" +echo "" \ No newline at end of file diff --git a/scripts/test_platform.sh b/scripts/test_platform.sh deleted file mode 100755 index 5f241d5f9b..0000000000 --- a/scripts/test_platform.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Documentation: -# This script tests a for a specific platform. -# Use _ instead of spaces when passing in the . - -# Verify that all required arguments are provided -if [ $# -ne 2 ]; then - echo "Error: This script requires exactly two arguments" - echo "Usage: $0 " - exit 1 -fi - -TARGET=$1 -PLATFORM="${2//_/ }" - -xcodebuild test -scheme $TARGET -derivedDataPath .build -destination "$PLATFORM" -enableCodeCoverage YES; diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 0000000000..bd3aaf5edc --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# Documentation: +# This script creates a new version for the provided , git and . + +# Usage: +# version.sh [ default:iOS macOS tvOS watchOS xrOS]" +# e.g. `scripts/version.sh MyTarget master iOS macOS` + +# This script will: +# * Call version_validate_git.sh to validate the git repo. +# * Call version_validate_project 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 +set -e + +# Verify that all required arguments are provided +if [ $# -lt 2 ]; then + echo "Error: This script requires at least two arguments" + echo "Usage: $0 [ default:iOS macOS tvOS watchOS xrOS]" + echo "For instance: $0 MyTarget master iOS macOS" + exit 1 +fi + +# Define argument variables +TARGET=$1 +BRANCH=${2:-main} + +# Remove TARGET and BRANCH from arguments list +shift +shift + +# Read platform arguments or use default value +if [ $# -eq 0 ]; then + set -- iOS macOS tvOS watchOS xrOS +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_VERSION_BUMP="$FOLDER/version_bump.sh" + +# A function that run a certain script and checks for errors +run_script() { + local script="$1" + shift # Remove the first argument (the script path) + + if [ ! -f "$script" ]; then + echo "Error: Script not found: $script" + exit 1 + fi + + chmod +x "$script" + if ! "$script" "$@"; then + echo "Error: Script $script failed" + exit 1 + fi +} + +# Start script +echo "" +echo "Creating a new version for $TARGET on the $BRANCH branch..." +echo "" + +# Validate git and project +echo "Validating..." +run_script "$SCRIPT_VALIDATE_GIT" "$BRANCH" +run_script "$SCRIPT_VALIDATE_PROJECT" "$TARGET" + +# Bump version +echo "Bumping version..." +run_script "$SCRIPT_VERSION_BUMP" + +# Complete successfully +echo "" +echo "Version created successfully!" +echo "" diff --git a/scripts/version_number_bump.sh b/scripts/version_bump.sh similarity index 54% rename from scripts/version_number_bump.sh rename to scripts/version_bump.sh index 40eade9e1b..720860a956 100755 --- a/scripts/version_number_bump.sh +++ b/scripts/version_bump.sh @@ -2,17 +2,39 @@ # Documentation: # This script bumps the project version number. +# You can append --no-semver to disable semantic version validation. + +# Usage: +# version_bump.sh [--no-semver] +# e.g. `bash scripts/version_bump.sh` +# e.g. `bash scripts/version_bump.sh --no-semver` # Exit immediately if a command exits with a non-zero status set -e # Use the script folder to refer to other scripts. FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -SCRIPT="$FOLDER/version_number.sh" +SCRIPT_VERSION_NUMBER="$FOLDER/version_number.sh" -# Get the latest version -VERSION=$($SCRIPT) +# Parse --no-semver argument +VALIDATE_SEMVER=true +for arg in "$@"; do + case $arg in + --no-semver) + VALIDATE_SEMVER=false + shift # Remove --no-semver from processing + ;; + esac +done + +# Start script +echo "" +echo "Bumping version number..." +echo "" + +# Get the latest version +VERSION=$($SCRIPT_VERSION_NUMBER) if [ $? -ne 0 ]; then echo "Failed to get the latest version" exit 1 @@ -23,6 +45,10 @@ echo "The current version is: $VERSION" # Function to validate semver format, including optional -rc. suffix validate_semver() { + if [ "$VALIDATE_SEMVER" = false ]; then + return 0 + fi + if [[ $1 =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then return 0 else @@ -34,6 +60,7 @@ validate_semver() { while true; do read -p "Enter the new version number: " NEW_VERSION + # Validate the version number to ensure that it's a semver version if validate_semver "$NEW_VERSION"; then break else @@ -42,6 +69,12 @@ while true; do fi done +# Push the new tag git push -u origin HEAD git tag $NEW_VERSION -git push --tags \ No newline at end of file +git push --tags + +# Complete successfully +echo "" +echo "Version tag pushed successfully!" +echo "" diff --git a/scripts/version_create.sh b/scripts/version_create.sh deleted file mode 100755 index fcea0b1d19..0000000000 --- a/scripts/version_create.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Documentation: -# This script creates a new project version for the provided and . - -# Exit immediately if a command exits with a non-zero status -set -e - -# Verify that all required arguments are provided -if [ $# -ne 2 ]; then - echo "Error: This script requires exactly two arguments" - echo "Usage: $0 " - exit 1 -fi - -# Create local argument variables. -BUILD_TARGET="$1" -GIT_BRANCH="$2" - -# Use the script folder to refer to the platform script. -FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -VALIDATE_GIT="$FOLDER/version_validate_git.sh" -VALIDATE_PROJECT="$FOLDER/version_validate_project.sh" -VERSION_BUMP="$FOLDER/version_number_bump.sh" - -# A function that run a certain script and checks for errors -run_script() { - local script="$1" - shift # Remove the first argument (the script path) - - if [ ! -f "$script" ]; then - echo "Error: Script not found: $script" - exit 1 - fi - - chmod +x "$script" - if ! "$script" "$@"; then - echo "Error: Script $script failed" - exit 1 - fi -} - - -# Execute the pipeline steps -echo "Starting pipeline for BUILD_TARGET: $BUILD_TARGET, GIT_BRANCH: $GIT_BRANCH" - -echo "Validating Git..." -run_script "$VALIDATE_GIT" "$GIT_BRANCH" - -echo "Validating Project..." -run_script "$VALIDATE_PROJECT" "$BUILD_TARGET" - -echo "Bumping version..." -run_script "$VERSION_BUMP" - -echo "" -echo "Version created successfully!" -echo "" diff --git a/scripts/version_number.sh b/scripts/version_number.sh index 50a8ba497a..6c2bd14b9b 100755 --- a/scripts/version_number.sh +++ b/scripts/version_number.sh @@ -1,7 +1,11 @@ #!/bin/bash # Documentation: -# This script returns the latest semver project version. +# This script returns the latest project version. + +# Usage: +# version_number.sh +# e.g. `bash scripts/version_number.sh` # Exit immediately if a command exits with a non-zero status set -e diff --git a/scripts/version_validate_git.sh b/scripts/version_validate_git.sh index 50e4b815f8..8b7899c791 100755 --- a/scripts/version_validate_git.sh +++ b/scripts/version_validate_git.sh @@ -1,8 +1,16 @@ #!/bin/bash # Documentation: -# This script version validates the Git repository for a . -# The script will fail if there are uncommitted changes, or if the branch is incorrect. +# This script validates the Git repository for a . + +# Usage: +# version_validate_git.sh " +# e.g. `bash scripts/version_validate_git.sh master` + +# This script will: +# * Validate that the script is run within a git repository. +# * Validate that the git repository doesn't have any uncommitted changes. +# * Validate that the current git branch matches the provided one. # Exit immediately if a command exits with a non-zero status set -e @@ -29,6 +37,11 @@ if ! git diff-index --quiet HEAD --; then exit 1 fi +# Start script +echo "" +echo "Validating git repository..." +echo "" + # Verify that we're on the correct branch current_branch=$(git rev-parse --abbrev-ref HEAD) if [ "$current_branch" != "$BRANCH" ]; then @@ -37,5 +50,6 @@ if [ "$current_branch" != "$BRANCH" ]; then fi # The Git repository validation succeeded. -echo "Git repository successfully validated for branch ($1)." -exit 0 +echo "" +echo "Git repository validated successfully!" +echo "" diff --git a/scripts/version_validate_project.sh b/scripts/version_validate_project.sh index cc6a7c0f33..cd4299aecc 100755 --- a/scripts/version_validate_project.sh +++ b/scripts/version_validate_project.sh @@ -2,25 +2,40 @@ # Documentation: # This script validates the project for a . -# The script will fail if swiftlint fails, or if any build and test runner fails. + +# Usage: +# version_validate_project.sh [ default:iOS macOS tvOS watchOS xrOS]" +# e.g. `bash scripts/version_validate_project.sh iOS macOS` + +# This script will: +# * Validate that swiftlint passes. +# * Validate that all unit tests passes for all . # Exit immediately if a command exits with a non-zero status set -e -# Verify that all required arguments are provided +# Verify that all requires at least one argument" if [ $# -eq 0 ]; then - echo "Error: This script requires exactly one argument" - echo "Usage: $0 " + echo "Error: This script requires at least one argument" + echo "Usage: $0 [ default:iOS macOS tvOS watchOS xrOS]" exit 1 fi # Create local argument variables. TARGET=$1 +# Remove TARGET from arguments list +shift + +# Define platforms variable +if [ $# -eq 0 ]; then + set -- iOS macOS tvOS watchOS xrOS +fi +PLATFORMS=$@ + # Use the script folder to refer to other scripts. FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -BUILD="$FOLDER/build.sh" -TEST="$FOLDER/test.sh" +SCRIPT_TEST="$FOLDER/test.sh" # A function that run a certain script and checks for errors run_script() { @@ -39,18 +54,20 @@ run_script() { fi } -echo "Running SwiftLint" -if ! swiftlint; then - echo "Error: SwiftLint failed." - exit 1 -fi +# Start script +echo "" +echo "Validating project..." +echo "" -echo "Building..." -run_script "$BUILD" "$TARGET" +# Run SwiftLint +echo "Running SwiftLint" +swiftlint +# Run unit tests echo "Testing..." -run_script "$TEST" "$TARGET" +run_script "$SCRIPT_TEST" "$TARGET" "$PLATFORMS" +# Complete successfully echo "" echo "Project successfully validated!" echo "" \ No newline at end of file diff --git a/version_create.sh b/version_create.sh deleted file mode 100755 index 886603962f..0000000000 --- a/version_create.sh +++ /dev/null @@ -1,4 +0,0 @@ -SCRIPT="scripts/version_create.sh" -chmod +x $SCRIPT -chmod +x version_create.sh -bash $SCRIPT SwiftUIKit main