UNPKG

@coveo/semantic-monorepo-tools

Version:

A library of helper functions to do SemVer2 compliant releases from Conventional Commits in monorepos

24 lines (23 loc) 858 B
import spawn from "../utils/spawn.js"; import gitLogger from "./utils/gitLogger.js"; import { chmodSync, mkdirSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { homedir } from "node:os"; export default async function (REPO_OWNER, REPO_NAME, sshKey, remoteName) { const sshDirPath = join(homedir(), ".ssh"); const pemPath = join(sshDirPath, "id_rsa"); const sshConfigPath = join(sshDirPath, "config"); mkdirSync(sshDirPath, { recursive: true }); writeFileSync(pemPath, sshKey); chmodSync(pemPath, 0o400); writeFileSync(sshConfigPath, `Host ${remoteName} Hostname github.com PreferredAuthentications publickey IdentityFile ${pemPath}`); await spawn("git", [ "remote", "add", remoteName, `git@${remoteName}:${REPO_OWNER}/${REPO_NAME}.git`, ], gitLogger); }