繁体   English   中英

GitHub 操作 IOS xcode QA/暂存和颁发证书和配置文件

[英]GitHub actions IOS xcode QA/Staging and issue with certificates and provisioning profile

我正在使用 xcode 11.3 对 IOS 使用 GitHub 动作。 我能够为开发环境构建、导出存档并推送到应用中心。 但是,我在 staging/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

如何为暂存(非开发或非生产环境)创建证书、配置文件? 请告知,如上所述,我如何解决分期/质量保证问题?

谢谢

我得到了同样的错误并且能够找出解决方案。 有很多事情可能会出错,所以我将添加几点可能会帮助您纠正问题:

  1. 开发人员与分发配置文件:存档 + 导出 + 部署需要不同的开发人员和分发配置文件。 xcodebuild 会自动选择正确的,但您必须为此创建 2 个不同的配置文件 + 2 个不同的证书。 必须为每个环境(QA、Staging、Prod 等)完成此过程。

总而言之,对于每个环境,将有 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 Developer Console -> Certificates, Identifiers & Profiles -> Profiles 中创建它们

确保您还设置了暂存(或其他)环境的标识符:com.app.staging 等。

  1. 在 XCode 中添加开发配置文件,并确保证书在直接使用 XCode 构建时有效。 然后在本地尝试您的脚本,然后将它们推送到 Github Actions。

  2. 有时Apple Developer 中的配置文件可能会失效(也许您在 XCode 中撤销或删除了证书等)。 这发生在我身上几次,所以一定要检查一切都是有效的。

  3. 解密后通过其 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 过程对我来说非常累,但主要的挑战是理解证书、配置文件和 KeyChain 访问的关系,以及它们是如何工作的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM