Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool for generating image release changes #868

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions build/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

# This script is used to prepare a release of the dev containers.
# It will bump the version of the manifest.json file and run the devcontainer upgrade command.
# It will only run on the images that have been modified since the last release.
# If no commit hash is provided, it will run in monthly release mode and bump the version of all images.
# Example adhoc release: ./build/prepare-release.sh 1c6f558dc86aafd7749074ec44e238f331303517
# Example monthly release: ./build/prepare-release.sh


SCRIPT_SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SRC_DIR=$(readlink -m $SCRIPT_SOURCE_DIR/../src)
MANIFEST_FILE="manifest.json"
COMMIT_HASH=$1

get_modified_images() {
git diff --name-only --diff-filter=ACMRTUB ${COMMIT_HASH} HEAD ${SRC_DIR} | while read file; do
if [ ! -z $file ]; then
commitMessage=$(git log -1 $file)
# omit auto commits from bot
if [[ $commitMessage != *"Dev containers Bot"* ]]; then
# only get the top level directory for the image
if [ $(echo $file | tr "/" "\n" | wc -l) -eq 3 ]; then
readlink -m $(dirname $file)
fi
fi
fi
done | sort | uniq
}

get_all_images() {
find $SRC_DIR -maxdepth 1 -type d | tail -n +2 | sort | uniq
}

bump_version() {
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
directory=$1
manifestPath="$directory/$MANIFEST_FILE"
version=$(grep -oP '(?<="version": ")[^"]*' $manifestPath)
newVersion=$(echo $version | awk -F. -v OFS=. '{$NF += 1 ; print}')
sed -i "s/\"version\": \"$version\"/\"version\": \"$newVersion\"/g" $manifestPath
}

release_image() {
image=$1
echo "-----------------------------------------------"
echo "Releasing image $image"
echo "-----------------------------------------------"

bump_version $image
devcontainer upgrade --workspace-folder $image
}

adhoc_release() {
for image in $(get_modified_images); do
release_image $image
done
}

monthly_release() {
for image in $(get_all_images); do
release_image $image
done
}

main() {
if [ "$COMMIT_HASH" == "" ]; then
echo "No commit hash provided, running in monthly release mode"
monthly_release
else
adhoc_release
fi
}

main