feat(coreos-update-submodule): add an helper to update submodule

The coreos-update-submodule script help to keep our internal git
mirror of upstream repository in sync by automatically pulling
and pushing the target branch for each submodule
This commit is contained in:
Samuel Dolt 2022-12-19 15:11:06 +01:00
parent e4f701b315
commit 1269f10f11
3 changed files with 62 additions and 0 deletions

4
.gitmodules vendored
View File

@ -1,16 +1,20 @@
[submodule "bitbake"] [submodule "bitbake"]
path = bitbake path = bitbake
url = ssh://git@bitbucket.gad.local:7999/ico/bitbake.git url = ssh://git@bitbucket.gad.local:7999/ico/bitbake.git
upstream-url = https://git.openembedded.org/bitbake/
branch = 2.0 branch = 2.0
[submodule "layers/openembedded-core"] [submodule "layers/openembedded-core"]
path = layers/openembedded-core path = layers/openembedded-core
url = ssh://git@bitbucket.gad.local:7999/ico/openembedded-core.git url = ssh://git@bitbucket.gad.local:7999/ico/openembedded-core.git
upstream-url = https://git.openembedded.org/openembedded-core
branch = kirkstone branch = kirkstone
[submodule "layers/meta-openembedded"] [submodule "layers/meta-openembedded"]
path = layers/meta-openembedded path = layers/meta-openembedded
url = ssh://git@bitbucket.gad.local:7999/ico/meta-openembedded.git url = ssh://git@bitbucket.gad.local:7999/ico/meta-openembedded.git
upstream-url = https://git.openembedded.org/meta-openembedded
branch = kirkstone branch = kirkstone
[submodule "layers/meta-virtualization"] [submodule "layers/meta-virtualization"]
path = layers/meta-virtualization path = layers/meta-virtualization
url = ssh://git@bitbucket.gad.local:7999/ico/meta-virtualization.git url = ssh://git@bitbucket.gad.local:7999/ico/meta-virtualization.git
upstream-url = https://git.yoctoproject.org/meta-virtualization
branch = kirkstone branch = kirkstone

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -e
# This is run by git submodule foreach inside the coreos-update-submodule script
# Some info is passed via variable.
if [ -z "$sm_path" ]; then
echo "This scripts should not be run directly"
exit 1
fi
UPSTREAM_URL=$(git config --file "${toplevel}/.gitmodules" --get "submodule.${name}.upstream-url")
DOWNSTREAM_URL=$(git config --file "${toplevel}/.gitmodules" --get "submodule.${name}.url")
TRACKING_BRANCH=$(git config --file "${toplevel}/.gitmodules" --get "submodule.${name}.branch")
echo "Pull $TRACKING_BRANCH from ${UPSTREAM_URL} and pushing to ${DOWNSTREAM_URL}"
git pull "${UPSTREAM_URL}" "${TRACKING_BRANCH}" --ff-only
git push "${DOWNSTREAM_URL}" "${TRACKING_BRANCH}"

38
scripts/coreos-update-submodule Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -e
echo "Updating layers"
# First we go to the root git repository. This will fail if we are not inside
# a repository
gitdir=$(git rev-parse --show-toplevel)
echo "Root Git directory found at $gitdir"
cd $gitdir
# Ensure we are inside the CoreOS repository
if ! [ -f "coreos-init-build-env" ]; then
echo "We are not inside the CoreOS repository"
exit 1
fi
echo "This script will update each submodule by pulling from the upstream url"
echo "Then the internal mirror on bitbucket.gad.local will be updated"
printf 'Do you want to proceed (y/n)? '
read answer
if ! [ "$answer" != "${answer#[Yy]}" ] ; then
exit 1
fi
echo "Update all submodule to latest commit, using the tracking branch..."
git submodule foreach "_coreos-update-submodule-internal"
echo "All submodule are updated, internal mirror are up to date"
echo "You can now use git add and git commit to push changes to CoreOS"
git status