GitHub操作IOS xcode QA/暂存以及证书和配置文件问题

nszi6y05  于 2022-11-26  发布在  Git
关注(0)|答案(2)|浏览(222)

我正在使用xcode 11.3为IOS使用GitHub操作。我可以为开发环境构建、导出存档并推送到应用中心。但是,我在暂存/QA环境中遇到错误。
如果我提供的证书和配置文件与我在staging/QA中用于开发环境的证书和配置文件相同,则在导出归档文件(构建成功)期间会出现错误:-

#Export Archives
##[error]Process completed with exit code 70.
Run xcodebuild -exportArchive -archivePath abc.xcarchive -exportPath abc.ipa -exportOptionsPlist ./abc/ExportOptions.plist          
2020-04-16 15:57:11.154 xcodebuild[7404:37990] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/abcStaging_2020-04-16_15-57-11.153.xcdistributionlogs'.
error: exportArchive: No profiles for 'com.abc.Staging' were found
** EXPORT FAILED **

Error Domain=IDEProfileLocatorErrorDomain Code=1 "No profiles for 'com.abc.Staging' were found" UserInfo={IDEDistributionIssueSeverity=3, NSLocalizedDescription=No profiles for 'com.abc.Staging' were found, NSLocalizedRecoverySuggestion=Xcode couldn't find any iOS Ad Hoc provisioning profiles matching 'com.abc.Staging'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.}

如果我在苹果开发者帐户中创建新证书(苹果发行版)和配置文件(临时发行版)。导出文件并转换文件,然后在GitHub操作中上传.p12.gpg和mobileprovision.gpg,我会在构建发生时收到错误:-

#Build archives
##[error]Process completed with exit code 65.
Run xcodebuild archive -workspace abc.xcworkspace -scheme abcStaging -archivePath abc.xcarchive
User defaults from command line:
    IDEArchivePathOverride = /Users/runner/runners/2.169.0/work/abcappIOS-v1.0/abcappIOS-v1.0/abc.xcarchive

note: Using new build system
note: Planning build
note: Constructing build description
error: No profiles for 'com.abc.Staging' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.abc.Staging'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'abc' from project 'abc')

** ARCHIVE FAILED **

##[error]Process completed with exit code 65.

我已在导出归档文件中提供-allowProvisioningUpdates作为参数,但错误仍然存在
下面是github操作的代码

name: Deploy iOS to App Center

on:
  push:
    branches: [ staging ]
  pull_request:
    branches: [ staging ]

jobs:
  build:
    runs-on: macOS-latest
    steps:
      - uses: actions/checkout@v1

      - name: Install gpg
        run: brew install gnupg

      - name: Switch XCode Version
        run: sudo xcode-select -s /Applications/Xcode_11.3.app

      - name: Setup provisioning profile
        run: |
          chmod +x ./.github/secrets/secrets.sh
          ./.github/secrets/secrets.sh
        env:
          IOS_PROFILE_KEY: ${{ secrets.ios_profile_key }}

      - name: Install Cocoapods
        run: gem install cocoapods

      - name: Install pod dependencies
        run: |
          pod install
        shell: bash

      - name: Build archive
        run: |
          xcodebuild archive -workspace abc.xcworkspace -scheme abcStaging -archivePath abc.xcarchive

      - name: Export Archive
        run: |
          xcodebuild -exportArchive -archivePath abc.xcarchive -exportPath abc.ipa -exportOptionsPlist ./abc/ExportOptions.plist -allowProvisioningUpdates

下面是shell脚本

#!/bin/sh
gpg --quiet --batch --yes --decrypt --passphrase="xxxx" --output ./.github/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxx.mobileprovision ./.github/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxx.mobileprovision.gpg

gpg --quiet --batch --yes --decrypt --passphrase="xxxx" --output ./.github/secrets/abc_Certificates.p12 ./.github/secrets/abc_Certificates.p12.gpg

mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles

cp ./.github/secrets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxx.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/xxxxx-xxxx-xxxx-xxxx-xxxxxxxx.mobileprovision

security create-keychain -p "" build.keychain
security import ./.github/secrets/abc_Certificates.p12 -t agg -k ~/Library/Keychains/build.keychain -P "xxxx" -A

security list-keychains -s ~/Library/Keychains/build.keychain
security default-keychain -s ~/Library/Keychains/build.keychain
security unlock-keychain -p "" ~/Library/Keychains/build.keychain
security set-keychain-settings -lut 1500 ~/Library/Keychains/build.keychain

security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "" ~/Library/Keychains/build.keychain

如何创建证书,为临时(非开发或非生产环境)配置文件?请告诉我,我如何解决上面提到的staging/qa问题?
谢谢

bfrts1fy

bfrts1fy1#

我得到了同样的错误,并能够找出解决方案。有很多事情可能会出错,所以我会添加几点,可能会帮助您纠正这个问题:
1.**开发者配置文件与分发配置文件:**存档+导出+部署需要不同的开发者配置文件和分发配置文件。xcodebuild将自动选择正确的配置文件,但您必须为此创建2个不同的配置文件+ 2个不同的证书。必须为每个环境(QA、登台、生产等)执行此过程。
总而言之,对于每个环境,将有2个配置文件和2个证书(证书可以重复使用,但配置文件不能重复使用,因为它们取决于您拥有的不同捆绑包的数量)。

error: No profiles for 'com.abc.Staging' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.abc.Staging'

上面的错误表明您从未为com.abc.Staging创建过配置文件,或者至少没有下载并将其添加到正确的位置。
您可以在Apple开发者控制台-〉证书、标识符和描述文件-〉描述文件中创建它们
确保还设置了临时(或其他)环境的标识符:com.应用程序.分段等
1.在XCode中添加开发Provision配置文件并确保直接使用XCode构建时证书有效。然后在本地尝试您的脚本,然后将它们推送到Github Actions。
1.有时Apple Developer中的配置文件可能会失效(可能您在XCode中撤销了配置文件或删除了证书等)。我有几次遇到过这种情况,因此请确保检查所有内容是否有效。
1.在解密后按UUID保存预配概要文件。我不确定这有多重要,但我还是继续使用了它。
代码如下:

for PROVISION in `ls ./*.mobileprovision`
do
  UUID=`/usr/libexec/PlistBuddy -c 'Print :UUID' /dev/stdin <<< $(security cms -D -i ./$PROVISION)`
  cp "./$PROVISION" "$HOME/Library/MobileDevice/Provisioning Profiles/$UUID.mobileprovision"
done

推理+示例代码来自本文:https://medium.com/@karaiskc/archive-and-export-ios-app-with-github-actions-b44f676e4bf9
CICD过程对我来说相当累人,但主要的挑战是理解证书、配置文件和密钥链访问的关系,以及它们是如何工作的。

4c8rllxm

4c8rllxm2#

我尝试使用base64时秘密保存的配置文件

- name: using profile
    run : |
      echo -n "$PROVISION_PROFILE_PROD" | base64 --decode > /tmp/build_pp.mobileprovision
      mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
      cp /tmp/build_pp.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles

其中/tmp/build_pp.mobileprovision解码文件64和$PROVISION_PROFILE_PROD = ${{ secrets.NAME_BASE64_VAR }}

相关问题