From 7e4c356f49980a84761bc8fcad8f2ebc99db69eb Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 20 Jan 2022 08:22:48 +0100 Subject: [PATCH 1/3] this fixes the custom clone step for forks with outdated default branch --- .drone.star | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.drone.star b/.drone.star index b82577b2b..0d3158102 100644 --- a/.drone.star +++ b/.drone.star @@ -357,7 +357,12 @@ def uploadScanResults(ctx): "SONAR_PULL_REQUEST_KEY": "%s" % (ctx.build.ref.replace("refs/pull/", "").split("/")[0]), }) - repo_slug = ctx.build.source_repo if ctx.build.source_repo else ctx.repo.slug + fork_handling = [] + if ctx.build.source_repo: + fork_handling = [ + "git remote add fork https://github.com/%s.git" % (ctx.build.source_repo), + "git pull fork", + ] return { "kind": "pipeline", @@ -375,9 +380,13 @@ def uploadScanResults(ctx): "name": "clone", "image": "alpine/git:latest", "commands": [ - "git clone https://github.com/%s.git ." % (repo_slug), - "git checkout $DRONE_COMMIT", - ], + # Always use the owncloud/ocis repository as base to have an up to date default branch. + # This is needed for the skipIfUnchanged step, since it references a commit on master (which could be absent on a fork) + "git clone https://github.com/%s.git ." % (ctx.repo.slug), + ] + fork_handling + + [ + "git checkout $DRONE_COMMIT", + ], }, ] + skipIfUnchanged(ctx, "unit-tests") + [ { From e436d7d26c4060aadb16c10a9295b3aeb6b4a685 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 20 Jan 2022 08:48:28 +0100 Subject: [PATCH 2/3] fetch infos from fork instead of just pulling --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 0d3158102..f0dffdf63 100644 --- a/.drone.star +++ b/.drone.star @@ -361,7 +361,7 @@ def uploadScanResults(ctx): if ctx.build.source_repo: fork_handling = [ "git remote add fork https://github.com/%s.git" % (ctx.build.source_repo), - "git pull fork", + "git fetch fork", ] return { From 4f294d589cd44ca3c199ac275c3c92167e0b462f Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 20 Jan 2022 08:55:18 +0100 Subject: [PATCH 3/3] only trigger fork handling if the repo slugs don't match --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index f0dffdf63..25420c3d3 100644 --- a/.drone.star +++ b/.drone.star @@ -358,7 +358,7 @@ def uploadScanResults(ctx): }) fork_handling = [] - if ctx.build.source_repo: + if ctx.build.source_repo != "" and ctx.build.source_repo != ctx.repo.slug: fork_handling = [ "git remote add fork https://github.com/%s.git" % (ctx.build.source_repo), "git fetch fork",