Skip to content

Commit

Permalink
Update dependencies-update scripts
Browse files Browse the repository at this point in the history
The scripts are changed so that the update happens in the current
branch, and the changes are not pushed to the repository.

Setting the branch and pushing the changes will be the
responsibility of the tekton pipeline.
  • Loading branch information
Roming22 committed Aug 16, 2023
1 parent 881aea5 commit ce1c9a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 47 deletions.
9 changes: 2 additions & 7 deletions developer/images/dependencies-update/hack/bin/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@ task_init() {
}

task_end() {
if [ -n "$BRANCH_NAME" ]; then
commit_changes
fi
}

commit_changes() {
if ! git diff --quiet HEAD; then
# Commit_changes
if ! git diff --quiet; then
git add .
git commit --file="$COMMIT_MSG" --quiet --signoff
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ run_task() {
for BINARY in "${BINARIES[@]}"; do
update_binary
done
git diff shared/config/dependencies.sh \
| grep "^+export" \
| sed -e "s:^+export:-:" -e "s:_VERSION=: to :" \
| tr -d \" \
| tr "[:upper:]" "[:lower:]" >>"$COMMIT_MSG"
if [ $(git diff shared/config/dependencies.sh | wc -l) != "0" ]; then
git diff shared/config/dependencies.sh \
| grep "^+export" \
| sed -e "s:^+export:-:" -e "s:_VERSION=: to :" \
| tr -d \" \
| tr "[:upper:]" "[:lower:]" >>"$COMMIT_MSG"
fi
}

update_binary() {
if grep --ignore-case --quiet " ${BINARY}_VERSION=.*# *Freeze" "$DEPENDENCIES"; then
# Ignore frozen dependencies
return
fi
echo "$BINARY"
echo -n " - $BINARY: "
unset VERSION
"get_${BINARY}_version"
echo "$VERSION"
BINARY=$(echo "$BINARY" | tr "[:lower:]" "[:upper:]")
sed -i -e "s:\( ${BINARY}_VERSION\)=.*:\1=\"$VERSION\":" "$DEPENDENCIES"
}
Expand Down Expand Up @@ -147,7 +150,6 @@ get_github_release() {
| sort -V \
| tail -1
)
echo "VERSION=$VERSION"
}

if [ "${BASH_SOURCE[0]}" == "$0" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ process_dockerfiles() {

process_base_image_cmd() {
base_image_name=$(echo "$from_base_image" | sed 's:^.* ::')
echo -n "- $base_image_name"
echo -n " - $base_image_name"
get_base_image_sha
echo -n "@$base_image_sha : "
update_base_image_sha
Expand Down
44 changes: 12 additions & 32 deletions developer/images/dependencies-update/hack/bin/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ Usage:
Upgrade Pipeline Service dependencies.
Optional arguments:
-c, --commit_to BRANCH_NAME
Commit changes to BRANCH_NAME
Default: robot/\$CURRENT_BRANCH_NAME/update_dependencies.
-t, --task TASKNAME
Only run the selected task. Can be repeated to run multiple tasks.
TASKNAME must be in [$(echo "${DEFAULT_TASKS[@]}" | sed 's: :, :')].
Expand All @@ -57,15 +54,11 @@ Example:
}

parse_args() {
mapfile -t DEFAULT_TASKS < <(find "$SCRIPT_DIR/tasks" -type f -name \*.sh -exec basename {} \; | sed 's:...$::')
mapfile -t DEFAULT_TASKS < <(find "$SCRIPT_DIR/tasks" -type f -name \*.sh -exec basename {} \; | sort | sed 's:...$::')
TASKS=()
WORKSPACE_DIR="$PROJECT_DIR"
while [[ $# -gt 0 ]]; do
case $1 in
-c | --commit_to)
shift
BRANCH_NAME="$1"
;;
-t | --task)
shift
TASKS+=("$1")
Expand Down Expand Up @@ -98,53 +91,40 @@ init() {
TASKS=( "${DEFAULT_TASKS[@]}" )
fi
COMMIT_MSG="${TMPDIR:-/tmp}/update_commit_msg.txt"
export BRANCH_NAME
export COMMIT_MSG
export WORKSPACE_DIR
cd "$WORKSPACE_DIR"
git config --global --add safe.directory "$PWD"
}

prepare_branch(){
CURRENT_BRANCH_NAME=$(git branch --show-current)
BRANCH_NAME=${BRANCH_NAME:-robot/$CURRENT_BRANCH_NAME/update_dependencies}

# Revert any change to the current branch
if ! git diff --quiet; then
git stash --include-untracked
GIT_STASH="true"
fi
GIT_STASH=${GIT_STASH:-}

# Create a new branch from the current branch
git branch --copy --force "$BRANCH_NAME"
git checkout "$BRANCH_NAME"
START_COMMIT=$(git rev-parse HEAD)
}

push_changes(){
local push="false"
if ! git diff --quiet "$CURRENT_BRANCH_NAME"; then
if ! git fetch origin "refs/heads/$BRANCH_NAME" 2>/dev/null; then
push="true"
elif ! git diff --quiet "origin/$BRANCH_NAME"; then
push="true"
fi
show_summary(){
local updated="false"
if ! git diff --quiet $START_COMMIT..HEAD; then
updated="true"
fi

echo
echo "[Summary]"
if [ "$push" = "true" ]; then
git log --format="%B" "$CURRENT_BRANCH_NAME..HEAD"
git push --force --quiet --set-upstream "origin" "$BRANCH_NAME"
if [ "$updated" = "true" ]; then
git log --format="%B" "$START_COMMIT..HEAD"
else
echo "No update to push"
echo "No updates"
fi
}

revert_to_current_branch(){
revert_branch(){
echo
git clean --force -x
git checkout --force "$CURRENT_BRANCH_NAME"
if [ -n "$GIT_STASH" ]; then
git stash pop
fi
Expand All @@ -163,8 +143,8 @@ main() {
echo "[$task_name]"
"$SCRIPT_DIR/tasks/$task_name.sh"
done
push_changes
revert_to_current_branch
show_summary
revert_branch
}

if [ "${BASH_SOURCE[0]}" == "$0" ]; then
Expand Down

0 comments on commit ce1c9a9

Please sign in to comment.