Search code examples
xcodegithubcocoapodsgithub-actions

How to install private pods with GitHub Actions?


I'm trying to install my dependencies on my workflow script. However, some are private pods, and it gives me this error when I try and do 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... results in this error: fatal: could not read Username for 'https://github.com': Device not configured even when i have my personal access token (secret) added.

Here's my full script:

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 }}

How can I install private pods with my workflow GitHub Actions script?

Note: I'm also trying to do this via an organisation.


Solution

  • You haven't provided the API token in the pod repo add https://github... command and most likely it fails due to that. Please add your personal API token to the github url like <token>@github.com. You can use secrets and env to do the same.

    Most likely the following should help pass the error you are encountering:

    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 }}
    

    The modified lines are:

                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 }}
    

    Make sure you define a secret POD_GITHUB_API_TOKEN with your personal access token.