rebuild release.sh
Some checks failed
Docker Build Smart Logic / Build amd64 & arm64 (push) Has been cancelled

This commit is contained in:
2026-02-09 19:49:34 +01:00
parent db01f706d3
commit a2032e1f46

View File

@@ -4,17 +4,20 @@ set -e
VERSION="$1" VERSION="$1"
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then
echo "Usage: ./release.sh <semver>" echo "Usage: ./release.sh <semver>"
echo "Example: ./release.sh 1.4.0" echo "Example: ./release.sh 1.4.0"
exit 1 exit 1
fi fi
# ----------------------------- # -----------------------------
# SemVer validation # SemVer validation
# ----------------------------- # -----------------------------
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version must be SemVer: X.Y.Z" if ! [[ "$VERSION" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
exit 1 echo "Version must be SemVer: X.Y.Z"
exit 1
fi fi
TAG="v$VERSION" TAG="v$VERSION"
@@ -22,125 +25,186 @@ TAG="v$VERSION"
echo "=== Release $TAG ===" echo "=== Release $TAG ==="
# ----------------------------- # -----------------------------
# Branch check
# portable sed
# ----------------------------- # -----------------------------
sedi() {
if sed --version >/dev/null 2>&1; then
sed -i "$@"
else
sed -i '' "$@"
fi
}
# -----------------------------
# Branch check
# -----------------------------
BRANCH=$(git rev-parse --abbrev-ref HEAD) BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" != "main" ]; then if [ "$BRANCH" != "main" ]; then
echo "Not on main branch" echo "Not on main branch"
exit 1 exit 1
fi fi
# ----------------------------- # -----------------------------
# Working tree clean? # Working tree clean?
# ----------------------------- # -----------------------------
if ! git diff --quiet; then if ! git diff --quiet; then
echo "Working tree not clean — commit first" echo "Working tree not clean — commit first"
exit 1 exit 1
fi fi
# ----------------------------- # -----------------------------
# Sync with remote # Sync with remote
# ----------------------------- # -----------------------------
git fetch origin git fetch origin
LOCAL=$(git rev-parse main) LOCAL=$(git rev-parse main)
REMOTE=$(git rev-parse origin/main) REMOTE=$(git rev-parse origin/main)
if [ "$LOCAL" != "$REMOTE" ]; then if [ "$LOCAL" != "$REMOTE" ]; then
echo "Local main not in sync with origin/main" echo "Local main not in sync with origin/main"
exit 1 exit 1
fi fi
# ----------------------------- # -----------------------------
# Tag already exists? # Tag already exists?
# ----------------------------- # -----------------------------
if git rev-parse "$TAG" >/dev/null 2>&1; then if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag already exists locally" echo "Tag already exists locally"
exit 1 exit 1
fi fi
if git ls-remote --tags origin | grep -q "$TAG"; then if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
echo "Tag already exists on remote" echo "Tag already exists on remote"
exit 1 exit 1
fi fi
# ----------------------------- # -----------------------------
# Update versions.env
# versions.env update
# ----------------------------- # -----------------------------
if [ ! -f versions.env ]; then
echo "versions.env not found"
exit 1
fi
echo "Updating versions.env" echo "Updating versions.env"
if grep -q "^APP_VERSION=" versions.env; then if grep -q "^APP_VERSION=" versions.env; then
sed -i "s/^APP_VERSION=.*/APP_VERSION=${VERSION}/" versions.env sedi "s/^APP_VERSION=.*/APP_VERSION=${VERSION}/" versions.env
else else
echo "APP_VERSION=${VERSION}" >> versions.env echo "APP_VERSION=${VERSION}" >> versions.env
fi fi
# ----------------------------- # -----------------------------
# Optional changelog entry
# CHANGELOG generation
# ----------------------------- # -----------------------------
if [ -f CHANGELOG.md ]; then if [ -f CHANGELOG.md ]; then
echo "Updating CHANGELOG.md" echo "Updating CHANGELOG.md"
DATE=$(date +%Y-%m-%d)
sed -i "1i ## $VERSION - $DATE\n- release\n" CHANGELOG.md
git add CHANGELOG.md
fi
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
if [ -n "$LAST_TAG" ]; then if [ -n "$LAST_TAG" ]; then
echo "Generating release notes from $LAST_TAG → HEAD" git log $LAST_TAG..HEAD --pretty=format:"- %s" > RELEASE_NOTES.tmp
git log $LAST_TAG..HEAD --pretty=format:"- %s" > RELEASE_NOTES.tmp
else else
git log --pretty=format:"- %s" > RELEASE_NOTES.tmp git log --pretty=format:"- %s" > RELEASE_NOTES.tmp
fi fi
echo -e "\n## $VERSION\n" | cat - RELEASE_NOTES.tmp >> CHANGELOG.md DATE=$(date +%Y-%m-%d)
{
echo "## $VERSION - $DATE"
cat RELEASE_NOTES.tmp
echo
cat CHANGELOG.md
} > CHANGELOG.new
mv CHANGELOG.new CHANGELOG.md
rm RELEASE_NOTES.tmp rm RELEASE_NOTES.tmp
git add CHANGELOG.md
fi
# ----------------------------- # -----------------------------
# Commit version bump # Commit version bump
# ----------------------------- # -----------------------------
git add versions.env git add versions.env
git commit -m "release: $VERSION" git commit -m "release: $VERSION"
# ----------------------------- # -----------------------------
# Push main → triggers edge build
# -----------------------------
git push origin main
# Push main → edge build
# -----------------------------
git push origin main
echo "Main pushed — edge build will run" echo "Main pushed — edge build will run"
# ----------------------------- # -----------------------------
# Create annotated tag # Create annotated tag
# ----------------------------- # -----------------------------
git tag -a "$TAG" -m "Release $TAG" git tag -a "$TAG" -m "Release $TAG"
# ----------------------------- # -----------------------------
# Push tag → triggers release build
# -----------------------------
git push origin "$TAG"
# Push tag → release build
# -----------------------------
git push origin "$TAG"
echo "Tag pushed — release build triggered" echo "Tag pushed — release build triggered"
# ----------------------------- # -----------------------------
# Optional: wait for CI success
# Optional CI wait
# ----------------------------- # -----------------------------
if [ -n "$GITEA_TOKEN" ]; then if [ -n "$GITEA_TOKEN" ]; then
echo "Checking CI status..." echo "Checking CI status..."
REPO=$(git config --get remote.origin.url | sed 's#.*/##; s/.git$//') URL=$(git config --get remote.origin.url)
OWNER=$(git config --get remote.origin.url | awk -F'[:/]' '{print $(NF-1)}') REPO=$(basename "$URL" .git)
OWNER=$(basename "$(dirname "$URL")")
for i in {1..30}; do for i in {1..30}; do
STATUS=$(curl -s \ STATUS=$(curl -s
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN"
"https://git.pi-farm.de/api/v1/repos/$OWNER/$REPO/actions/runs?event=push" \ "[https://git.pi-farm.de/api/v1/repos/$OWNER/$REPO/actions/runs](https://git.pi-farm.de/api/v1/repos/$OWNER/$REPO/actions/runs)"
| jq -r '.workflow_runs[0].status') | jq -r '.workflow_runs[0].status // empty')
echo "CI status: $STATUS" ```
[ "$STATUS" = "success" ] && break echo "CI status: $STATUS"
sleep 5 [ "$STATUS" = "success" ] && break
done sleep 5
```
done
fi fi
echo "=== Release complete ===" echo "=== Release complete ==="