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

@@ -10,9 +10,12 @@ if [ -z "$VERSION" ]; then
fi
# -----------------------------
# SemVer validation
# -----------------------------
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if ! [[ "$VERSION" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
echo "Version must be SemVer: X.Y.Z"
exit 1
fi
@@ -22,8 +25,25 @@ TAG="v$VERSION"
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)
if [ "$BRANCH" != "main" ]; then
echo "Not on main branch"
@@ -31,16 +51,22 @@ if [ "$BRANCH" != "main" ]; then
fi
# -----------------------------
# Working tree clean?
# -----------------------------
if ! git diff --quiet; then
echo "Working tree not clean — commit first"
exit 1
fi
# -----------------------------
# Sync with remote
# -----------------------------
git fetch origin
LOCAL=$(git rev-parse main)
@@ -52,94 +78,132 @@ if [ "$LOCAL" != "$REMOTE" ]; then
fi
# -----------------------------
# Tag already exists?
# -----------------------------
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag already exists locally"
exit 1
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"
exit 1
fi
# -----------------------------
# Update versions.env
# versions.env update
# -----------------------------
if [ ! -f versions.env ]; then
echo "versions.env not found"
exit 1
fi
echo "Updating versions.env"
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
echo "APP_VERSION=${VERSION}" >> versions.env
fi
# -----------------------------
# Optional changelog entry
# CHANGELOG generation
# -----------------------------
if [ -f CHANGELOG.md ]; then
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
echo "Generating release notes from $LAST_TAG → HEAD"
git log $LAST_TAG..HEAD --pretty=format:"- %s" > RELEASE_NOTES.tmp
else
git log --pretty=format:"- %s" > RELEASE_NOTES.tmp
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
git add CHANGELOG.md
fi
# -----------------------------
# Commit version bump
# -----------------------------
git add versions.env
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"
# -----------------------------
# Create annotated 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"
# -----------------------------
# Optional: wait for CI success
# Optional CI wait
# -----------------------------
if [ -n "$GITEA_TOKEN" ]; then
echo "Checking CI status..."
REPO=$(git config --get remote.origin.url | sed 's#.*/##; s/.git$//')
OWNER=$(git config --get remote.origin.url | awk -F'[:/]' '{print $(NF-1)}')
URL=$(git config --get remote.origin.url)
REPO=$(basename "$URL" .git)
OWNER=$(basename "$(dirname "$URL")")
for i in {1..30}; do
STATUS=$(curl -s \
-H "Authorization: token $GITEA_TOKEN" \
"https://git.pi-farm.de/api/v1/repos/$OWNER/$REPO/actions/runs?event=push" \
| jq -r '.workflow_runs[0].status')
STATUS=$(curl -s
-H "Authorization: token $GITEA_TOKEN"
"[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 // empty')
```
echo "CI status: $STATUS"
[ "$STATUS" = "success" ] && break
sleep 5
```
done
fi