From 55eb74d147da61b0650fcf0481a0197b9049ea09 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Tue, 26 Mar 2024 15:53:11 +0100 Subject: [PATCH] fix: Use default branch for unpublished Cargo deps (#64) --- dist/publish-crates-cargo-main.js | 21 +++++++++++++-------- src/publish-crates-cargo.ts | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/dist/publish-crates-cargo-main.js b/dist/publish-crates-cargo-main.js index 9fd55b3..860a02c 100644 --- a/dist/publish-crates-cargo-main.js +++ b/dist/publish-crates-cargo-main.js @@ -82328,13 +82328,13 @@ async function main(input) { for (const repo of input.unpublishedDepsRepos) { await publishToEstuary(input, repo, registry, /^$/); } - await publishToEstuary(input, input.repo, registry, input.unpublishedDepsRegExp); + await publishToEstuary(input, input.repo, registry, input.unpublishedDepsRegExp, input.branch); await deleteRepos(input); if (input.liveRun) { for (const repo of input.unpublishedDepsRepos) { publishToCratesIo(input, repo); } - publishToCratesIo(input, input.repo); + publishToCratesIo(input, input.repo, input.branch); } await cleanup(input, registry); } @@ -82358,9 +82358,14 @@ async function cleanup(input, registry) { } await deleteRepos(input); } -function clone(input, repo) { +function clone(input, repo, branch) { const remote = `https://${input.githubToken}@github.com/${repo}.git`; - sh(`git clone --recursive --single-branch --branch ${input.branch} ${remote}`); + if (branch == undefined) { + sh(`git clone --recursive ${remote}`); + } + else { + sh(`git clone --recursive --single-branch --branch ${branch} ${remote}`); + } } async function deleteRepos(input) { lib_core.info(`Deleting repository clone ${repoPath(input.repo)}`); @@ -82373,8 +82378,8 @@ async function deleteRepos(input) { function repoPath(repo) { return repo.split("/").at(1); } -async function publishToEstuary(input, repo, registry, registryDepsRegExp) { - clone(input, repo); +async function publishToEstuary(input, repo, registry, registryDepsRegExp, branch) { + clone(input, repo, branch); const path = repoPath(input.repo); await configRegistry(path, registry.name, registry.index); await setRegistry(path, registryDepsRegExp, registry.name); @@ -82384,8 +82389,8 @@ async function publishToEstuary(input, repo, registry, registryDepsRegExp) { }; publish(path, env); } -function publishToCratesIo(input, repo) { - clone(input, repo); +function publishToCratesIo(input, repo, branch) { + clone(input, repo, branch); const path = repoPath(input.repo); const env = { CARGO_REGISTRY_TOKEN: input.cratesIoToken, diff --git a/src/publish-crates-cargo.ts b/src/publish-crates-cargo.ts index 147dd4b..27a48d3 100644 --- a/src/publish-crates-cargo.ts +++ b/src/publish-crates-cargo.ts @@ -46,7 +46,7 @@ export async function main(input: Input) { await publishToEstuary(input, repo, registry, /^$/); } - await publishToEstuary(input, input.repo, registry, input.unpublishedDepsRegExp); + await publishToEstuary(input, input.repo, registry, input.unpublishedDepsRegExp, input.branch); await deleteRepos(input); @@ -55,7 +55,7 @@ export async function main(input: Input) { publishToCratesIo(input, repo); } - publishToCratesIo(input, input.repo); + publishToCratesIo(input, input.repo, input.branch); } await cleanup(input, registry); @@ -80,9 +80,14 @@ export async function cleanup(input: Input, registry: estuary.Estuary) { await deleteRepos(input); } -function clone(input: Input, repo: string): void { +function clone(input: Input, repo: string, branch?: string): void { const remote = `https://${input.githubToken}@github.com/${repo}.git`; - sh(`git clone --recursive --single-branch --branch ${input.branch} ${remote}`); + + if (branch == undefined) { + sh(`git clone --recursive ${remote}`); + } else { + sh(`git clone --recursive --single-branch --branch ${branch} ${remote}`); + } } async function deleteRepos(input: Input) { @@ -104,8 +109,9 @@ async function publishToEstuary( repo: string, registry: estuary.Estuary, registryDepsRegExp: RegExp, + branch?: string, ): Promise { - clone(input, repo); + clone(input, repo, branch); const path = repoPath(input.repo); await cargo.configRegistry(path, registry.name, registry.index); @@ -119,8 +125,8 @@ async function publishToEstuary( publish(path, env); } -function publishToCratesIo(input: Input, repo: string) { - clone(input, repo); +function publishToCratesIo(input: Input, repo: string, branch?: string) { + clone(input, repo, branch); const path = repoPath(input.repo); const env = {