[英]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.