Skip to content

Commit 0543bbb

Browse files
committed
Adjust release scripts to work with scripts as monorepo
The change prepared in flatcar/scripts#699 means that we don't use the coreos-overlay/portage-stable repos anymore. Skip these repositories and the submodule handling, too. Leave existing logic there to support doing releases the old way (at least for the nearer future).
1 parent 34a1687 commit 0543bbb

File tree

3 files changed

+75
-24
lines changed

3 files changed

+75
-24
lines changed

mirror-repos-branch

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ trap '{ export EXT="$?"; rm -rf "${REPOS_DIR}" && exit "${EXT}"; }' EXIT
4141

4242
cd "${REPOS_DIR}"
4343

44+
# Check if we are in the monorepo case
45+
[ ! -d scripts ] && git clone --recurse-submodules "git@github.com:flatcar/scripts"
46+
if [ "$(git -C scripts show "origin/${SRC_BUILD_BRANCH}":.gitmodules 2>/dev/null)" = "" ]; then
47+
FLATCAR_REPOS=("scripts")
48+
fi
49+
4450
for repo in "${FLATCAR_REPOS[@]}"; do
4551
# Note: systemd repo has neither flatcar-build-* branches nor flatcar-master
4652
# branch. So we should skip systemd completely.
@@ -62,7 +68,7 @@ for repo in "${FLATCAR_REPOS[@]}"; do
6268
fi
6369

6470
echo "Mirroring a branch ${src_branch} to ${DST_BUILD_BRANCH}"
65-
git checkout -B "${DST_BUILD_BRANCH}" "origin/${src_branch}"
71+
git checkout --recurse-submodules --force -B "${DST_BUILD_BRANCH}" "origin/${src_branch}"
6672
git push ${PUSH_OPTIONS} origin "${DST_BUILD_BRANCH}"
6773

6874
popd

show-changes

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,66 @@ for section in security bugfixes changes updates; do
4848
esac
4949
echo
5050
for repo in coreos-overlay portage-stable scripts; do
51-
if [ "${repo}" = scripts ] && [ ! -e "${repo}" ]; then
52-
# Support the previous repo name for old checkouts
53-
repo="flatcar-scripts"
54-
fi
5551
OLDREF="${OLD}"
5652
NEWREF="${NEW}"
57-
REPOPATH="${repo}"
58-
# For the submodule detection, assume that the "scripts" repo name is ok
59-
if [ "${repo}" != "scripts" ] && [ -d "scripts/sdk_container/src/third_party/${repo}" ]; then
53+
OLDREPOPATH="${repo}"
54+
NEWREPOPATH="${repo}"
55+
OLDPREPEND=""
56+
NEWPREPEND=""
57+
if [ "${repo}" != "scripts" ]; then
6058
if [ "${FETCH}" = 1 ]; then
6159
git -C "scripts" fetch -t -f 2> /dev/null > /dev/null || { echo "Error: git fetch -t -f failed" ; exit 1 ; }
6260
fi
63-
# Find the pinned submodule refs because there may be no release tags inside the submodules
64-
# Pipe to awk instead of using --object-only for git 2.35 support
65-
OLDREF=$(git -C "scripts" ls-tree "${OLD}" "sdk_container/src/third_party/${repo}" | awk '{print $3 }')
66-
NEWREF=$(git -C "scripts" ls-tree "${NEW}" "sdk_container/src/third_party/${repo}" | awk '{print $3 }')
67-
REPOPATH="scripts/sdk_container/src/third_party/${repo}"
61+
# Check if we are in the monorepo case where we can use the scripts ref or not
62+
if [ "$(git -C scripts show "${OLD}":.gitmodules 2>/dev/null)" != "" ]; then
63+
# Find the pinned submodule refs because there may be no release tags inside the submodules
64+
# Pipe to awk instead of using --object-only for git 2.35 support
65+
OLDREF=$(git -C "scripts" ls-tree "${OLD}" "sdk_container/src/third_party/${repo}" | awk '{print $3 }')
66+
# We can't assume anymore that the submodule repo is available under scripts/
67+
if [ ! -d "${repo}" ]; then
68+
git clone "git@github.com:flatcar/${repo}.git"
69+
fi
70+
else
71+
OLDPREPEND="sdk_container/src/third_party/${repo}/"
72+
OLDREPOPATH="scripts"
73+
fi
74+
if [ "$(git -C scripts show "${NEW}":.gitmodules 2>/dev/null)" != "" ]; then
75+
NEWREF=$(git -C "scripts" ls-tree "${NEW}" "sdk_container/src/third_party/${repo}" | awk '{print $3 }')
76+
if [ ! -d "${repo}" ]; then
77+
git clone "git@github.com:flatcar/${repo}.git"
78+
fi
79+
else
80+
NEWPREPEND="sdk_container/src/third_party/${repo}/"
81+
NEWREPOPATH="scripts"
82+
fi
6883
fi
6984
if [ "${FETCH}" = 1 ]; then
70-
git -C "${REPOPATH}" fetch -t -f 2> /dev/null > /dev/null || { echo "Error: git fetch -t -f failed" ; exit 1 ; }
85+
git -C "${OLDREPOPATH}" fetch -t -f 2> /dev/null > /dev/null || { echo "Error: git fetch -t -f failed" ; exit 1 ; }
86+
git -C "${NEWREPOPATH}" fetch -t -f 2> /dev/null > /dev/null || { echo "Error: git fetch -t -f failed" ; exit 1 ; }
7187
fi
7288
if [ "${section}" = "security" ] && [ "${repo}" = "coreos-overlay" ]; then
73-
FROM_KERNEL=$(git -C "${REPOPATH}" show "${OLDREF}":sys-kernel/coreos-kernel/ | grep -m 1 'coreos-kernel-.*\.ebuild' | cut -d - -f 3 | cut -d . -f 1-3)
74-
TO_KERNEL=$(git -C "${REPOPATH}" show "${NEWREF}":sys-kernel/coreos-kernel/ | grep -m 1 'coreos-kernel-.*\.ebuild' | cut -d - -f 3 | cut -d . -f 1-3)
89+
FROM_KERNEL=$(git -C "${OLDREPOPATH}" show "${OLDREF}":"${OLDPREPEND}"sys-kernel/coreos-kernel/ | grep -m 1 'coreos-kernel-.*\.ebuild' | cut -d - -f 3 | cut -d . -f 1-3)
90+
TO_KERNEL=$(git -C "${NEWREPOPATH}" show "${NEWREF}":"${NEWPREPEND}"sys-kernel/coreos-kernel/ | grep -m 1 'coreos-kernel-.*\.ebuild' | cut -d - -f 3 | cut -d . -f 1-3)
7591
if [ "${FROM_KERNEL}" != "${TO_KERNEL}" ]; then
7692
KERNEL_ENTRIES=$("${SCRIPTFOLDER}"/show-fixed-kernel-cves.py -f "${FROM_KERNEL}" -t "${TO_KERNEL}")
7793
if [ "${KERNEL_ENTRIES}" != "" ]; then
7894
echo "- Linux (${KERNEL_ENTRIES})"
7995
fi
8096
fi
8197
fi
82-
git -C "${REPOPATH}" difftool --no-prompt --extcmd='sh -c "cat \"$REMOTE\"" --' "${OLDREF}..${NEWREF}" -- "changelog/${section}/" | sort || { echo "Error: git difftool failed" ; exit 1 ; }
98+
99+
# The assumption is that the old ref is really older, so we can assume that old would have submodules while new doesn't have them anymore
100+
if [ "${OLDREPOPATH}" != "${NEWREPOPATH}" ] && [ "${NEWREPOPATH}" = "scripts" ]; then
101+
# One patch before the ./checkout helper disappeared we still had submodules
102+
LAST_SUBMOD_SCRIPTS_REF="$(git -C scripts rev-list -n 1 "${NEWREF}" -- checkout)~1"
103+
LAST_SUBMOD_REF=$(git -C scripts ls-tree "${LAST_SUBMOD_SCRIPTS_REF}" "sdk_container/src/third_party/${repo}" | awk '{print $3 }')
104+
# The patch that removed the submodule overrides README has the merge history
105+
FIRST_MONO_REF=$(git -C scripts rev-list -n 1 "${NEWREF}" -- sdk_container/git-override/README.md)
106+
git -C "${OLDREPOPATH}" difftool --no-prompt --extcmd='sh -c "cat \"$REMOTE\"" --' "${OLDREF}..${LAST_SUBMOD_REF}" -- "${OLDPREPEND}changelog/${section}/" | sort || { echo "Error: git difftool failed" ; exit 1 ; }
107+
git -C "${NEWREPOPATH}" difftool --no-prompt --extcmd='sh -c "cat \"$REMOTE\"" --' "${FIRST_MONO_REF}..${NEWREF}" -- "${NEWPREPEND}changelog/${section}/" | sort || { echo "Error: git difftool failed" ; exit 1 ; }
108+
else
109+
git -C "${NEWREPOPATH}" difftool --no-prompt --extcmd='sh -c "cat \"$REMOTE\"" --' "${OLDREF}..${NEWREF}" -- "${NEWPREPEND}changelog/${section}/" | sort || { echo "Error: git difftool failed" ; exit 1 ; }
110+
fi
83111
# The -x 'sh -c "cat \"$REMOTE\"" --' command assumes that new changes have their own changelog files,
84112
# and thus ignores the LOCAL file (which is the empty /dev/null) and prints out the REMOTE completly.
85113
# If an existing file got changed, we assume that this is just a correction for the old change but

tag-release

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ echo "SCRIPTS_REF=$SCRIPTS_REF OVERLAY_REF=$OVERLAY_REF PORTAGE_REF=$PORTAGE_REF
3636
REPOS="coreos-overlay portage-stable scripts"
3737
# scripts should be last as it binds the other two together as submodules, if they exist
3838

39+
# Check if we are in the monorepo, in this case only work on "scripts"
40+
cd "$SCRIPTFOLDER/.."
41+
if [ ! -d "scripts" ]; then
42+
git clone --recurse-submodules 'git@github.com:flatcar/scripts.git'
43+
fi
44+
git -C scripts fetch origin
45+
if [ "$(git -C scripts show "origin/$MAINT-$MAJOR":.gitmodules 2>/dev/null)" = "" ]; then
46+
REPOS="scripts"
47+
fi
48+
49+
3950
for REPO in ${REPOS}; do
4051
echo "Preparing ${REPO}"
4152
cd "$SCRIPTFOLDER/.."
@@ -52,13 +63,17 @@ for REPO in ${REPOS}; do
5263
git tag -d "$TAG" || echo "No local tags deleted"
5364
git push --delete origin "$TAG" || echo "No remote tags deleted"
5465
# Check if we have to update the submodules while tagging
55-
if [ "${REPO}" = "scripts" ] && git show "origin/$MAINT-$MAJOR":sdk_container/src > /dev/null 2>/dev/null ; then
66+
if [ "${REPO}" = "scripts" ]; then
5667
if [ "${REF}" != "origin/$MAINT-$MAJOR" ]; then
5768
echo "Error: can't find the scripts branch to push the updated submodule to, you can't overwrite SCRIPTS_REF anymore"
5869
exit 1
5970
fi
60-
echo "Checking out scripts branch $MAINT-$MAJOR to update submodules"
61-
git checkout --recurse-submodules -B "$MAINT-$MAJOR" "origin/$MAINT-$MAJOR" || { echo "Error: could not checkout the right branch in your 'scripts' repo" ; exit 1 ; }
71+
if [ "$(git status --porcelain)" != "" ]; then
72+
echo "Error: uncommitted changes found which will be lost"
73+
exit 1
74+
fi
75+
echo "Checking out scripts branch $MAINT-$MAJOR to update submodules and create version file"
76+
git checkout --force --recurse-submodules -B "$MAINT-$MAJOR" "origin/$MAINT-$MAJOR" || { echo "Error: could not checkout the right branch in your 'scripts' repo" ; exit 1 ; }
6277
git pull --recurse-submodules || { echo "Error: could not pull the branch in your 'scripts' repo" ; exit 1 ; }
6378
if [ "$(git log HEAD.."origin/$MAINT-$MAJOR")" != "" ] || ! git diff --quiet "origin/$MAINT-$MAJOR" ; then
6479
echo "Error: local changes in your 'scripts' repo"
@@ -68,14 +83,16 @@ for REPO in ${REPOS}; do
6883
(
6984
source sdk_lib/sdk_container_common.sh
7085
source ci-automation/ci_automation_common.sh
71-
cd "sdk_container/src/third_party/coreos-overlay"; git fetch --all --tags --force; cd -
72-
cd "sdk_container/src/third_party/portage-stable"; git fetch --all --tags --force; cd -
73-
update_submodules "${OVERLAY_REF}" "${PORTAGE_REF}"
86+
if [ "$(git show "origin/$MAINT-$MAJOR":.gitmodules 2>/dev/null)" != "" ]; then
87+
cd "sdk_container/src/third_party/coreos-overlay"; git fetch --all --tags --force; cd -
88+
cd "sdk_container/src/third_party/portage-stable"; git fetch --all --tags --force; cd -
89+
update_submodules "${OVERLAY_REF}" "${PORTAGE_REF}"
90+
fi
7491
create_versionfile "${SDK_VERSION}" "${VERSION}"
7592
SIGN=1 update_and_push_version "${TAG}" true
7693
)
7794
else
78-
# Tag the other repos or the LTS scripts repo
95+
# Tag the other repos
7996
echo "Tagging ${REF} as ${TAG}"
8097
git tag -s "${TAG}" -m "${TAG}" "${REF}"
8198
echo "Pushing tag"

0 commit comments

Comments
 (0)