77 lines
2.3 KiB
Bash
Executable File
77 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Get version from package.json.
|
|
VERSION=$(node -p -e "require('./package.json').version")
|
|
|
|
# Set alias to latest if branch is main, dev if develop, or commit hash if others.
|
|
if [ "$(git branch --show-current)" == "main" ]; then
|
|
# Check if the working directory is clean.
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
echo "Working directory is not clean. Commit changes before releasing."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if the local main branch is up-to-date with the remote main branch.
|
|
git fetch
|
|
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
|
|
echo "Local main branch is not up-to-date with the remote main branch. Push changes before releasing."
|
|
exit 1
|
|
fi
|
|
elif [ "$(git branch --show-current)" == "develop" ]; then
|
|
# Check if the working directory is clean.
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
echo "Working directory is not clean. Commit changes before releasing."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if the local main branch is up-to-date with the remote main branch.
|
|
git fetch
|
|
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/develop)" ]; then
|
|
echo "Local main branch is not up-to-date with the remote main branch. Push changes before releasing."
|
|
exit 1
|
|
fi
|
|
else
|
|
VERSION=$(git rev-parse --short HEAD)
|
|
fi
|
|
|
|
# Set tags.
|
|
TAGS=(
|
|
"3t.network/butlerbot:$VERSION"
|
|
"git.3t.network/3t.network/butlerbot:$VERSION"
|
|
)
|
|
|
|
# Append to tags if the branch is main or develop.
|
|
if [ "$ALIAS" == "latest" ]; then
|
|
TAGS+=("3t.network/butlerbot:latest")
|
|
TAGS+=("git.3t.network/3t.network/butlerbot:latest")
|
|
elif [ "$ALIAS" == "dev" ]; then
|
|
TAGS+=("3t.network/butlerbot:dev")
|
|
TAGS+=("git.3t.network/3t.network/butlerbot:dev")
|
|
fi
|
|
|
|
# cd to the project root directory.
|
|
cd "$(dirname "$0")/.."
|
|
docker build -t butlerbot:$VERSION .
|
|
|
|
# Tag the Docker image.
|
|
for TAG in "${TAGS[@]}"; do
|
|
docker tag butlerbot:$VERSION "$TAG"
|
|
done
|
|
|
|
# Create docker-compose.override.yml with the version.
|
|
cat > docker-compose.override.yml <<EOF
|
|
services:
|
|
butlerbot:
|
|
image: git.3t.network/3t.network/butlerbot:$VERSION
|
|
EOF
|
|
|
|
echo "docker-compose.override.yml created."
|
|
|
|
# Print build information.
|
|
echo "butlerbot:$VERSION built successfully."
|
|
echo "Tags:"
|
|
for TAG in "${TAGS[@]}"; do
|
|
echo " $TAG"
|
|
done
|
|
echo "Run 'docker compose up' to start the bot."
|