mirror of
https://codeberg.org/knightsub9/lxcafe.git
synced 2026-07-19 19:30:16 +02:00
Executable
+128
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
question_answered_with_yes() {
|
||||
local prompt="$1"
|
||||
local ans
|
||||
printf '%b\n Enter y or n and press Enter,\n abort with any other key ... [y/N]: ' "$prompt"
|
||||
read -r ans
|
||||
case "$ans" in
|
||||
y|Y) return 0 ;;
|
||||
n|N|"") return 1 ;;
|
||||
*) echo "Aborted."; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "Error: You have uncommitted local changes."
|
||||
echo "Please commit or stash them before releasing."
|
||||
echo ""
|
||||
echo "Uncommitted files:"
|
||||
git status --short
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Fetching latest changes..."
|
||||
git fetch origin
|
||||
|
||||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [ "$CURRENT_BRANCH" = "main" ]; then
|
||||
echo "Pulling latest from main..."
|
||||
git pull origin main || true
|
||||
else
|
||||
echo "Error: You must be on the main branch to create a release."
|
||||
echo "Current branch: $CURRENT_BRANCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION_FILE="VERSION"
|
||||
SCRIPT_FILE="post_installation_script/Nachinstallationsarbeiten_LC_Esslingen_XFCE.sh"
|
||||
|
||||
if [ ! -f "$VERSION_FILE" ]; then
|
||||
echo "Error: $VERSION_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENT_VERSION=$(cat "$VERSION_FILE" | tr -d '\n')
|
||||
|
||||
if [ ! -f "$SCRIPT_FILE" ]; then
|
||||
echo "Error: $SCRIPT_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENT_MAJOR=${CURRENT_VERSION#v}
|
||||
|
||||
if ! [[ "$CURRENT_VERSION" =~ ^v[0-9]+$ ]]; then
|
||||
echo "Error: Invalid version format in $VERSION_FILE. Expected v0, v1, v2, etc."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NEXT_VERSION=$((CURRENT_MAJOR + 1))
|
||||
NEXT_VERSION_STR="v$NEXT_VERSION"
|
||||
|
||||
RELEASE_BRANCH="release/$NEXT_VERSION_STR"
|
||||
|
||||
if git ls-remote --heads origin "$RELEASE_BRANCH" 2>/dev/null | grep -q .; then
|
||||
echo "Error: Branch $RELEASE_BRANCH already exists on remote."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if git rev-parse "$RELEASE_BRANCH" >/dev/null 2>&1; then
|
||||
echo "Branch $RELEASE_BRANCH exists locally."
|
||||
if question_answered_with_yes "Delete local branch and continue?"; then
|
||||
git branch -D "$RELEASE_BRANCH"
|
||||
else
|
||||
echo "Release aborted."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Current version: $CURRENT_VERSION"
|
||||
echo "Proposed version: $NEXT_VERSION_STR"
|
||||
echo "Release branch: $RELEASE_BRANCH"
|
||||
echo ""
|
||||
|
||||
if ! question_answered_with_yes "Confirm release version $NEXT_VERSION_STR?"; then
|
||||
echo "Release aborted."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Creating release branch $RELEASE_BRANCH..."
|
||||
git checkout -b "$RELEASE_BRANCH"
|
||||
|
||||
echo "$NEXT_VERSION_STR" > "$VERSION_FILE"
|
||||
|
||||
sed -i.bak "s/^SCRIPT_VERSION=.*/SCRIPT_VERSION=\"$NEXT_VERSION_STR\"/" "$SCRIPT_FILE"
|
||||
if [ -f "${SCRIPT_FILE}.bak" ]; then
|
||||
rm "${SCRIPT_FILE}.bak"
|
||||
fi
|
||||
|
||||
git add "$VERSION_FILE" "$SCRIPT_FILE"
|
||||
git commit -m "Release $NEXT_VERSION_STR"
|
||||
|
||||
echo ""
|
||||
echo "Release $NEXT_VERSION_STR prepared on branch $RELEASE_BRANCH."
|
||||
if question_answered_with_yes "Push release branch to origin?"; then
|
||||
git push -u origin "$RELEASE_BRANCH"
|
||||
echo ""
|
||||
echo "Branch pushed to origin."
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Create a PR from $RELEASE_BRANCH to main"
|
||||
echo " - Via web: Go to your git hosting and create a PR"
|
||||
echo " - Or: gh pr create --base main --head $RELEASE_BRANCH"
|
||||
echo ""
|
||||
echo "2. After PR is merged, create a tag:"
|
||||
echo " git checkout main && git pull"
|
||||
echo " git tag -a $NEXT_VERSION_STR -m \"Release $NEXT_VERSION_STR\""
|
||||
echo " git push origin $NEXT_VERSION_STR"
|
||||
echo ""
|
||||
echo "3. Gitea will create a release from the tag"
|
||||
else
|
||||
echo ""
|
||||
echo "Release prepared locally. Push manually with:"
|
||||
echo " git push -u origin $RELEASE_BRANCH"
|
||||
echo ""
|
||||
echo "Then create a PR to main via your git hosting."
|
||||
fi
|
||||
Reference in New Issue
Block a user