Skip to content

Instantly share code, notes, and snippets.

@Grohden
Last active January 29, 2025 10:55
Show Gist options
  • Save Grohden/b70c91c14680efc526664a20abfe962e to your computer and use it in GitHub Desktop.
Save Grohden/b70c91c14680efc526664a20abfe962e to your computer and use it in GitHub Desktop.
ssh setup for private repo usages in expo eas
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
function present(value) {
return value !== null && value !== undefined && value !== '';
}
console.log('Enabling corepack for yarn v4');
execSync('corepack enable && corepack prepare [email protected] --activate', {
stdio: 'inherit',
});
const githubSshKey = process.env.GITHUB_SSH_KEY;
// For dev machines, they should already have the proper key, so local we'll
// not overwrite their keys if GITHUB_SSH_KEY is not set
if (present(githubSshKey)) {
console.log('Setting up SSH Key for iOS Our internal dependencies');
const sshDir = path.resolve(
process.env.HOME || process.env.USERPROFILE,
'.ssh',
);
if (!fs.existsSync(sshDir)) {
fs.mkdirSync(sshDir, { recursive: true });
}
fs.writeFileSync(
path.join(sshDir, 'id_rsa'),
Buffer.from(githubSshKey, 'base64'),
);
fs.chmodSync(path.join(sshDir, 'id_rsa'), 0o600);
execSync(
`ssh-keygen -y -f ${path.join(sshDir, 'id_rsa')} > ${path.join(sshDir, 'id_rsa.pub')}`,
{ stdio: 'inherit' },
);
execSync(
`ssh-keyscan -t rsa github.com >> ${path.join(sshDir, 'known_hosts')}`,
{ stdio: 'inherit' },
);
console.log('SSH Key setup done');
} else {
console.log(
'GITHUB_SSH_KEY not present, assuming build to be on dev machine (SSH setup skipped)',
);
}
// other checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment