Skip to content

Commit

Permalink
Merge pull request #8 from Automattic/add/known_hosts_fix
Browse files Browse the repository at this point in the history
Add a new `add_host_to_ssh_known_hosts` command
  • Loading branch information
AliSoftware authored Nov 5, 2021
2 parents 753c146 + 38ff9e5 commit 824d1b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions bin/add_host_to_ssh_known_hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eu

# Parameter can be just a host name, or a full http, https or git URL.
URL="${1:?You need to provide an URL as first parameter}"

# Use a RegEx to extract the $HOST. Match the optional `http://`, `https://` or `git@` at the start, then capture everything after that up to the next `/` or `:`.
[[ $URL =~ ^(https?://|git@)?([^/:]+) ]] && HOST=${BASH_REMATCH[2]}

echo "Adding ${HOST} to '~/.ssh/known_hosts'..."
for ip in $(dig @8.8.8.8 "${HOST}" +short); do ssh-keyscan "${HOST}",$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
7 changes: 2 additions & 5 deletions bin/install_swiftpm_dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
sudo defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES

# Trust all GitHub.com and BitBucket.org keys – this allows checking out dependencies via SSH
for ip in $(dig @8.8.8.8 bitbucket.org +short); do ssh-keyscan bitbucket.org,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
echo ":bitbucket: Added BitBucket IP Addresses to known_hosts"

for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
echo ":github: Added GitHub IP Addresses to known_hosts"
add_host_to_ssh_known_hosts bitbucket.org
add_host_to_ssh_known_hosts github.com

xcodebuild -resolvePackageDependencies
5 changes: 4 additions & 1 deletion bin/publish_private_pod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ ssh-add -D
ssh-add ~/.ssh/pod_repo_push_deploy_key
ssh-add -l

# Add the host of the spec repo (typically github.com) to the known_hosts to be sure we can clone it via ssh
add_host_to_ssh_known_hosts "$PRIVATE_SPECS_REPO"

# For some reason this fixes a failure in `lib lint`
# https://github.com/Automattic/buildkite-ci/issues/7
xcrun simctl list >> /dev/null

bundle exec pod repo push $PRIVATE_SPECS_REPO $PODSPEC_PATH
bundle exec pod repo push "$PRIVATE_SPECS_REPO" "$PODSPEC_PATH"

0 comments on commit 824d1b0

Please sign in to comment.