-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tool for generating image release changes (#868)
* Tool for generating image release changes * commit hash not needed for monthly
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
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 |