Compare commits

...

1 Commits

Author SHA1 Message Date
DevTekVE
7354dd53a9 Enhance the LFS sync script in release pipeline
This commit significantly extends the `sync-lfs.sh` script used in the release process. Rather than just switching LFS configurations and pulling/pushing, it now incorporates operations like creating a clone for branch, resetting changes, trapping exit signals and cleaning up.

This improvement enhances the reliability of synchronizing Large File Storage (LFS) objects between repositories by incorporating additional safety checks and informative echo statements. The shell script now also handles situations such as exiting in the midway more gracefully. This enhanced script is expected to provide a smoother and more reliable release process.
2024-09-01 13:56:11 +02:00

View File

@@ -1,7 +1,51 @@
#!/usr/bin/env bash
mv .lfsconfig .lfsconfig.bak
mv .lfsconfig-comma .lfsconfig
git lfs fetch --all; git lfs pull
mv .lfsconfig .lfsconfig-comma
mv .lfsconfig.bak .lfsconfig
git lfs fetch --all; git lfs push --all origin
# How to use: run from the root of the openpilot repository with the following command: ./release/ci/sync-lfs.sh
# Set variables
export their_repo="https://github.com/commaai/openpilot.git"
export their_branch="master"
export current_branch=$(git rev-parse --abbrev-ref HEAD)
export our_lfs_url=${LFS_URL:-"https://gitlab.com/sunnypilot/public/sunnypilot-lfs.git/info/lfs"}
export our_lfs_push_url=${LFS_PUSH_URL:-"ssh://git@gitlab.com/sunnypilot/public/sunnypilot-lfs.git"}
echo "Syncing LFS objects from $their_repo:$their_branch to $our_lfs_url"
echo "Pushing LFS objects to $our_lfs_push_url"
# Function to reset to the current branch and perform a hard reset
function reset_hard {
exit_status=$?
echo "Resetting to the current branch and performing a hard reset..."
git reset --hard
git switch $current_branch
exit $exit_status
}
# Set trap to ensure reset on exit
trap reset_hard SIGINT SIGTERM EXIT
# Add remote if it does not exist
git remote add comma $their_repo 2>/dev/null || echo "Remote 'comma' already exists."
# Fetch the specified branch from the remote
git fetch comma $their_branch
# Clean up old branch if it exists
git branch -D ${their_branch}-upstream 2>/dev/null || echo "No old branch to clean up."
# Checkout new branch based on the upstream branch
git checkout -b ${their_branch}-upstream comma/$their_branch
# Write the .lfsconfig directly
cat <<EOL > .lfsconfig
[lfs]
url = $our_lfs_url
pushurl = $our_lfs_push_url
locksverify = false
EOL
# Fetch all LFS objects and push them to the specified pushurl
git lfs fetch --all
git lfs push --all $our_lfs_push_url
git restore .lfsconfig
# Switch back to the current branch (handled by trap)