Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Git checkout cache #1141

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pkg/build/pipelines/git-checkout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,21 +55,35 @@ 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 clone $git_clone_flags $clone_target --depth '${{inputs.depth}}' '${{inputs.repository}}' $workdir
git config --global --add safe.directory $referenceRepo
git config --global advice.detachedHead false
git config --global init.defaultBranch main

# Init or re-init
git init --bare $referenceRepo
# Populate or update cache
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


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"
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"
Expand Down
Loading