Skip to content

Commit f69bb6f

Browse files
committed
Update package scripts
1 parent 2939769 commit f69bb6f

18 files changed

+299
-51
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Build Runner
55

66
on:
77
push:
8-
branches: ["master"]
8+
branches: ["main"]
99
pull_request:
10-
branches: ["master"]
10+
branches: ["main"]
1111

1212
jobs:
1313
build:
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v3
1717
- uses: maxim-lobanov/setup-xcode@v1
1818
with:
19-
xcode-version: '16.0'
19+
xcode-version: latest-stable
2020
- name: Build all platforms
2121
run: bash scripts/build.sh ${{ github.event.repository.name }}
2222
- name: Test iOS

.github/workflows/docc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: DocC Runner
66

77
on:
88
push:
9-
branches: ["master"]
9+
branches: ["main"]
1010

1111
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1212
permissions:
@@ -34,13 +34,13 @@ jobs:
3434
- name: Select Xcode version
3535
uses: maxim-lobanov/setup-xcode@v1
3636
with:
37-
xcode-version: '16.0'
37+
xcode-version: latest-stable
3838
- name: Build DocC
3939
run: bash scripts/docc.sh ${{ github.event.repository.name }}
4040
- name: Upload artifact
4141
uses: actions/upload-pages-artifact@v3
4242
with:
43-
path: '.build/docs'
43+
path: '.build/docs-iOS'
4444
- id: deployment
4545
name: Deploy to GitHub Pages
4646
uses: actions/deploy-pages@v4
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
# You can customize this to fit your project when you copy these scripts.
66
# You can pass in a custom branch if you don't want to use the default one.
77

8-
NAME="RichTextKit"
9-
DEFAULT_BRANCH="main"
10-
BRANCH=${1:-$DEFAULT_BRANCH}
11-
SCRIPT="scripts/version.sh"
8+
SCRIPT="scripts/package_version.sh"
129
chmod +x $SCRIPT
13-
bash $SCRIPT $NAME $BRANCH
10+
bash $SCRIPT

scripts/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Documentation:
44
# This script builds a <TARGET> for all provided <PLATFORMS>.
5+
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6+
# You can pass in a list of <PLATFORMS> if you want to customize the build.
57

68
# Usage:
79
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
@@ -62,4 +64,4 @@ done
6264
# Complete successfully
6365
echo ""
6466
echo "Building $TARGET completed successfully!"
65-
echo ""
67+
echo ""

scripts/chmod.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script makes all scripts in this folder executable.
5+
6+
# Usage:
7+
# scripts_chmod.sh
8+
# e.g. `bash scripts/chmod.sh`
9+
10+
# Exit immediately if a command exits with a non-zero status
11+
set -e
12+
13+
# Use the script folder to refer to other scripts.
14+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
15+
16+
# Find all .sh files in the FOLDER except chmod.sh
17+
find "$FOLDER" -name "*.sh" ! -name "chmod.sh" -type f | while read -r script; do
18+
chmod +x "$script"
19+
done

scripts/docc.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

33
# Documentation:
4-
# This script builds DocC for a <TARGET> for all provided <PLATFORMS>.
4+
# This script builds DocC for a <TARGET> and certain <PLATFORMS>.
5+
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6+
# You can pass in a list of <PLATFORMS> if you want to customize the build.
57
# The documentation ends up in to .build/docs-<PLATFORM>.
68

79
# Usage:
@@ -11,6 +13,9 @@
1113
# Exit immediately if a command exits with a non-zero status
1214
set -e
1315

16+
# Fail if any command in a pipeline fails
17+
set -o pipefail
18+
1419
# Verify that all required arguments are provided
1520
if [ $# -eq 0 ]; then
1621
echo "Error: This script requires at least one argument"
@@ -38,8 +43,9 @@ swift package resolve;
3843
# A function that builds $TARGET for a specific platform
3944
build_platform() {
4045

41-
# Define a local $PLATFORM variable
46+
# Define a local $PLATFORM variable and set an exit code
4247
local PLATFORM=$1
48+
local EXIT_CODE=0
4349

4450
# Define the build folder name, based on the $PLATFORM
4551
case $PLATFORM in
@@ -66,19 +72,26 @@ build_platform() {
6672

6773
# Build $TARGET docs for the $PLATFORM
6874
echo "Building $TARGET docs for $PLATFORM..."
69-
xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination 'generic/platform='$PLATFORM;
75+
if ! xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination "generic/platform=$PLATFORM"; then
76+
echo "Error: Failed to build documentation for $PLATFORM" >&2
77+
return 1
78+
fi
7079

7180
# Transform docs for static hosting
72-
$(xcrun --find docc) process-archive \
81+
if ! $(xcrun --find docc) process-archive \
7382
transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH/$TARGET.doccarchive \
7483
--output-path .build/docs-$PLATFORM \
75-
--hosting-base-path "$TARGET";
84+
--hosting-base-path "$TARGET"; then
85+
echo "Error: Failed to transform documentation for $PLATFORM" >&2
86+
return 1
87+
fi
7688

7789
# Inject a root redirect script on the root page
7890
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs-$PLATFORM/index.html;
7991

8092
# Complete successfully
8193
echo "Successfully built $TARGET docs for $PLATFORM"
94+
return 0
8295
}
8396

8497
# Start script

scripts/framework.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

33
# Documentation:
4-
# This script generates an XCFramework for a certain <TARGET> for all provided <PLATFORMS>.
4+
# This script builds DocC for a <TARGET> and certain <PLATFORMS>.
5+
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6+
# You can pass in a list of <PLATFORMS> if you want to customize the build.
57

68
# Important:
79
# This script doesn't work on packages, only on .xcproj projects that generate a framework.
@@ -111,4 +113,4 @@ echo ""
111113
# Complete successfully
112114
echo ""
113115
echo "$TARGET XCFramework created successfully!"
114-
echo ""
116+
echo ""

scripts/git_default_branch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script echos the default git branch name.
5+
6+
# Usage:
7+
# git_default_branch.sh
8+
# e.g. `bash scripts/git_default_branch.sh`
9+
10+
BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
11+
echo $BRANCH

scripts/package_docc.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script builds DocC documentation for `Package.swift`.
5+
# This script targets iOS by default, but you can pass in custom <PLATFORMS>.
6+
7+
# Usage:
8+
# package_docc.sh [<PLATFORMS> default:iOS]
9+
# e.g. `bash scripts/package_docc.sh iOS macOS`
10+
11+
# Exit immediately if a command exits with non-zero status
12+
set -e
13+
14+
# Use the script folder to refer to other scripts.
15+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
16+
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
17+
SCRIPT_DOCC="$FOLDER/docc.sh"
18+
19+
# Define platforms variable
20+
if [ $# -eq 0 ]; then
21+
set -- iOS
22+
fi
23+
PLATFORMS=$@
24+
25+
# Get package name
26+
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }
27+
28+
# Build package documentation
29+
bash $SCRIPT_DOCC $PACKAGE_NAME $PLATFORMS || { echo "DocC script failed"; exit 1; }

scripts/package_framework.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script generates an XCFramework for `Package.swift`.
5+
# This script targets iOS by default, but you can pass in custom <PLATFORMS>.
6+
7+
# Usage:
8+
# package_framework.sh [<PLATFORMS> default:iOS]
9+
# e.g. `bash scripts/package_framework.sh iOS macOS`
10+
11+
# Exit immediately if a command exits with non-zero status
12+
set -e
13+
14+
# Use the script folder to refer to other scripts.
15+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
16+
SCRIPT_PACKAGE_NAME="$FOLDER/package_name.sh"
17+
SCRIPT_FRAMEWORK="$FOLDER/framework.sh"
18+
19+
# Define platforms variable
20+
if [ $# -eq 0 ]; then
21+
set -- iOS
22+
fi
23+
PLATFORMS=$@
24+
25+
# Get package name
26+
PACKAGE_NAME=$("$SCRIPT_PACKAGE_NAME") || { echo "Failed to get package name"; exit 1; }
27+
28+
# Build package framework
29+
bash $SCRIPT_FRAMEWORK $PACKAGE_NAME $PLATFORMS

0 commit comments

Comments
 (0)