[英]How to install private pods with GitHub Actions?
我正在尝试在我的工作流脚本上安装我的依赖项。 但是,有些是私有 pod,当我尝试执行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
即使添加了个人访问令牌(秘密), 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 操作脚本安装私有 Pod?
注意:我也在尝试通过一个组织来做到这一点。
您尚未在pod repo add https://github...
命令中提供 API 令牌,并且很可能因此而失败。 请将您的个人 API 令牌添加到 github url 中,例如<token>@github.com
。 您可以使用secrets
和env
来做同样的事情。
很可能以下内容应该有助于传递您遇到的错误:
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 的用户名和密码。 不推荐这样做,而且非常不安全。 (但仍然是一个选项)阅读此文档以获取更多描述因此 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。 使用示例检查下面的设置
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 变成了一个私有仓库,以便我可以为此设置一个管道。 如果您有后续问题,请告诉我,但我认为这应该足以满足您的问题
pod repo add ColorMatchTabs https://meroware:${{ secrets.GITHUBTOKEN }}@github.com/meroware/ColorMatchTabs.git
此外,您无需为所有机密创建 env 变量。 您可以直接在运行中使用它们。 将它们添加到 env 的唯一原因是为了直接从 envs 获取它们的操作或命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.