Files
multi_render_blender/release.sh
2026-02-27 10:36:58 +01:00

156 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
############################################
# Chargement du token
############################################
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
if [ -z "${GITEA_TOKEN:-}" ]; then
echo "Erreur: GITEA_TOKEN non defini. Creez un fichier .env avec GITEA_TOKEN=votre_token"
exit 1
fi
############################################
# Config
############################################
GITEA_URL="https://git.sorlinv.fr"
OWNER="sorlinv"
REPO="multi_render_blender"
PRODUCT_NAME="multi-render-blender"
############################################
# Version actuelle
############################################
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Version actuelle: v$CURRENT_VERSION"
echo ""
echo "Comment incrementer la version ?"
echo " 1) patch"
echo " 2) minor"
echo " 3) major"
echo " 4) garder ($CURRENT_VERSION)"
echo ""
read -p "Choix [1/2/3/4]: " BUMP_CHOICE
case "$BUMP_CHOICE" in
1) npm version patch --no-git-tag-version ;;
2) npm version minor --no-git-tag-version ;;
3) npm version major --no-git-tag-version ;;
4) echo "Version inchangee." ;;
*) echo "Choix invalide"; exit 1 ;;
esac
VERSION=$(node -p "require('./package.json').version")
TAG="v$VERSION"
if [ "$CURRENT_VERSION" = "$VERSION" ]; then
echo "Aucune modification de version."
else
echo "Nouvelle version: $VERSION"
fi
############################################
# Mise a jour version.json (robuste)
############################################
echo "Synchronisation de version.json..."
if command -v jq >/dev/null 2>&1; then
tmp=$(mktemp)
jq --arg v "$VERSION" '.str_version=$v' version.json > "$tmp"
mv "$tmp" version.json
else
node <<EOF
const fs = require('fs');
const file = 'version.json';
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
data.str_version = "$VERSION";
fs.writeFileSync(file, JSON.stringify(data, null, 4) + '\n');
EOF
fi
############################################
# Commit + tag local + push
############################################
git add package.json version.json
git commit -m "chore: release ${TAG}" || true
git tag -a "${TAG}" -m "Release ${TAG}"
git push
git push origin "${TAG}"
############################################
# Build
############################################
echo ""
echo "==> Build de la version $TAG"
rm -rf dist
npm run build
############################################
# ZIP
############################################
cd dist
if [ -d "linux-unpacked" ]; then
echo "Zip linux-unpacked..."
zip -r -q "${PRODUCT_NAME}-${VERSION}-linux-x64.zip" "linux-unpacked/"
fi
if [ -d "win-unpacked" ]; then
echo "Zip win-unpacked..."
zip -r -q "${PRODUCT_NAME}-${VERSION}-win-x64.zip" "win-unpacked/"
fi
cd ..
############################################
# Release Gitea
############################################
echo ""
echo "==> Upload de la release $TAG sur Gitea..."
RELEASE_RESPONSE=$(curl -s -X POST \
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"${TAG}\",
\"name\": \"${TAG}\",
\"body\": \"Release ${TAG}\",
\"draft\": false,
\"prerelease\": false
}")
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id // empty')
if [ -z "$RELEASE_ID" ]; then
echo "Erreur lors de la creation de la release:"
echo "$RELEASE_RESPONSE"
exit 1
fi
echo "Release creee (id: $RELEASE_ID)"
############################################
# Upload assets
############################################
for FILE in dist/${PRODUCT_NAME}-${VERSION}-*.zip; do
[ -f "$FILE" ] || continue
FILENAME=$(basename "$FILE")
echo "Upload de $FILENAME..."
curl -s -X POST \
"${GITEA_URL}/api/v1/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}&token=${GITEA_TOKEN}" \
-F "attachment=@${FILE}"
done
echo ""
echo "==> Release publiee : ${GITEA_URL}/${OWNER}/${REPO}/releases"
echo "Done!"