101 lines
3.1 KiB
Bash
Executable File
101 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
PUBSPEC="pubspec.yaml"
|
|
|
|
line=$(grep "^version:" $PUBSPEC | awk '{print $2}')
|
|
before_plus="${line%%+*}" # 1.0.3
|
|
build="${line##*+}"
|
|
|
|
major=$(echo $before_plus | cut -d. -f1)
|
|
minor=$(echo $before_plus | cut -d. -f2)
|
|
patch=$(echo $before_plus | cut -d. -f3)
|
|
|
|
patch=$((patch + 1))
|
|
|
|
new="${major}.${minor}.${patch}"
|
|
|
|
echo "Neue Version: $new"
|
|
|
|
sed -i "s/^version: .*/version: ${new}/" "$PUBSPEC"
|
|
|
|
flutter clean
|
|
flutter pub get
|
|
flutter build apk --release
|
|
mkdir -p release
|
|
cp build/app/outputs/flutter-apk/app-release.apk ./release/eggtimer.apk
|
|
echo "APK built and copied to ./release/eggtimer.apk"
|
|
GITEA_URL="https://git.ude-consult.de"
|
|
GITEA_TOKEN="6ea286299e8e081d9923d5deea2fbd91ad83dc8e"
|
|
OWNER="Arnold"
|
|
REPO="EggTimer"
|
|
APK_PATH="release/eggtimer.apk"
|
|
|
|
# Version z.B. aus Datei oder Argument
|
|
VERSION_TAG=$(grep "^version:" pubspec.yaml | awk '{print $2}')
|
|
git commit -a -m"Version auf ${VERSION_TAG} gesetzt"
|
|
git push
|
|
|
|
RELEASE_TITLE="EggTimer ${VERSION_TAG}"
|
|
RELEASE_BODY="Automatisch erstelltes Release ${VERSION_TAG}."
|
|
|
|
# 1. Release anlegen
|
|
create_release_response=$(curl -sS -X POST \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases" \
|
|
-d "{
|
|
\"tag_name\": \"${VERSION_TAG}\",
|
|
\"target\": \"main\",
|
|
\"title\": \"${RELEASE_TITLE}\",
|
|
\"note\": \"${RELEASE_BODY}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}")
|
|
|
|
release_id=$(echo "$create_release_response" | jq -r '.id')
|
|
|
|
if [[ "$release_id" == "null" || -z "$release_id" ]]; then
|
|
echo "Fehler: Konnte Release-ID nicht auslesen."
|
|
echo "$create_release_response"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release ${VERSION_TAG} erstellt, ID=${release_id}"
|
|
|
|
APK_FILENAME="eggtimer-${VERSION_TAG}.apk"
|
|
|
|
# Alte Assets entfernen, damit nur die APK im Release bleibt
|
|
existing_assets=$(curl -sS \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases/${release_id}/assets")
|
|
|
|
echo "$existing_assets" | jq -r '.[] | [.id, .name] | @tsv' | while IFS=$'\t' read -r asset_id asset_name; do
|
|
echo "Entferne altes Asset: ${asset_name}"
|
|
curl -sS -X DELETE \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases/${release_id}/assets/${asset_id}" >/dev/null
|
|
done
|
|
|
|
# 2. APK hochladen
|
|
curl -sS -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${APK_PATH};filename=${APK_FILENAME}" \
|
|
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases/${release_id}/assets"
|
|
|
|
echo "APK hochgeladen."
|
|
|
|
# Nur die drei neuesten Releases behalten, ältere löschen
|
|
all_releases=$(curl -sS \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases")
|
|
|
|
echo "$all_releases" | jq -r 'sort_by(.created_at) | .[0:-3] | .[]? | "\(.id)\t\(.tag_name)"' | while IFS=$'\t' read -r old_id old_tag; do
|
|
echo "Lösche altes Release: ${old_tag} (ID ${old_id})"
|
|
curl -sS -X DELETE \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases/${old_id}" >/dev/null
|
|
done
|
|
|
|
echo "Ältere Releases bereinigt; es bleiben die letzten drei."
|