Skip to content

Commit

Permalink
Make packager script less dependant of directory structure (#2214)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksproger authored Jul 10, 2024
1 parent b9c4b07 commit e44c39a
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 111 deletions.
36 changes: 36 additions & 0 deletions scripts/api-compatibility-check/dump_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -x
set -euo pipefail

# Define the parameters
OUTPUT=${1}
BASELINE=${2}
MAPBOX_MAPS_DIR=${3}
PACKAGE_MAPBOX_SCRIPT=${4}
BREAKING_API_CHECK_SCRIPT=${5}
MAPBOX_MAPS_VERSION_FILE=${6}
BINARY_OUTPUT=${7}

# Check if the output file exists and the baseline flag is true
if [[ -f "$OUTPUT" && "$BASELINE" == "true" ]]; then
echo "File $OUTPUT exists."
exit 0
fi

# Checkout the specific version if baseline is true
if [ "$BASELINE" == "true" ]; then
git checkout "$(cat "$MAPBOX_MAPS_VERSION_FILE")"
fi

PACKAGER_DIR="$MAPBOX_MAPS_DIR/scripts/release/packager"
"$PACKAGE_MAPBOX_SCRIPT" dynamic "$PACKAGER_DIR/versions.json" "$PACKAGER_DIR/create-xcframework.sh" "$PACKAGER_DIR/project.yml" "$MAPBOX_MAPS_DIR" "$MAPBOX_MAPS_DIR/LICENSE.md"
mv MapboxMaps*.zip "$MAPBOX_MAPS_DIR"

# Checkout back to the original branch if baseline is true
if [ "$BASELINE" == "true" ]; then
git checkout -
fi

# Run the API compatibility check script
"$BREAKING_API_CHECK_SCRIPT" dump "$MAPBOX_MAPS_DIR/MapboxMaps.zip" --module MapboxMaps -o "$OUTPUT"
mv "$MAPBOX_MAPS_DIR/MapboxMaps.zip" "$BINARY_OUTPUT"
20 changes: 0 additions & 20 deletions scripts/release/packager/PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,6 @@ zipped archive of XCFrameworks.
- Finally, it will zip that folder so everything will be in one bundle
- NOTE: This script **MUST** be called from this directory

### `download-dependency.sh`
- Usage:
```
./download-dependency.sh <SDK_REGISTRY_NAME> <SDK_REGISTRY_ARTIFACT> <VERSION>
```
- This script downloads `MapboxCoreMaps.xcframework` and `MapboxCommon.xcframework`
from SDK Registry
- NOTE: You **MUST** have a valid `.netrc` token

### `build-dependency.sh`

- Usage:
```
./build-dependency.sh <NAME> <GIT_REPO_URL> <GIT_TAG> <SCHEME>
```
- This script clones a given repository, checks out a `git tag`, and builds the specified `<SCHEME>`.
- Uses `xcodebuild`
- The `<NAME>` provided must match the name of the `.xcodeproj` and the base name of the resulting .framework product built in the `<SCHEME>`
- The `.xcodeproj` for the repository should be at the root of the repository.

### `create-xcframework.sh`

- Usage:
Expand Down
30 changes: 0 additions & 30 deletions scripts/release/packager/build-dependency.sh

This file was deleted.

10 changes: 6 additions & 4 deletions scripts/release/packager/create-xcframework.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

#!/usr/bin/env bash
set -x
set -euo pipefail

function step { >&2 echo -e "\033[1m\033[36m* $@\033[0m"; }
Expand All @@ -11,6 +11,8 @@ LINK_TYPE=${2}
SCHEME=${3:-"$PRODUCT"}
PROJECT=${4:-"$PRODUCT.xcodeproj"}
DSYM_NAMES=${5:-$PRODUCT}
MAPS_SDK_VERSION_FILE_PATH=${6}
OUTPUT_DIR=${7}

if [ "$LINK_TYPE" = "dynamic" ]; then
MACH_O_TYPE=mh_dylib
Expand Down Expand Up @@ -70,15 +72,15 @@ inject_build_info() {
plutil -insert "MBXBuildInfo.Git Branch" -string "$(git rev-parse --abbrev-ref HEAD)" "$plist_path"
plutil -insert "MBXBuildInfo.Swift version" -string "$(swift --version 2>&1 | grep -o "version .*" | cut -d ' ' -f2)" "$plist_path"
plutil -insert "MBXBuildInfo.Xcode version" -string "$(xcodebuild -version | head -n 1 | cut -d ' ' -f2)" "$plist_path"
plutil -insert "MBXBuildInfo.SDK version" -string "$(jq -r .version ../../../../Sources/MapboxMaps/MapboxMaps.json)" "$plist_path"
plutil -insert "MBXBuildInfo.SDK version" -string "$(jq -r .version "$MAPS_SDK_VERSION_FILE_PATH")" "$plist_path"

if [[ -n "${CIRCLE_BUILD_NUM:-}" ]]; then
echo "Injecting CI build info into info.plist"
plutil -insert "MBXBuildInfo.CI Build Number" -string "$CIRCLE_BUILD_NUM" "$plist_path"
fi
}

BUILD_XCFRAMEWORK_COMMAND="xcodebuild -create-xcframework -output '$PRODUCT.xcframework'"
BUILD_XCFRAMEWORK_COMMAND="xcodebuild -create-xcframework -output "$OUTPUT_DIR/$PRODUCT.xcframework""

BREAK=$'\n\t'
DEBUG_BREAK=$'\n\t\t'
Expand Down
29 changes: 0 additions & 29 deletions scripts/release/packager/download-dependency.sh

This file was deleted.

103 changes: 75 additions & 28 deletions scripts/release/packager/package-mapbox-maps.sh
Original file line number Diff line number Diff line change
@@ -1,68 +1,115 @@
#!/bin/bash

set -x
set -euo pipefail

function step { >&2 echo -e "\033[1m\033[36m* $@\033[0m"; }
function finish { >&2 echo -en "\033[0m"; }
trap finish EXIT

# Default values are set to facilitate local runs with the expectation that scriprt will be called from the packager directory.
LINK_TYPE=${1:-"dynamic"}
VERSIONS_JSON_PATH=$(realpath "${2:-"./versions.json"}")
CREATE_XCFRAMEWORK_SCRIPT=$(realpath "${3:-"./create-xcframework.sh"}")
XCODE_PROJECT_SPEC_PATH=$(realpath "${4:-"./project.yml"}")
MAPBOX_MAPS_DIR=$(realpath "${5:-"../../../../mapbox-maps-ios"}")
LICENSE_PATH=$(realpath "${6:-"../../../LICENSE.md"}")
ARCHIVE_OUTPUT_PATH=${7:-"MapboxMaps.zip"}

function build_from_git() {
local NAME=${1}
local GIT_REPO_URL=${2}
local VERSION=${3}
local LINK_TYPE=${4}
local SCHEME=${5}
local CREATE_XCFRAMEWORK_SCRIPT=${6}
local ARTIFACTS_DIR=${7}

step "Clone $GIT_REPO_URL"
git clone "$GIT_REPO_URL" "$ARTIFACTS_DIR/$NAME"

step "Checkout tag: $VERSION"
git -C "$ARTIFACTS_DIR/$NAME" checkout "$VERSION"

step "Build $NAME"
"$CREATE_XCFRAMEWORK_SCRIPT" "$NAME" "$LINK_TYPE" "$SCHEME" "$ARTIFACTS_DIR/$NAME/$NAME.xcodeproj" Turf "$MAPBOX_MAPS_DIR/Sources/MapboxMaps/MapboxMaps.json" "$ARTIFACTS_DIR"

step "Remove directory"
rm -rf "$ARTIFACTS_DIR/${NAME:?}"
}

function download_binary() {
local SDK_REGISTRY_NAME=${1}
local SDK_REGISTRY_ARTIFACT=${2}
local VERSION=${3}
local ARTIFACTS_DIR=${4}
local RELEASE_FOLDER="releases"

mkdir .download

if [[ ${VERSION} = *"SNAPSHOT"* ]]; then
RELEASE_FOLDER="snapshots"
fi

step "Download dependency at https://api.mapbox.com/downloads/v2/$SDK_REGISTRY_NAME/$RELEASE_FOLDER/ios/packages/$VERSION/$SDK_REGISTRY_ARTIFACT.zip"
curl -n "https://api.mapbox.com/downloads/v2/$SDK_REGISTRY_NAME/$RELEASE_FOLDER/ios/packages/$VERSION/$SDK_REGISTRY_ARTIFACT.zip" --output .download/tmp.zip

step "Unzipping $SDK_REGISTRY_ARTIFACT.zip ..."
unzip -q .download/tmp.zip -d .download
mv .download/*.xcframework "$ARTIFACTS_DIR"

rm -rf .download
}

step 'Reading from versions.json'
CORE_VERSION=$(jq -r '.MapboxCoreMaps' ./versions.json)
COMMON_VERSION=$(jq -r '.MapboxCommon' ./versions.json)
TURF_VERSION=$(jq -r '.Turf' ./versions.json)
CORE_VERSION=$(jq -r '.MapboxCoreMaps' "$VERSIONS_JSON_PATH")
COMMON_VERSION=$(jq -r '.MapboxCommon' "$VERSIONS_JSON_PATH")
TURF_VERSION=$(jq -r '.Turf' "$VERSIONS_JSON_PATH")

step 'Cleaning up dependencies directory'
rm -rf artifacts
mkdir artifacts
pushd artifacts
mkdir -p artifacts/.xcode

step 'Installing Dependencies'
if [ "$LINK_TYPE" = "dynamic" ]; then
echo "Creating dynamic framework."
COMMON_ARTIFACT=MapboxCommon
CORE_ARTIFACT=MapboxCoreMaps.xcframework-dynamic
ZIP_ARCHIVE_NAME="MapboxMaps.zip"
README_PATH=../README-dynamic.md
README_PATH="$MAPBOX_MAPS_DIR/scripts/release/README-dynamic.md"
elif [ "$LINK_TYPE" = "static" ]; then
echo "Creating static framework."
COMMON_ARTIFACT=MapboxCommon-static
CORE_ARTIFACT=MapboxCoreMaps.xcframework-static
ZIP_ARCHIVE_NAME="MapboxMaps-static.zip"
README_PATH=../README-static.md
README_PATH="$MAPBOX_MAPS_DIR/scripts/release/README-static.md"
else
echo "Error: Invalid link type: $LINK_TYPE"
echo "Usage: $0 [dynamic|static]"
exit 1
fi

../download-dependency.sh mapbox-common "$COMMON_ARTIFACT" "$COMMON_VERSION"
../download-dependency.sh mobile-maps-core "$CORE_ARTIFACT" "$CORE_VERSION"
../build-dependency.sh Turf 'https://github.com/mapbox/turf-swift.git' "v$TURF_VERSION" "$LINK_TYPE"
download_binary mapbox-common "$COMMON_ARTIFACT" "$COMMON_VERSION" artifacts
download_binary mobile-maps-core "$CORE_ARTIFACT" "$CORE_VERSION" artifacts
build_from_git "Turf" "https://github.com/mapbox/turf-swift.git" "v$TURF_VERSION" "$LINK_TYPE" "Turf" "$CREATE_XCFRAMEWORK_SCRIPT" artifacts

step 'Creating MapboxMaps.xcodeproj'
mkdir .xcode
cp ../project.yml .xcode/
pushd .xcode
ln -s ../../../../../../mapbox-maps-ios .
xcodegen
popd
cp "$XCODE_PROJECT_SPEC_PATH" artifacts/.xcode/

step 'Symlink MapboxMaps directory'
ln -s "$MAPBOX_MAPS_DIR" artifacts/.xcode
xcodegen --spec artifacts/.xcode/project.yml

step 'Building MapboxMaps.xcframework'
../create-xcframework.sh 'MapboxMaps' "$LINK_TYPE" 'MapboxMaps' ".xcode/MapboxMaps.xcodeproj" 'MapboxMaps'
"$CREATE_XCFRAMEWORK_SCRIPT" 'MapboxMaps' "$LINK_TYPE" 'MapboxMaps' "artifacts/.xcode/MapboxMaps.xcodeproj" "MapboxMaps" "$MAPBOX_MAPS_DIR/Sources/MapboxMaps/MapboxMaps.json" artifacts
rm -rf .xcode

popd

step 'Sign XCFrameworks'
SIGNEABLE_FRAMEWORKS=$(find artifacts -name '*.xcframework' -a -not -name 'MapboxCommon.xcframework')
codesign --timestamp -v --sign "Apple Distribution: Mapbox, Inc. (GJZR2MEM28)" $SIGNEABLE_FRAMEWORKS

codesign --timestamp -v --sign "Apple Distribution: Mapbox, Inc. (GJZR2MEM28)" "artifacts/Turf.xcframework" "artifacts/MapboxCoreMaps.xcframework" "artifacts/MapboxMaps.xcframework"

step 'Add License and README to bundle'
cp ../../../LICENSE.md artifacts/
cp "$LICENSE_PATH" artifacts/LICENSE.md
cp "$README_PATH" artifacts/README.md

step 'Zip Bundle'
zip -qyr "$ZIP_ARCHIVE_NAME" artifacts
zip -qyr "$ARCHIVE_OUTPUT_PATH" artifacts

step 'Delete Artifacts Directory'
rm -rf artifacts
rm -rf artifacts

0 comments on commit e44c39a

Please sign in to comment.