How to clone private spec repo in CocoaPods within GitHub Actions?

Viewed 601

I have a private CocoaPods spec repo that my project relies on to run pod install.

I'm trying to automate my build process using GitHub Actions. However, since the spec repo is private, I'm having trouble getting access to it in this other project.

I have tried the following code:

      - name: Clone private-cocoapods-spec
        uses: actions/checkout@v2
        with:
          repository: fishcharlie/Private-CocoaPods-Spec
          ref: refs/heads/master
          # GitHub's personal access token with access to `my-organization/awesome-action`
          token: ${{ secrets.GH_ACCESS_TOKEN }}
          persist-credentials: false
          path: /Users/runner/.cocoapods/repos/private-cocoapods-spec

Sadly this produces the following error:

Repository path '/Users/runner/.cocoapods/repos/private-cocoapods-spec' is not under '/Users/runner/work/Project/Project'

I also tried the following based on this Stack Overflow answer:

      - name: Configure git
        env:
          TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
        run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

However this didn't work either and produced the following error:

Cloning spec repo `private-cocoapods-spec` from `git@github.com:fishcharlie/Private-CocoaPods-Spec.git`
[!] Unable to add a source with url `git@github.com:fishcharlie/Private-CocoaPods-Spec.git ` named `private-cocoapods-spec`.
You can try adding it manually in `/Users/runner/.cocoapods/repos` or via `pod repo add`.

I'm assuming this is because I'm trying to use SSH instead of HTTPS to authenticate.

What is the best method to achieve this and have access to my private cocoapods-spec so that my pod install command will succeed?

1 Answers

To avoid using credentials explicit, you can use git-credentials-store:

git config --global credential.helper store
echo "https://username:${{ secrets.TOKEN }}@github.com" > ~/.git-credentials

In Podfile and podspec I use only https:// links (without username/password). With git credentials configuration pod install is enough to get spec and pod repositories.

I built it on GitHub Actions here.

Using SSH is quite problematic - if you use deployment keys, it's not possible to distinguish which key should be used to spec/pod repo. The only way to do it is to change host in ~/.ssh/config. I think it's a wrong way, especially if you see how the configuration in podspec and podfile needs to be to make it working.

Related