From 16f69042329dcc1458d52f7174b52ff9913bb36a Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Tue, 13 Jul 2021 18:48:28 -0700 Subject: [PATCH] [iOS] Packaging pipeline improvements. (#8324) Updates to the iOS packaging pipeline: - Make it harder to overwrite package archives accidentally when uploading (fails if the archive already exists) - Only upload package archives for release builds - Some clean up --- .../apple/assemble_ios_packaging_artifacts.sh | 18 +++++---- .../mac-ios-packaging-pipeline.yml | 39 ++++++++++++------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh b/tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh index c43a9d89d3..3e9e114e79 100755 --- a/tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh +++ b/tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh @@ -6,7 +6,7 @@ set -e set -x -USAGE_TEXT="Usage: ${0} " +USAGE_TEXT="Usage: ${0} " abspath() { local INPUT_PATH=${1:?"Expected path as the first argument."} @@ -18,6 +18,7 @@ BINARIES_STAGING_DIR=$(abspath "${1:?${USAGE_TEXT}}") # staging directory for build artifacts (destination) ARTIFACTS_STAGING_DIR=$(abspath "${2:?${USAGE_TEXT}}") ORT_POD_VERSION=${3:?${USAGE_TEXT}} +SHOULD_UPLOAD_ARCHIVES=${4:?${USAGE_TEXT}} STORAGE_ACCOUNT_NAME="onnxruntimepackages" STORAGE_ACCOUNT_CONTAINER_NAME="ortmobilestore" @@ -34,13 +35,16 @@ assemble_and_upload_pod() { zip -r ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} * --exclude ${PODSPEC_BASENAME} cp ${PODSPEC_BASENAME} ${ARTIFACTS_STAGING_DIR}/${PODSPEC_BASENAME} - # upload the pod archive and set the podspec source to the pod archive URL - az storage blob upload \ - --account-name ${STORAGE_ACCOUNT_NAME} --container-name ${STORAGE_ACCOUNT_CONTAINER_NAME} \ - --file ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} --name ${POD_ARCHIVE_BASENAME} + if [[ "${SHOULD_UPLOAD_ARCHIVES}" == "true" ]]; then + # upload the pod archive and set the podspec source to the pod archive URL + az storage blob upload \ + --account-name ${STORAGE_ACCOUNT_NAME} --container-name ${STORAGE_ACCOUNT_CONTAINER_NAME} \ + --file ${ARTIFACTS_STAGING_DIR}/${POD_ARCHIVE_BASENAME} --name ${POD_ARCHIVE_BASENAME} \ + --if-none-match "*" - sed -i "" -e "s|file:///http_source_placeholder|${STORAGE_URL_PREFIX}/${POD_ARCHIVE_BASENAME}|" \ - ${ARTIFACTS_STAGING_DIR}/${PODSPEC_BASENAME} + sed -i "" -e "s|file:///http_source_placeholder|${STORAGE_URL_PREFIX}/${POD_ARCHIVE_BASENAME}|" \ + ${ARTIFACTS_STAGING_DIR}/${PODSPEC_BASENAME} + fi popd } diff --git a/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml index b2086976d9..cb780590dc 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ios-packaging-pipeline.yml @@ -32,13 +32,20 @@ jobs: VERSION="${BASE_VERSION}-dev" fi - echo "##vso[task.setvariable variable=ORT_POD_VERSION]${VERSION}" - echo "Version number: ${VERSION}" - displayName: "Set version number" + set_var() { + local VAR_NAME=${1:?} + local VAR_VALUE=${2:?} + echo "##vso[task.setvariable variable=${VAR_NAME}]${VAR_VALUE}" + echo "${VAR_NAME}: ${VAR_VALUE}" + } + + set_var "ORT_POD_VERSION" "${VERSION}" + set_var "ORT_SHOULD_UPLOAD_ARCHIVES" "${IS_RELEASE_BUILD}" + displayName: "Set variables" - script: | python tools/ci_build/github/apple/build_ios_framework.py \ - --build_dir $(Build.BinariesDirectory)/ios_framework \ + --build_dir "$(Build.BinariesDirectory)/ios_framework" \ --include_ops_by_config tools/ci_build/github/android/mobile_package.required_operators.config \ tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json displayName: "Build iOS framework" @@ -46,15 +53,15 @@ jobs: - script: | python tools/ci_build/github/apple/test_ios_packages.py \ --fail_if_cocoapods_missing \ - --c_framework_dir $(Build.BinariesDirectory)/ios_framework/framework_out + --c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" displayName: "Test iOS framework" - script: | python tools/ci_build/github/apple/c/assemble_c_pod_package.py \ - --staging-dir $(Build.BinariesDirectory)/staging/onnxruntime-mobile-c \ + --staging-dir "$(Build.BinariesDirectory)/staging/onnxruntime-mobile-c" \ --pod-version ${ORT_POD_VERSION} \ - --framework-info-file $(Build.BinariesDirectory)/ios_framework/framework_info.json \ - --framework-dir $(Build.BinariesDirectory)/ios_framework/framework_out/onnxruntime.framework + --framework-info-file "$(Build.BinariesDirectory)/ios_framework/framework_info.json" \ + --framework-dir "$(Build.BinariesDirectory)/ios_framework/framework_out/onnxruntime.framework" displayName: "Assemble onnxruntime-mobile-c pod files" - script: | @@ -64,14 +71,14 @@ jobs: - script: | python tools/ci_build/github/apple/objectivec/assemble_objc_pod_package.py \ - --staging-dir $(Build.BinariesDirectory)/staging/onnxruntime-mobile-objc \ + --staging-dir "$(Build.BinariesDirectory)/staging/onnxruntime-mobile-objc" \ --pod-version ${ORT_POD_VERSION} \ - --framework-info-file $(Build.BinariesDirectory)/ios_framework/framework_info.json + --framework-info-file "$(Build.BinariesDirectory)/ios_framework/framework_info.json" displayName: "Assemble onnxruntime-mobile-objc pod files" - script: | pod lib lint --verbose \ - --include-podspecs=$(Build.BinariesDirectory)/staging/onnxruntime-mobile-c/onnxruntime-mobile-c.podspec + --include-podspecs="$(Build.BinariesDirectory)/staging/onnxruntime-mobile-c/onnxruntime-mobile-c.podspec" workingDirectory: "$(Build.BinariesDirectory)/staging/onnxruntime-mobile-objc" displayName: "Check onnxruntime-mobile-objc pod" @@ -79,7 +86,7 @@ jobs: set -e gem install jazzy jazzy --config objectivec/docs/jazzy_config.yaml \ - --output $(Build.BinariesDirectory)/staging/objc_api_docs \ + --output "$(Build.BinariesDirectory)/staging/objc_api_docs" \ --module-version ${ORT_POD_VERSION} displayName: "Generate Objective-C API docs" @@ -89,9 +96,13 @@ jobs: scriptType: 'bash' scriptLocation: 'scriptPath' scriptPath: 'tools/ci_build/github/apple/assemble_ios_packaging_artifacts.sh' - arguments: '"$(Build.BinariesDirectory)/staging" "$(Build.ArtifactStagingDirectory)" "$(ORT_POD_VERSION)"' + arguments: >- + "$(Build.BinariesDirectory)/staging" + "$(Build.ArtifactStagingDirectory)" + "$(ORT_POD_VERSION)" + "$(ORT_SHOULD_UPLOAD_ARCHIVES)" displayName: "Assemble artifacts" - - publish: $(Build.ArtifactStagingDirectory) + - publish: "$(Build.ArtifactStagingDirectory)" artifact: ios_packaging_artifacts displayName: "Publish artifacts"