-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathrelease-tool.sh
More file actions
155 lines (130 loc) · 5.44 KB
/
release-tool.sh
File metadata and controls
155 lines (130 loc) · 5.44 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
# Function for colored output
function chalk() {
local color=$1
local text=$2
local color_code=0
if [[ $color == "red" ]]; then
color_code=1
elif [[ $color == "green" ]]; then
color_code=2
fi
# Check if TERM is set before using tput
if [[ -n "$TERM" ]]; then
echo -e "$(tput setaf $color_code)${text}$(tput sgr0)"
else
# Fallback if TERM is not set
if [[ $color == "red" ]]; then
echo -e "\033[31m${text}\033[0m"
elif [[ $color == "green" ]]; then
echo -e "\033[32m${text}\033[0m"
else
echo -e "${text}"
fi
fi
}
# Function to build the Java project with Maven
function build_java_project() {
echo "Building Java project with Maven..."
# Change to the directory containing the POM file
cd destination/iceberg/olake-iceberg-java-writer || fail "Failed to change to Maven project directory"
echo "Building Maven project in $(pwd)"
mvn clean package -Dmaven.test.skip=true || fail "Maven build failed"
# Return to the original directory
cd - || fail "Failed to return to original directory"
echo "$(chalk green "✅ Java project successfully built")"
}
# Function to fail with a message
function fail() {
local error="${1:-Unknown error}"
echo "$(chalk red "${error}")"
exit 1
}
# Function to check and enable buildx support
function setup_buildx() {
echo "Setting up Docker buildx and QEMU..."
docker buildx version >/dev/null 2>&1 || fail "Docker buildx is not installed. Please install it."
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes || fail "Failed to set up QEMU"
docker buildx create --use --name multiarch-builder || echo "Buildx builder already exists, using it."
docker buildx inspect --bootstrap || fail "Failed to bootstrap buildx builder"
echo "✅ Buildx and QEMU setup complete"
}
# Function to perform the release
function release() {
local version=$1
local platform=$2
local branch=${3:-master}
local target_stage=${4:-driver-stage}
local image_name="$DHID/$type-$connector"
# Default to dev mode
local tag_version="dev-${version}"
local latest_tag="dev-latest"
# Override for special branches
if [[ "$branch" == "master" ]]; then
tag_version="${version}"
latest_tag="latest"
elif [[ "$branch" == "staging" ]]; then
tag_version="stag-${version}"
latest_tag="stag-latest"
fi
echo "Logging into Docker..."
docker login -u="$DOCKER_LOGIN" -p="$DOCKER_PASSWORD" || fail "Docker login failed for $DOCKER_LOGIN"
echo "**** Releasing $image_name for platforms [$platform] with version [$tag_version] ****"
# Attempt multi-platform build
echo "Attempting multi-platform build..."
docker buildx build --platform "$platform" --push \
--target "$target_stage" \
-t "${image_name}:${tag_version}" \
-t "${image_name}:${latest_tag}" \
--build-arg DRIVER_NAME="$connector" \
--build-arg DRIVER_VERSION="$VERSION" . || fail "Multi-platform build failed. Exiting..."
echo "$(chalk green "Release successful for $image_name version $tag_version")"
}
# Main script execution
SEMVER_EXPRESSION='v([0-9]+\.[0-9]+\.[0-9]+)$'
STAGING_VERSION_EXPRESSION='v([0-9]+\.[0-9]+\.[0-9]+)-[a-zA-Z0-9_.-]+'
echo "Release tool running..."
CURRENT_BRANCH=$(git branch --show-current)
echo "Building on branch: $CURRENT_BRANCH"
echo "Fetching remote changes from git with git fetch"
git fetch origin "$CURRENT_BRANCH" >/dev/null 2>&1
GIT_COMMITSHA=$(git rev-parse HEAD | cut -c 1-8)
echo "Latest commit SHA: $GIT_COMMITSHA"
echo "Running checks..."
# Verify Docker login
docker login -u="$DOCKER_LOGIN" -p="$DOCKER_PASSWORD" >/dev/null 2>&1 || fail "❌ Docker login failed. Ensure DOCKER_LOGIN and DOCKER_PASSWORD are set."
echo "✅ Docker login successful"
# Version validation based on branch (default is dev with no restrictions)
if [[ -z "$VERSION" ]]; then
fail "❌ Version not set. Empty version passed."
fi
# Only validate special branches
if [[ "$CURRENT_BRANCH" == "master" ]]; then
[[ $VERSION =~ $SEMVER_EXPRESSION ]] || fail "❌ Version $VERSION does not match semantic versioning required for master branch (e.g., v1.0.0)"
echo "✅ Version $VERSION matches semantic versioning for master branch"
elif [[ "$CURRENT_BRANCH" == "staging" ]]; then
[[ $VERSION =~ $STAGING_VERSION_EXPRESSION ]] || fail "❌ Version $VERSION does not match staging version format (e.g., v1.0.0-rc1)"
echo "✅ Version $VERSION matches format for staging branch"
else
echo "✅ Flexible versioning allowed for development branch: $VERSION"
fi
# Setup buildx and QEMU
setup_buildx
# Release the driver
platform="linux/amd64,linux/arm64"
# if driver is db2, target_stage -> db2-stage else target_stage -> driver-stage
target_stage="driver-stage"
if [[ "$DRIVER" == "db2" ]]; then
echo "ℹ️ DB2 detected: Building for linux/amd64 only using db2 driver stage"
platform="linux/amd64"
target_stage="db2-stage"
fi
echo "✅ Releasing driver $DRIVER for version $VERSION on branch $CURRENT_BRANCH to platforms: $platform (target: $target_stage)"
chalk green "=== Releasing driver: $DRIVER ==="
chalk green "=== Branch: $CURRENT_BRANCH ==="
chalk green "=== Release version: $VERSION ==="
connector=$DRIVER
type="source"
# Build Java project
build_java_project
release "$VERSION" "$platform" "$CURRENT_BRANCH" "$target_stage"