Skip to content

Commit adaae7e

Browse files
mrodmanupratharamachandran
authored andcommitted
[CI] Add dev/codeowners and .go-version file to be synced in backport branches (elastic#13994)
Sync in backport branches dev/codeowners folder, .go-version file and update .github/CODEOWNERS file to avoid failures.
1 parent e2b84da commit adaae7e

File tree

1 file changed

+49
-24
lines changed

1 file changed

+49
-24
lines changed

.buildkite/scripts/backport_branch.sh

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ createLocalBackportBranch() {
9696

9797
removeOtherPackages() {
9898
local sourceFolder=$1
99+
local currentPackage=""
99100
for dir in "$sourceFolder"/*; do
100101
if [[ -d "$dir" ]] && [[ "$(basename "$dir")" != "$PACKAGE_NAME" ]]; then
101102
echo "Removing directory: $dir"
102103
rm -rf "$dir"
104+
105+
currentPackage=$(basename "${dir}")
106+
echo "Removing ${currentPackage} from .github/CODEOWNERS"
107+
sed -i "/^\/packages\/${currentPackage}\//d" .github/CODEOWNERS
103108
fi
104109
done
105110
}
@@ -116,70 +121,90 @@ updateBackportBranchContents() {
116121
local BUILDKITE_FOLDER_PATH=".buildkite"
117122
local JENKINS_FOLDER_PATH=".ci"
118123
local files_cached_num=""
124+
125+
git checkout "$BACKPORT_BRANCH_NAME"
126+
echo "Copying $BUILDKITE_FOLDER_PATH from $SOURCE_BRANCH..."
127+
git checkout $SOURCE_BRANCH -- $BUILDKITE_FOLDER_PATH
128+
git add $BUILDKITE_FOLDER_PATH
129+
119130
if git ls-tree -d --name-only main:.ci >/dev/null 2>&1; then
120-
git checkout $BACKPORT_BRANCH_NAME
121-
echo "Copying $BUILDKITE_FOLDER_PATH from $SOURCE_BRANCH..."
122-
git checkout $SOURCE_BRANCH -- $BUILDKITE_FOLDER_PATH
123131
echo "Copying $JENKINS_FOLDER_PATH from $SOURCE_BRANCH..."
124132
git checkout $SOURCE_BRANCH -- $JENKINS_FOLDER_PATH
133+
git add $JENKINS_FOLDER_PATH
125134
else
126-
git checkout $BACKPORT_BRANCH_NAME
127-
echo "Copying $BUILDKITE_FOLDER_PATH from $SOURCE_BRANCH..."
128-
git checkout $SOURCE_BRANCH -- $BUILDKITE_FOLDER_PATH
129-
echo "Removing $JENKINS_FOLDER_PATH from $BACKPORT_BRANCH_NAME..."
130-
rm -rf "$JENKINS_FOLDER_PATH"
135+
if [ -d "${JENKINS_FOLDER_PATH}" ]; then
136+
echo "Removing $JENKINS_FOLDER_PATH from $BACKPORT_BRANCH_NAME..."
137+
rm -rf "$JENKINS_FOLDER_PATH"
138+
git add "$JENKINS_FOLDER_PATH"
139+
fi
131140
fi
132141

133142
# Update scripts used by mage
134143
local MAGEFILE_SCRIPTS_FOLDER="dev/citools"
135144
local TESTSREPORTER_SCRIPTS_FOLDER="dev/testsreporter"
136145
local COVERAGE_SCRIPTS_FOLDER="dev/coverage"
146+
local CODEOWNERS_SCRIPTS_FOLDER="dev/codeowners"
147+
137148
if git ls-tree -d --name-only main:${MAGEFILE_SCRIPTS_FOLDER} > /dev/null 2>&1 ; then
138149
echo "Copying $MAGEFILE_SCRIPTS_FOLDER from $SOURCE_BRANCH..."
139150
git checkout "$SOURCE_BRANCH" -- "${MAGEFILE_SCRIPTS_FOLDER}"
151+
git add ${MAGEFILE_SCRIPTS_FOLDER}
152+
140153
echo "Copying $TESTSREPORTER_SCRIPTS_FOLDER from $SOURCE_BRANCH..."
141154
git checkout "$SOURCE_BRANCH" -- "${TESTSREPORTER_SCRIPTS_FOLDER}"
155+
git add ${TESTSREPORTER_SCRIPTS_FOLDER}
156+
142157
echo "Copying $COVERAGE_SCRIPTS_FOLDER from $SOURCE_BRANCH..."
143158
git checkout "$SOURCE_BRANCH" -- "${COVERAGE_SCRIPTS_FOLDER}"
159+
git add ${COVERAGE_SCRIPTS_FOLDER}
160+
161+
echo "Copying $CODEOWNERS_SCRIPTS_FOLDER from $SOURCE_BRANCH..."
162+
git checkout "$SOURCE_BRANCH" -- "${CODEOWNERS_SCRIPTS_FOLDER}"
163+
git add ${CODEOWNERS_SCRIPTS_FOLDER}
164+
144165
echo "Copying magefile.go from $SOURCE_BRANCH..."
145166
git checkout "$SOURCE_BRANCH" -- "magefile.go"
167+
git add magefile.go
168+
169+
# As this script runs in the context of the main branch (mainly go mod tidy), we need to copy
170+
# the .go-version file from the main branch to the backport branch. This avoids failures
171+
# installing dependencies in the backport Pull Request.
172+
echo "Copying .go-version from $SOURCE_BRANCH..."
173+
git checkout "$SOURCE_BRANCH" -- ".go-version"
174+
git add .go-version
175+
146176
# Run go mod tidy to update just the dependencies related to magefile and dev scripts
147177
go mod tidy
178+
179+
git add go.mod go.sum
148180
fi
149181

150182
if [ "${REMOVE_OTHER_PACKAGES}" == "true" ]; then
151183
echo "Removing all packages from $PACKAGES_FOLDER_PATH folder"
152184
removeOtherPackages "${PACKAGES_FOLDER_PATH}"
153-
ls -la $PACKAGES_FOLDER_PATH
185+
ls -la "${PACKAGES_FOLDER_PATH}"
186+
187+
git add "${PACKAGES_FOLDER_PATH}/"
188+
git add .github/CODEOWNERS
154189
fi
155190

191+
git status
192+
156193
echo "Setting up git environment..."
157194
update_git_config
158195

159-
echo "Commiting"
160-
git add $BUILDKITE_FOLDER_PATH
161-
if [ -d "${JENKINS_FOLDER_PATH}" ]; then
162-
git add "${JENKINS_FOLDER_PATH}"
163-
fi
164-
if [ -d "${MAGEFILE_SCRIPTS_FOLDER}" ] ; then
165-
git add ${MAGEFILE_SCRIPTS_FOLDER}
166-
git add ${TESTSREPORTER_SCRIPTS_FOLDER}
167-
git add go.mod go.sum
168-
fi
169-
git add $PACKAGES_FOLDER_PATH/
170-
git status
171-
172196
files_cached_num=$(git diff --name-only --cached | wc -l)
173197
if [ "${files_cached_num}" -gt 0 ]; then
198+
echo "Committing changes..."
174199
git commit -m "Add $BUILDKITE_FOLDER_PATH and $JENKINS_FOLDER_PATH to backport branch: $BACKPORT_BRANCH_NAME from the $SOURCE_BRANCH branch"
175200
else
176201
echo "Nothing to commit, skip."
177202
fi
178203

179204
if [ "$DRY_RUN" == "true" ];then
180205
echo "DRY_RUN mode, nothing will be pushed."
181-
# Show just the relevant files diff (go.mod, go.sum, .buildkite, dev and package to be backported)
182-
git --no-pager diff $SOURCE_BRANCH...$BACKPORT_BRANCH_NAME go.mod go.sum .buildkite/ dev/ "packages/${PACKAGE_NAME}"
206+
# Show just the relevant files diff (go.mod, go.sum, .buildkite, dev, .go-version, .github/CODEOWNERS and package to be backported)
207+
git --no-pager diff $SOURCE_BRANCH...$BACKPORT_BRANCH_NAME .buildkite/ dev/ go.sum go.mod .go-version .github/CODEOWNERS "packages/${PACKAGE_NAME}"
183208
else
184209
echo "Pushing..."
185210
git push origin $BACKPORT_BRANCH_NAME

0 commit comments

Comments
 (0)