diff --git a/Build-tf b/Build-tf index 0bf57826..2ccea9ac 100644 --- a/Build-tf +++ b/Build-tf @@ -1,123 +1,148 @@ #!/usr/bin/env bash -set -xeu -set -o pipefail +IDENTITY="Apple Distribution: ITVIO, OOO (VL68C36HYS)" +P12_TMP_PATH="certs/distribution.p12" -export LANG=en_US.UTF-8 -LANG=en_US.UTF-8 +echo "🔑 Decoding certificate..." +echo "$CERTIFICATES_FILE_BASE64" | base64 --decode > "$P12_TMP_PATH" +ls -l "$P12_TMP_PATH" # Проверим размер и существование файла -function finish() { - if [[ -d "${RESULT_BUNDLE_PATH}" ]]; then - ditto -c -k --sequesterRsrc --keepParent "${RESULT_BUNDLE_PATH}" "${RESULT_BUNDLE_PATH}.zip" - rm -rf "${RESULT_BUNDLE_PATH}" - fi +echo "📦 Preparing certificate..." +mkdir -p certs +echo "$CERTIFICATES_FILE_BASE64" | base64 --decode > "$P12_TMP_PATH" + +echo "🔑 Importing .p12 certificate..." +security import "$P12_TMP_PATH" -k login.keychain -P "$CERTIFICATES_PASSWORD" -T /usr/bin/codesign || { + echo "❌ Failed to import .p12" + exit 1 } -trap finish EXIT +security set-key-partition-list -S apple-tool:,apple: -s -k "$CERTIFICATES_PASSWORD" login.keychain -SDK="${SDK:-iphoneos}" -WORKSPACE="${WORKSPACE:-ios/Runner.xcworkspace}" -SCHEME="${SCHEME:-Runner}" -CONFIGURATION="${CONFIGURATION:-Release}" - -BUILD_DIR="${BUILD_DIR:-build}" -ARTIFACT_PATH="${RESULT_PATH:-${BUILD_DIR}/Artifacts}" -RESULT_BUNDLE_PATH="${ARTIFACT_PATH}/${SCHEME}.xcresult" -ARCHIVE_PATH="${ARCHIVE_PATH:-${BUILD_DIR}/Archives/${SCHEME}.xcarchive}" -DERIVED_DATA_PATH="${DERIVED_DATA_PATH:-${BUILD_DIR}/DerivedData}" -CURRENT_PROJECT_VERSION="${BUILD_NUMBER:-0}" -EXPORT_OPTIONS_FILE="Support/ExportOptions.plist" - -# Clean and prepare the build -flutter clean -flutter pub get -dart run build_runner build --delete-conflicting-outputs - -cd ios -rm -rf Pods Podfile.lock -pod install --repo-update -pod update || { echo "Pod update failed"; exit 1; } -cd .. - -rm -rf "${RESULT_BUNDLE_PATH}" "${DERIVED_DATA_PATH}" -mkdir -p "${ARTIFACT_PATH}" - -function resign_frameworks() { - IDENTITY="Apple Distribution: ITVIO, OOO (VL68C36HYS)" - P12_TMP_PATH="certs/distribution.p12" - - echo "📦 Preparing certificate..." - mkdir -p certs - echo "$CERTIFICATES_FILE_BASE64" | base64 --decode > "$P12_TMP_PATH" - - echo "🔑 Importing .p12 certificate..." - security import "$P12_TMP_PATH" -k login.keychain -P "$CERTIFICATES_PASSWORD" -T /usr/bin/codesign || { - echo "❌ Failed to import .p12" - exit 1 - } - - security set-key-partition-list -S apple-tool:,apple: -s -k "$CERTIFICATES_PASSWORD" login.keychain - - # 🧾 Проверка, что identity доступен - if ! security find-identity -v -p codesigning | grep -q "${IDENTITY}"; then - echo "❌ Signing identity '${IDENTITY}' not found in keychain." - exit 1 - fi - - local app_path="${ARCHIVE_PATH}/Products/Applications/Runner.app" - local frameworks_path="${app_path}/Frameworks" - - echo "🔐 Removing old signatures..." - codesign --remove-signature "${frameworks_path}/App.framework/App" - codesign --remove-signature "${frameworks_path}/Flutter.framework/Flutter" - - echo "🔐 Resigning App.framework..." - codesign -f --deep --no-strict -s "${IDENTITY}" \ - --preserve-metadata=entitlements,identifier,flags \ - "${frameworks_path}/App.framework/App" - - echo "🔐 Resigning Flutter.framework..." - codesign -f --deep --no-strict -s "${IDENTITY}" \ - --preserve-metadata=entitlements,identifier,flags \ - "${frameworks_path}/Flutter.framework/Flutter" - - echo "🔐 Resigning Runner.app..." - codesign -f --deep --no-strict -s "${IDENTITY}" \ - --preserve-metadata=entitlements,identifier,flags \ - "${app_path}" - - echo "✅ Resigning completed" -} - -# Archive the build -xcrun xcodebuild \ - -workspace "${WORKSPACE}" \ - -scheme "${SCHEME}" \ - -configuration "${CONFIGURATION}" \ - -sdk "${SDK}" \ - -parallelizeTargets \ - -showBuildTimingSummary \ - -derivedDataPath "${DERIVED_DATA_PATH}" \ - -archivePath "${ARCHIVE_PATH}" \ - -resultBundlePath "${RESULT_BUNDLE_PATH}" \ - -allowProvisioningUpdates \ - CURRENT_PROJECT_VERSION="${CURRENT_PROJECT_VERSION}" \ - CODE_SIGNING_ALLOWED=NO \ - DEVELOPMENT_TEAM=VL68C36HYS \ - archive || { echo "Xcode archive failed"; exit 1; } - -resign_frameworks - -# Export the build to .ipa -xcrun xcodebuild \ - -exportArchive \ - -exportOptionsPlist "${EXPORT_OPTIONS_FILE}" \ - -archivePath "${ARCHIVE_PATH}" \ - -exportPath "${ARTIFACT_PATH}/${SCHEME}.ipa" || { echo "Export to IPA failed"; exit 1; } - -# Zip the archive -if [[ -d "${ARCHIVE_PATH}" ]]; then - ditto -c -k --sequesterRsrc --keepParent "${ARCHIVE_PATH}" "${ARTIFACT_PATH}/${SCHEME}.xcarchive.zip" -else - echo "Archive directory not found, skipping zip." +# 🧾 Проверка, что identity доступен +if ! security find-identity -v -p codesigning | grep -q "${IDENTITY}"; then + echo "❌ Signing identity '${IDENTITY}' not found in keychain." + exit 1 fi + +#set -xeu +#set -o pipefail +# +#export LANG=en_US.UTF-8 +#LANG=en_US.UTF-8 +# +#function finish() { +# if [[ -d "${RESULT_BUNDLE_PATH}" ]]; then +# ditto -c -k --sequesterRsrc --keepParent "${RESULT_BUNDLE_PATH}" "${RESULT_BUNDLE_PATH}.zip" +# rm -rf "${RESULT_BUNDLE_PATH}" +# fi +#} +# +#trap finish EXIT +# +#SDK="${SDK:-iphoneos}" +#WORKSPACE="${WORKSPACE:-ios/Runner.xcworkspace}" +#SCHEME="${SCHEME:-Runner}" +#CONFIGURATION="${CONFIGURATION:-Release}" +# +#BUILD_DIR="${BUILD_DIR:-build}" +#ARTIFACT_PATH="${RESULT_PATH:-${BUILD_DIR}/Artifacts}" +#RESULT_BUNDLE_PATH="${ARTIFACT_PATH}/${SCHEME}.xcresult" +#ARCHIVE_PATH="${ARCHIVE_PATH:-${BUILD_DIR}/Archives/${SCHEME}.xcarchive}" +#DERIVED_DATA_PATH="${DERIVED_DATA_PATH:-${BUILD_DIR}/DerivedData}" +#CURRENT_PROJECT_VERSION="${BUILD_NUMBER:-0}" +#EXPORT_OPTIONS_FILE="Support/ExportOptions.plist" +# +## Clean and prepare the build +#flutter clean +#flutter pub get +#dart run build_runner build --delete-conflicting-outputs +# +#cd ios +#rm -rf Pods Podfile.lock +#pod install --repo-update +#pod update || { echo "Pod update failed"; exit 1; } +#cd .. +# +#rm -rf "${RESULT_BUNDLE_PATH}" "${DERIVED_DATA_PATH}" +#mkdir -p "${ARTIFACT_PATH}" +# +#function resign_frameworks() { +# IDENTITY="Apple Distribution: ITVIO, OOO (VL68C36HYS)" +# P12_TMP_PATH="certs/distribution.p12" +# +# echo "📦 Preparing certificate..." +# mkdir -p certs +# echo "$CERTIFICATES_FILE_BASE64" | base64 --decode > "$P12_TMP_PATH" +# +# echo "🔑 Importing .p12 certificate..." +# security import "$P12_TMP_PATH" -k login.keychain -P "$CERTIFICATES_PASSWORD" -T /usr/bin/codesign || { +# echo "❌ Failed to import .p12" +# exit 1 +# } +# +# security set-key-partition-list -S apple-tool:,apple: -s -k "$CERTIFICATES_PASSWORD" login.keychain +# +# # 🧾 Проверка, что identity доступен +# if ! security find-identity -v -p codesigning | grep -q "${IDENTITY}"; then +# echo "❌ Signing identity '${IDENTITY}' not found in keychain." +# exit 1 +# fi +# +# local app_path="${ARCHIVE_PATH}/Products/Applications/Runner.app" +# local frameworks_path="${app_path}/Frameworks" +# +# echo "🔐 Removing old signatures..." +# codesign --remove-signature "${frameworks_path}/App.framework/App" +# codesign --remove-signature "${frameworks_path}/Flutter.framework/Flutter" +# +# echo "🔐 Resigning App.framework..." +# codesign -f --deep --no-strict -s "${IDENTITY}" \ +# --preserve-metadata=entitlements,identifier,flags \ +# "${frameworks_path}/App.framework/App" +# +# echo "🔐 Resigning Flutter.framework..." +# codesign -f --deep --no-strict -s "${IDENTITY}" \ +# --preserve-metadata=entitlements,identifier,flags \ +# "${frameworks_path}/Flutter.framework/Flutter" +# +# echo "🔐 Resigning Runner.app..." +# codesign -f --deep --no-strict -s "${IDENTITY}" \ +# --preserve-metadata=entitlements,identifier,flags \ +# "${app_path}" +# +# echo "✅ Resigning completed" +#} +# +## Archive the build +#xcrun xcodebuild \ +# -workspace "${WORKSPACE}" \ +# -scheme "${SCHEME}" \ +# -configuration "${CONFIGURATION}" \ +# -sdk "${SDK}" \ +# -parallelizeTargets \ +# -showBuildTimingSummary \ +# -derivedDataPath "${DERIVED_DATA_PATH}" \ +# -archivePath "${ARCHIVE_PATH}" \ +# -resultBundlePath "${RESULT_BUNDLE_PATH}" \ +# -allowProvisioningUpdates \ +# CURRENT_PROJECT_VERSION="${CURRENT_PROJECT_VERSION}" \ +# CODE_SIGNING_ALLOWED=NO \ +# DEVELOPMENT_TEAM=VL68C36HYS \ +# archive || { echo "Xcode archive failed"; exit 1; } +# +#resign_frameworks +# +## Export the build to .ipa +#xcrun xcodebuild \ +# -exportArchive \ +# -exportOptionsPlist "${EXPORT_OPTIONS_FILE}" \ +# -archivePath "${ARCHIVE_PATH}" \ +# -exportPath "${ARTIFACT_PATH}/${SCHEME}.ipa" || { echo "Export to IPA failed"; exit 1; } +# +## Zip the archive +#if [[ -d "${ARCHIVE_PATH}" ]]; then +# ditto -c -k --sequesterRsrc --keepParent "${ARCHIVE_PATH}" "${ARTIFACT_PATH}/${SCHEME}.xcarchive.zip" +#else +# echo "Archive directory not found, skipping zip." +#fi