-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make packager script less dependant of directory structure (#2214)
- Loading branch information
1 parent
b9c4b07
commit e44c39a
Showing
6 changed files
with
117 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |