-
Notifications
You must be signed in to change notification settings - Fork 1
/
talend-modules.sh
executable file
·110 lines (96 loc) · 3.37 KB
/
talend-modules.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# This script manages the talend modules
# Function to display help
function display_help() {
echo "Usage: $0 <command> [arguments]"
echo "Available commands:"
echo " commit <version-patch> - Commit a Git submodule, extract version/patch, and save to product.properties. Perform a Git commit."
echo " clean - Reset Git submodules to the last committed state."
echo " update - Initialize and update Git submodules."
echo " help - Display this help message."
}
# Function for the commit command
function commit_command() {
if [ $# -lt 1 ]; then
echo "Usage: $0 commit <version-patch>"
exit 1
fi
local VERSION_PATCH="$1"
local VERSION="${VERSION_PATCH%%-*}"
local MAJOR_VERSION="${VERSION%%.*}"
local PATCH="${VERSION_PATCH#*-}"
# Define the base URL
local PATCH_BASE_URL="https://update.talend.com/Studio/$MAJOR_VERSION/updates/$PATCH"
# Construct the URL for patch.properties
local PATCH_PROPERTIES_URL="$PATCH_BASE_URL/patch.properties"
# Fetch the contents of patch.properties and store it in PATCH_PROPERTIES
local PATCH_PROPERTIES=$(curl -s "$PATCH_PROPERTIES_URL")
# Extract the date and time part of product.version and store it in PRODUCT_TIMESTAMP using the specified regex
if [[ $PATCH_PROPERTIES =~ product\.version=.*([0-9]{8}_[0-9]{4}).* ]]; then
local PRODUCT_TIMESTAMP="${BASH_REMATCH[1]}"
else
echo "Failed to extract PRODUCT_TIMESTAMP"
exit 1
fi
# Reset the Git submodule and check out the release or patch branch
for submodule in $(git submodule status --recursive | awk '{print $2}'); do
(cd "$submodule" || exit 1
git fetch --prune --tags --all --force --prune-tags
git reset --hard
if ! git checkout release/"$VERSION"-"$PATCH"; then
git checkout patch/"$VERSION"/"$PATCH"
fi
)
done
# Create a properties file with the extracted information
echo "product.version=$VERSION" > product.properties
echo "product.patch=$PATCH" >> product.properties
echo "product.timestamp=$PRODUCT_TIMESTAMP" >> product.properties
echo "release.suffix=$PATCH" >> product.properties
echo "revision.filename=-$PATCH" >> product.properties
# Perform a Git commit with the version as the commit message
git commit -a -m "$VERSION_PATCH"
}
# Function for the clean command
function clean_command() {
# Make sure any git index is reset
git submodule foreach git reset --hard
# Remove all files not in git submodule repos, including files from .gitignore
git submodule foreach git clean -fdx
# Remove all files not in git submodule repos, excluding files from .gitignore
git clean -fd
# But remove the target
rm -rf target
}
# Function for the update command
function update_command() {
# Update submodules using "git submodule update --init"
git submodule update --init
}
# Check if a command was provided as the first argument
if [ -z "$1" ]; then
display_help
exit 1
fi
# Extract the command
COMMAND="$1"
case "$COMMAND" in
"commit")
shift
commit_command "$@"
;;
"clean")
clean_command
;;
"update")
update_command
;;
"help")
display_help
;;
*)
echo "Invalid command: $COMMAND"
display_help
exit 1
;;
esac