From dcd6819ce8469bf98e48e9cabbfe7db0563e7751 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Tue, 16 Jul 2024 16:57:42 +0530 Subject: [PATCH] feat: run copybara with github token auth --- action.yml | 14 +++++++------- src/copybara.ts | 6 ++++-- src/copybaraAction.ts | 2 -- src/hostConfig.ts | 4 ---- src/main.ts | 13 ++++++++++--- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index 6c2e5a2..ad513dd 100644 --- a/action.yml +++ b/action.yml @@ -1,15 +1,15 @@ -name: "Copybara Action 2" -description: "Transform and move code between repositories. Start with ZERO config and 100% customizable." -author: "Romain Barissat" +name: "Action Copybara" +description: "Transform and move code between repositories" +author: "Sudoblock" inputs: ssh_key: description: "SSH public key." - required: true + required: false access_token: description: "Personal access token with `repo` permissions. Always required on *destination*. Required on *SoT* only if the variable `sot_branch` below is left empty and to decide between **push** and **init** workflows." - required: false + required: true sot_repo: description: "Source repository (Source of Truth)." @@ -97,7 +97,7 @@ inputs: copybara_image: description: "Copybara Docker image to run." required: false - default: "olivr/copybara" + default: "shreyasbhat0/copybara" copybara_image_tag: description: "Copybara Docker image tag to use." @@ -115,7 +115,7 @@ inputs: default: "yes" runs: - using: "node12" + using: "node20" main: "dist/index.js" branding: diff --git a/src/copybara.ts b/src/copybara.ts index 7701abb..95ba878 100644 --- a/src/copybara.ts +++ b/src/copybara.ts @@ -11,6 +11,8 @@ export class CopyBara { } public async run(workflow: string, copybaraOptions: string[], ref: string | number = ""): Promise { + + console.log(copybaraOptions); switch (workflow) { case "init": return this.exec( @@ -32,9 +34,9 @@ export class CopyBara { public static getConfig(workflow: string, config: CopybaraConfig): string { this.validateConfig(config, workflow); return copyBaraSky( - `git@github.com:${config.sot.repo}.git`, + config.sot.repo, config.sot.branch, - `git@github.com:${config.destination.repo}.git`, + config.destination.repo, config.destination.branch, config.committer, "file:///usr/src/app", diff --git a/src/copybaraAction.ts b/src/copybaraAction.ts index 7d51e97..65beabd 100644 --- a/src/copybaraAction.ts +++ b/src/copybaraAction.ts @@ -139,7 +139,6 @@ export class CopybaraAction { async saveConfigFiles() { core.debug("Save config files"); - await hostConfig.saveSshKey(this.config.sshKey); await hostConfig.saveAccessToken(this.config.accessToken); await hostConfig.saveCommitter(this.config.committer); await hostConfig.saveKnownHosts(this.config.knownHosts); @@ -165,6 +164,5 @@ export class CopybaraAction { } interface CopybaraActionConfig extends CopybaraConfig { - sshKey: string; accessToken: string; } diff --git a/src/hostConfig.ts b/src/hostConfig.ts index 7364c81..a78719d 100644 --- a/src/hostConfig.ts +++ b/src/hostConfig.ts @@ -30,10 +30,6 @@ export class hostConfig { return this.save(this.gitCredentialsPath, `https://user:${accessToken}@github.com`); } - static async saveSshKey(sshKey: string): Promise { - return this.save(this.sshKeyPath, sshKey); - } - static async saveKnownHosts(knownHosts: string): Promise { return this.save(this.knownHostsPath, `${this.githubKnownHost}\n${knownHosts}`); } diff --git a/src/main.ts b/src/main.ts index ee8aac8..775d4e6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,16 +4,15 @@ import { exit } from "./exit"; const action = new CopybaraAction({ // Credentials - sshKey: core.getInput("ssh_key", { required: true }), accessToken: core.getInput("access_token"), // Common config sot: { - repo: core.getInput("sot_repo"), + repo: createAuthenticatedUrl(core.getInput("access_token"),core.getInput("sot_repo")), branch: core.getInput("sot_branch"), }, destination: { - repo: core.getInput("destination_repo"), + repo: createAuthenticatedUrl(core.getInput("access_token"),core.getInput("destination_repo")), branch: core.getInput("destination_branch"), }, committer: core.getInput("committer"), @@ -57,3 +56,11 @@ if (!core.isDebug()) { core.debug("BEWARE: Debug mode is on, this could result in this action succeeding while it didn't. Check the logs."); action.run().then(exit); } + +function createAuthenticatedUrl(repourl:string,access_token:string): string{ + const url = new URL(repourl); + url.username = 'oauth'; + url.password = access_token; + return url.toString(); + +} \ No newline at end of file