From 9fdf456e8add8462c14d903ea028b6976867f40c Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Sat, 13 Apr 2024 05:29:59 +0100 Subject: [PATCH 1/3] git-checkout: move configs earlier One can end up in detached head upon checking out a tag already. Thus move config to remove detached head warning earlier, before any git commands are executed. Signed-off-by: Dimitri John Ledkov --- pkg/build/pipelines/git-checkout.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/build/pipelines/git-checkout.yaml b/pkg/build/pipelines/git-checkout.yaml index 2da3001a9..0d1a3fcaa 100644 --- a/pkg/build/pipelines/git-checkout.yaml +++ b/pkg/build/pipelines/git-checkout.yaml @@ -57,6 +57,7 @@ pipeline: git config --global --add safe.directory $workdir git config --global --add safe.directory $clone_fullpath + git config --global advice.detachedHead false git clone $git_clone_flags $clone_target --depth '${{inputs.depth}}' '${{inputs.repository}}' $workdir cd $workdir @@ -68,7 +69,6 @@ pipeline: if [ -z "${{inputs.expected-commit}}" ]; then echo "Warning (git-checkout): no expected-commit" elif [ -n '${{inputs.branch}}' ]; then - git config --global advice.detachedHead false remote_commit=$(git rev-parse --verify --end-of-options "refs/heads/${{inputs.branch}}") if [[ '${{inputs.expected-commit}}' != "$remote_commit" ]]; then echo "Error (git-checkout): expect commit ${{inputs.expected-commit}}, got $remote_commit" From 9bf34708b9267319655efe405cf65d0b8f5050ed Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Sat, 13 Apr 2024 05:49:30 +0100 Subject: [PATCH 2/3] git-checkout: add caching layer Initialize a bare repository in melange cache and fetch all potential desired objects into it. Then continue git clone as before. This means that any package rebuilds will be quicker w.r.t. git-checkout pipeline action. Signed-off-by: Dimitri John Ledkov --- pkg/build/pipelines/git-checkout.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/build/pipelines/git-checkout.yaml b/pkg/build/pipelines/git-checkout.yaml index 0d1a3fcaa..1a743ce6a 100644 --- a/pkg/build/pipelines/git-checkout.yaml +++ b/pkg/build/pipelines/git-checkout.yaml @@ -54,11 +54,20 @@ pipeline: workdir=$(mktemp -d) mkdir -p '${{inputs.destination}}' clone_fullpath=$(realpath '${{inputs.destination}}') + referenceRepo="/var/cache/melange/${{package.name}}.git" git config --global --add safe.directory $workdir git config --global --add safe.directory $clone_fullpath + git config --global --add safe.directory $referenceRepo git config --global advice.detachedHead false - git clone $git_clone_flags $clone_target --depth '${{inputs.depth}}' '${{inputs.repository}}' $workdir + git config --global init.defaultBranch main + + # Init or re-init + git init --bare $referenceRepo + # Populate or update cache + git -C $referenceRepo fetch $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' '${{inputs.branch}}' '${{inputs.tag}}' + # Do clone like before, but with reference + git clone --reference $referenceRepo $git_clone_flags $clone_target --depth '${{inputs.depth}}' '${{inputs.repository}}' $workdir cd $workdir tar -c . | (cd $clone_fullpath && tar -x) From 5686ab0bd96687bf4a4315285484f72691c64a56 Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Tue, 16 Apr 2024 18:29:01 +0100 Subject: [PATCH 3/3] wip --- pkg/build/pipelines/git-checkout.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/build/pipelines/git-checkout.yaml b/pkg/build/pipelines/git-checkout.yaml index 1a743ce6a..d013ff803 100644 --- a/pkg/build/pipelines/git-checkout.yaml +++ b/pkg/build/pipelines/git-checkout.yaml @@ -39,6 +39,7 @@ inputs: pipeline: - runs: | + set -x if [ -z "${{inputs.branch}}" ] && [ -z "${{inputs.tag}}" ]; then echo "Warning (git-checkout): you have not specified a branch or tag." fi @@ -65,15 +66,20 @@ pipeline: # Init or re-init git init --bare $referenceRepo # Populate or update cache - git -C $referenceRepo fetch $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' '${{inputs.branch}}' '${{inputs.tag}}' + if [ -n '${{inputs.tag}}' ]; then + git -C $referenceRepo fetch --progress $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' tag '${{inputs.tag}}' + elif [ -n '${{inputs.branch}}' ]; then + git -C $referenceRepo fetch --progress $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' '${{inputs.branch}}:${{inputs.branch}}' + elif + git -C $referenceRepo fetch --progress $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' HEAD:main + fi # Do clone like before, but with reference - git clone --reference $referenceRepo $git_clone_flags $clone_target --depth '${{inputs.depth}}' '${{inputs.repository}}' $workdir + cd $workdir tar -c . | (cd $clone_fullpath && tar -x) rm -rf $workdir cd $clone_fullpath - git config --global --add safe.directory $clone_fullpath if [ -z "${{inputs.expected-commit}}" ]; then echo "Warning (git-checkout): no expected-commit"