如何使用 GitHub 操作安装私有 pods?

How to install private pods with GitHub Actions?

我正在尝试在我的工作流脚本上安装我的依赖项。但是,有些是私有的 pods,当我尝试 bundle exec pod install:

时出现此错误
Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs`
Cloning spec repo `keterauk` from `https://github.com/KeteraUK/Strive-Pod-Specs`
[!] Unable to add a source with url `https://github.com/KeteraUK/Strive-Pod-Specs` named `keterauk`.
You can try adding it manually in `/Users/runner/.cocoapods/repos` or via `pod repo add`.
##[error]Process completed with exit code 1.

pod repo add... 导致此错误:fatal: could not read Username for 'https://github.com': Device not configured 即使我添加了我的个人访问令牌(秘密)。

这是我的完整脚本:

name: Swift

on:
  push:
    branches: 
      - master
      - enhancement/*
      - develop
      - develop/*
      - release
      - release/*

jobs:
  test:
    name: Test
    runs-on: macOS-latest
    strategy:
      matrix:
        destination: ['platform=iOS Simulator,OS=13.3,name=iPhone 11']
        xcode: ['/Applications/Xcode_11.6.app/Contents/Developer']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
        with:
          token: ${{ secrets.STRIVE_ACTIONS_SECRET }} # PAT
      - name: Bundle Update
        run: gem install bundler:1.17.2
      - name: Bundle Install
        run: bundle install

# Currently fails here...
      - name: Specs Repo
        run: pod repo add Strive-Pod-Specs https://github.com/KeteraUK/Strive-Pod-Specs.git

      - name: Dependencies
        run: bundle exec pod install
        env:
          DEVELOPER_DIR: ${{ matrix.xcode }}
      - name: Build and test
        run: bundle exec fastlane scan --destination "${destination}" --scheme "CI"
        env:
          destination: ${{ matrix.destination }}
          DEVELOPER_DIR: ${{ matrix.xcode }}

如何使用我的工作流 GitHub 操作脚本安装私有 pods?

注意:我也在尝试通过一个组织来做到这一点。

您没有在 pod repo add https://github... 命令中提供 API 标记,很可能因此失败。请将您的个人 API 标记添加到 github url 中,例如 <token>@github.com。您可以使用 secretsenv 来做同样的事情。

以下很可能有助于解决您遇到的错误:

name: Swift

on:
  push:
    branches: 
      - master
      - enhancement/*
      - develop
      - develop/*
      - release
      - release/*

jobs:
  test:
    name: Test
    runs-on: macOS-latest
    strategy:
      matrix:
        destination: ['platform=iOS Simulator,OS=13.3,name=iPhone 11']
        xcode: ['/Applications/Xcode_11.6.app/Contents/Developer']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
        with:
          token: ${{ secrets.STRIVE_ACTIONS_SECRET }} # PAT
      - name: Bundle Update
        run: gem install bundler:1.17.2
      - name: Bundle Install
        run: bundle install

      - name: Specs Repo
        run: pod repo add Strive-Pod-Specs https://${POD_GITHUB_API_TOKEN}@github.com/KeteraUK/Strive-Pod-Specs.git
        env:
          POD_GITHUB_API_TOKEN: ${{ secrets.POD_GITHUB_API_TOKEN }}
      - name: Dependencies
        run: bundle exec pod install
        env:
          DEVELOPER_DIR: ${{ matrix.xcode }}
      - name: Build and test
        run: bundle exec fastlane scan --destination "${destination}" --scheme "CI"
        env:
          destination: ${{ matrix.destination }}
          DEVELOPER_DIR: ${{ matrix.xcode }}

修改后的行是:

            run: pod repo add Strive-Pod-Specs https://${POD_GITHUB_API_TOKEN}@github.com/KeteraUK/Strive-Pod-Specs.git
            env:
              POD_GITHUB_API_TOKEN: ${{ secrets.POD_GITHUB_API_TOKEN }}

确保使用您的个人访问令牌定义一个秘密 POD_GITHUB_API_TOKEN。

错误提示 git 需要您进行身份验证或授权。因此,您可以通过多种选择来实现这一目标。

第一个也是最推荐的选项是使用SSH而不是HTTPS。所以机器会自动使用密钥,不会询问您的用户名。和密码每次。所以 URL 就像:ssh://<user>@github.com/KeteraUK/Strive-Pod-Specs.git

第二个选项是硬编码git的用户名和密码。这是 NOT 推荐的,它非常不安全。 (但仍然是一种选择)Read this document for more description 所以 URL 就像 https://<user:pass>@github.com/KeteraUK/Strive-Pod-Specs.git

您的另一个选择 是设置一个辅助应用程序,在该过程中注入密码。您可能已经配置了一个,但 git 可能根本无法找到它。上面的文档页面也有关于这个选项的信息。您可以通过 git config --global credential.helper cache 全局缓存它或通过 git config credential.helper store

永久存储它

您需要将用户名和令牌添加到您的 pod repo add。通过示例检查下面的设置

Sample workflow with success run

Sample workflow code

 name: Swift

 on:
   push:
 jobs:
   test:
     name: Test
     runs-on: macOS-latest
     strategy:
       matrix:
         destination: ['platform=iOS Simulator,OS=13.3,name=iPhone 11']
         xcode: ['/Applications/Xcode_11.6.app/Contents/Developer']
     steps:
       - name: Checkout
         uses: actions/checkout@v1
         with:
           token: ${{ secrets.GITHUBTOKEN }}
       - name: Bundle Update
         run: gem install bundler:1.17.2
       - name: Bundle Install
         run: bundle install
       - name: Specs Repo
         run: pod repo add ColorMatchTabs https://meroware:${{ secrets.GITHUBTOKEN }}@github.com/meroware/ColorMatchTabs.git

注意:在这个例子中,我将 ColorMatchTabs 制作成一个私人仓库,这样我就可以为此设置一个管道。如果您有后续问题,请告诉我,但我认为这足以满足您的问题

Line that was edited that you care about

    pod repo add ColorMatchTabs https://meroware:${{ secrets.GITHUBTOKEN }}@github.com/meroware/ColorMatchTabs.git

此外,您不需要为所有机密创建环境变量。您可以直接在 运行 中使用它们。将它们添加到 env 的唯一原因是为了直接从 envs 中获取它们的操作或命令。