Skip to content

Commit 53b9984

Browse files
authored
Tool for generating image release changes (#868)
* Tool for generating image release changes * commit hash not needed for monthly
1 parent c2b4c10 commit 53b9984

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

build/prepare-release.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# This script is used to prepare a release of the dev containers.
4+
# It will bump the version of the manifest.json file and run the devcontainer upgrade command.
5+
# It will only run on the images that have been modified since the last release.
6+
# If no commit hash is provided, it will run in monthly release mode and bump the version of all images.
7+
# Example adhoc release: ./build/prepare-release.sh 1c6f558dc86aafd7749074ec44e238f331303517
8+
# Example monthly release: ./build/prepare-release.sh
9+
10+
11+
SCRIPT_SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12+
SRC_DIR=$(readlink -m $SCRIPT_SOURCE_DIR/../src)
13+
MANIFEST_FILE="manifest.json"
14+
COMMIT_HASH=$1
15+
16+
get_modified_images() {
17+
git diff --name-only --diff-filter=ACMRTUB ${COMMIT_HASH} HEAD ${SRC_DIR} | while read file; do
18+
if [ ! -z $file ]; then
19+
commitMessage=$(git log -1 $file)
20+
# omit auto commits from bot
21+
if [[ $commitMessage != *"Dev containers Bot"* ]]; then
22+
# only get the top level directory for the image
23+
if [ $(echo $file | tr "/" "\n" | wc -l) -eq 3 ]; then
24+
readlink -m $(dirname $file)
25+
fi
26+
fi
27+
fi
28+
done | sort | uniq
29+
}
30+
31+
get_all_images() {
32+
find $SRC_DIR -maxdepth 1 -type d | tail -n +2 | sort | uniq
33+
}
34+
35+
bump_version() {
36+
directory=$1
37+
manifestPath="$directory/$MANIFEST_FILE"
38+
version=$(grep -oP '(?<="version": ")[^"]*' $manifestPath)
39+
newVersion=$(echo $version | awk -F. -v OFS=. '{$NF += 1 ; print}')
40+
sed -i "s/\"version\": \"$version\"/\"version\": \"$newVersion\"/g" $manifestPath
41+
}
42+
43+
release_image() {
44+
image=$1
45+
echo "-----------------------------------------------"
46+
echo "Releasing image $image"
47+
echo "-----------------------------------------------"
48+
49+
bump_version $image
50+
devcontainer upgrade --workspace-folder $image
51+
}
52+
53+
adhoc_release() {
54+
for image in $(get_modified_images); do
55+
release_image $image
56+
done
57+
}
58+
59+
monthly_release() {
60+
for image in $(get_all_images); do
61+
release_image $image
62+
done
63+
}
64+
65+
main() {
66+
if [ "$COMMIT_HASH" == "" ]; then
67+
echo "No commit hash provided, running in monthly release mode"
68+
monthly_release
69+
else
70+
adhoc_release
71+
fi
72+
}
73+
74+
main

0 commit comments

Comments
 (0)