#!/usr/bin/env bash # Create a Gitea release and upload latest.zip for the current plugin version. # Usage: # ./create-release.sh # uses version from HSCompare.csproj # ./create-release.sh v1.0.3 # optional: override tag # # Token: put your Gitea token in .gitea-token (one line, token only) in this dir, # or run: GITEA_TOKEN=your_token ./create-release.sh # Create token at: Gitea → Settings → Applications → Generate New Token set -e BASE="http://brassnet.ddns.net:33983" OWNER="Dawnsorrow" REPO="HSCompare" ZIP_PATH="HSCompare/bin/Release/HSCompare/latest.zip" # Token: env var wins, then .gitea-token file (never commit that file) if [[ -z "${GITEA_TOKEN}" ]]; then if [[ -f ".gitea-token" ]]; then GITEA_TOKEN=$(cat .gitea-token | tr -d '\n\r') fi fi if [[ -z "${GITEA_TOKEN}" ]]; then echo "Set GITEA_TOKEN or create .gitea-token with your token, then run again." echo "Create token at: ${BASE}/user/settings/applications" exit 1 fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Tag: from first argument or from HSCompare.csproj if [[ -n "$1" ]]; then TAG="$1" else VER=$(sed -n 's/.*\([^<]*\)<\/Version>.*/\1/p' HSCompare/HSCompare.csproj 2>/dev/null | head -1) if [[ -z "$VER" ]]; then echo "Could not read version from HSCompare/HSCompare.csproj. Run: ./create-release.sh v1.0.x" exit 1 fi TAG="v${VER}" fi if [[ ! -f "$ZIP_PATH" ]]; then echo "Building release zip..." dotnet build -c Release -q fi echo "Creating release ${TAG}..." RESP=$(curl -s -w "\n%{http_code}" -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":\"HSCompare ${TAG} - WoW-style equipment comparison tooltips\"}" \ "${BASE}/api/v1/repos/${OWNER}/${REPO}/releases") HTTP_CODE=$(echo "$RESP" | tail -n1) BODY=$(echo "$RESP" | sed '$d') if [[ "$HTTP_CODE" != "201" && "$HTTP_CODE" != "200" ]]; then echo "Create release failed (HTTP ${HTTP_CODE}): $BODY" exit 1 fi RELEASE_ID=$(echo "$BODY" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) if [[ -z "$RELEASE_ID" ]]; then echo "Could not parse release id from: $BODY" exit 1 fi echo "Uploading latest.zip to release ${RELEASE_ID}..." UPLOAD_RESP=$(curl -s -w "\n%{http_code}" -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -F "attachment=@${ZIP_PATH}" \ "${BASE}/api/v1/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=latest.zip") UPLOAD_CODE=$(echo "$UPLOAD_RESP" | tail -n1) if [[ "$UPLOAD_CODE" != "201" && "$UPLOAD_CODE" != "200" ]]; then echo "Upload failed (HTTP ${UPLOAD_CODE}): $(echo "$UPLOAD_RESP" | sed '$d')" exit 1 fi # Update pluginmaster.json so Dalamud installer sees the new version VER_NO_V="${TAG#v}" ASSEMBLY_VER="${VER_NO_V}.0" DOWNLOAD_URL="${BASE}/${OWNER}/${REPO}/releases/download/${TAG}/latest.zip" LAST_UPDATE=$(date +%s) if [[ -f "pluginmaster.json" ]]; then sed -e "s/\"AssemblyVersion\":\"[^\"]*\"/\"AssemblyVersion\":\"${ASSEMBLY_VER}\"/" \ -e "s|${BASE}/${OWNER}/${REPO}/releases/download/v[^/]*/latest\\.zip|${DOWNLOAD_URL}|g" \ -e "s/\"LastUpdate\":\"[^\"]*\"/\"LastUpdate\":\"${LAST_UPDATE}\"/" \ pluginmaster.json > pluginmaster.json.tmp && mv pluginmaster.json.tmp pluginmaster.json echo "Updated pluginmaster.json (AssemblyVersion=${ASSEMBLY_VER}, LastUpdate=${LAST_UPDATE})." fi echo "Done. Release: ${BASE}/${OWNER}/${REPO}/releases/tag/${TAG}" echo "Push your changes (including pluginmaster.json) so the installer sees the update: git add . && git commit -m 'Release ${TAG}' && git push"