Sur demande uniquement (pas de trigger auto par commit) : build les 2 jars, zip, cree le tag/release via l'API Gitea et y attache le zip. Token passe en variable d'env GITEA_TOKEN, jamais stocke dans le repo. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
64 lines
2.3 KiB
Bash
64 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Build les 2 jars, zip, puis cree une release Gitea avec le zip attache.
|
|
#
|
|
# Usage :
|
|
# GITEA_TOKEN=xxxx ./scripts/release.sh 1.0.1 "Description de la release"
|
|
#
|
|
# Le token doit avoir le scope "repo" (Parametres -> Applications -> Generer un nouveau jeton).
|
|
# Ne JAMAIS commit le token. Passe-le uniquement en variable d'environnement.
|
|
|
|
set -euo pipefail
|
|
|
|
VERSION="${1:?Usage: release.sh <version> [notes]}"
|
|
NOTES="${2:-Release ${VERSION}}"
|
|
|
|
GITEA_HOST="https://gitea.louconnect.fr"
|
|
OWNER="Sar_Tron"
|
|
REPO="VoteNetwork"
|
|
TAG="v${VERSION}"
|
|
|
|
if [ -z "${GITEA_TOKEN:-}" ]; then
|
|
echo "Erreur : variable GITEA_TOKEN non definie." >&2
|
|
echo "Cree un token dans Gitea (Parametres > Applications, scope repo) puis :" >&2
|
|
echo " GITEA_TOKEN=xxxx ./scripts/release.sh ${VERSION}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
echo "==> Build Maven"
|
|
mvn -q clean package
|
|
|
|
echo "==> Preparation du zip de distribution"
|
|
rm -rf dist
|
|
mkdir -p dist
|
|
cp velocity/target/VoteNetwork-Velocity.jar dist/
|
|
cp spigot/target/VoteNetwork-Spigot.jar dist/
|
|
|
|
if command -v zip >/dev/null 2>&1; then
|
|
(cd dist && zip -q VoteNetwork.zip VoteNetwork-Velocity.jar VoteNetwork-Spigot.jar)
|
|
else
|
|
powershell -Command "Compress-Archive -Path dist/VoteNetwork-Velocity.jar,dist/VoteNetwork-Spigot.jar -DestinationPath dist/VoteNetwork.zip -Force"
|
|
fi
|
|
|
|
echo "==> Creation de la release Gitea ${TAG}"
|
|
RELEASE_JSON=$(curl -sf -X POST "${GITEA_HOST}/api/v1/repos/${OWNER}/${REPO}/releases" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"VoteNetwork ${VERSION}\",\"body\":$(printf '%s' "$NOTES" | python3 -c 'import json,sys;print(json.dumps(sys.stdin.read()))' 2>/dev/null || printf '"%s"' "$NOTES"),\"draft\":false,\"prerelease\":false}")
|
|
|
|
RELEASE_ID=$(printf '%s' "$RELEASE_JSON" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*')
|
|
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Erreur : creation de la release echouee." >&2
|
|
echo "$RELEASE_JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> Upload du zip (release id ${RELEASE_ID})"
|
|
curl -sf -X POST "${GITEA_HOST}/api/v1/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=VoteNetwork.zip" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@dist/VoteNetwork.zip" > /dev/null
|
|
|
|
echo "==> Fait : ${GITEA_HOST}/${OWNER}/${REPO}/releases/tag/${TAG}"
|