feat: Implement brand-aware release creation for Agravity
Some checks failed
Tests & Quality Checks / Test on Python 3.11 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.11-1 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12-1 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.10 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.11-2 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12-2 (push) Has been cancelled
Tests & Quality Checks / Build Artifacts (push) Has been cancelled
Tests & Quality Checks / Build Artifacts-1 (push) Has been cancelled

- Added support for multiple brands in release scripts, allowing for branded artifacts.
- Introduced brand configuration management with JSON files for each brand.
- Created a new `brand_config.py` script to handle brand-specific logic and asset resolution.
- Updated `create_release.ps1` and `create_release.sh` scripts to utilize brand configurations and generate release manifests.
- Added unit tests for brand configuration loading and release manifest generation.
- Introduced `agravity` brand with its specific configuration in `agravity.json`.
This commit is contained in:
claudi 2026-03-10 16:18:28 +01:00
parent b988532aaa
commit fd69996c53
8 changed files with 552 additions and 409 deletions

View file

@ -1,31 +1,33 @@
#!/bin/bash
# Create Forgejo Release with Binary Assets
# Usage: ./create_release.sh -v 1.0.0
# Uses your Forgejo credentials (same as git)
# First run will prompt for credentials and save them to this session
# Create or update a shared Forgejo release with branded macOS assets.
set -e
# Parse arguments
VERSION=""
FORGEJO_USER=""
FORGEJO_PASS=""
BRANDS=("agravity")
FORGEJO_USER="${FORGEJO_USER}"
FORGEJO_PASS="${FORGEJO_PASS}"
FORGEJO_URL="https://git.him-tools.de"
REPO="HIM-public/webdrop-bridge"
DMG_PATH="build/dist/macos/WebDropBridge.dmg"
CHECKSUM_PATH="build/dist/macos/WebDropBridge.dmg.sha256"
CLEAR_CREDS=false
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
BRAND_HELPER="$PROJECT_ROOT/build/scripts/brand_config.py"
MANIFEST_OUTPUT="$PROJECT_ROOT/build/dist/release-manifest.json"
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version) VERSION="$2"; shift 2;;
-u|--url) FORGEJO_URL="$2"; shift 2;;
--clear-credentials) CLEAR_CREDS=true; shift;;
*) echo "Unknown option: $1"; exit 1;;
-v|--version) VERSION="$2"; shift 2 ;;
-u|--url) FORGEJO_URL="$2"; shift 2 ;;
--brand) BRANDS+=("$2"); shift 2 ;;
--clear-credentials) CLEAR_CREDS=true; shift ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# Handle --clear-credentials flag
if [ ${#BRANDS[@]} -gt 1 ] && [ "${BRANDS[0]}" = "agravity" ]; then
BRANDS=("${BRANDS[@]:1}")
fi
if [ "$CLEAR_CREDS" = true ]; then
unset FORGEJO_USER
unset FORGEJO_PASS
@ -33,127 +35,95 @@ if [ "$CLEAR_CREDS" = true ]; then
exit 0
fi
# Load credentials from environment
FORGEJO_USER="${FORGEJO_USER}"
FORGEJO_PASS="${FORGEJO_PASS}"
# Verify required parameters
if [ -z "$VERSION" ]; then
echo "ERROR: Version parameter required" >&2
echo "Usage: $0 -v VERSION [-u FORGEJO_URL]" >&2
echo "Example: $0 -v 1.0.0" >&2
exit 1
VERSION="$(python3 -c "from pathlib import Path; import sys; sys.path.insert(0, str(Path(r'$PROJECT_ROOT/build/scripts').resolve())); from version_utils import get_current_version; print(get_current_version())")"
fi
# If no credentials, prompt user interactively
if [ -z "$FORGEJO_USER" ] || [ -z "$FORGEJO_PASS" ]; then
echo "Forgejo credentials not found. Enter your credentials:"
if [ -z "$FORGEJO_USER" ]; then
read -p "Username: " FORGEJO_USER
read -r -p "Username: " FORGEJO_USER
fi
if [ -z "$FORGEJO_PASS" ]; then
read -sp "Password: " FORGEJO_PASS
read -r -s -p "Password: " FORGEJO_PASS
echo ""
fi
# Export for this session
export FORGEJO_USER
export FORGEJO_PASS
echo "[OK] Credentials saved to this shell session"
echo "Tip: Credentials will persist until you close the terminal or run: $0 --clear-credentials"
fi
# Verify files exist
if [ ! -f "$DMG_PATH" ]; then
echo "ERROR: DMG file not found at $DMG_PATH"
ARTIFACTS=()
for BRAND in "${BRANDS[@]}"; do
BRAND_JSON=$(python3 "$BRAND_HELPER" show --brand "$BRAND")
BRAND_ID=$(printf '%s' "$BRAND_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["brand_id"])')
ASSET_PREFIX=$(printf '%s' "$BRAND_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["asset_prefix"])')
DMG_PATH="$PROJECT_ROOT/build/dist/macos/$BRAND_ID/${ASSET_PREFIX}-${VERSION}-macos-universal.dmg"
CHECKSUM_PATH="$DMG_PATH.sha256"
if [ -f "$DMG_PATH" ]; then
ARTIFACTS+=("$DMG_PATH")
[ -f "$CHECKSUM_PATH" ] && ARTIFACTS+=("$CHECKSUM_PATH")
DMG_SIZE=$(du -m "$DMG_PATH" | cut -f1)
echo "macOS artifact: $(basename "$DMG_PATH") ($DMG_SIZE MB)"
fi
done
python3 "$BRAND_HELPER" release-manifest --version "$VERSION" --output "$MANIFEST_OUTPUT" --brands "${BRANDS[@]}" >/dev/null
[ -f "$MANIFEST_OUTPUT" ] && ARTIFACTS+=("$MANIFEST_OUTPUT")
if [ ${#ARTIFACTS[@]} -eq 0 ]; then
echo "ERROR: No macOS artifacts found"
exit 1
fi
if [ ! -f "$CHECKSUM_PATH" ]; then
echo "ERROR: Checksum file not found at $CHECKSUM_PATH"
exit 1
fi
echo "Creating WebDropBridge $VERSION release on Forgejo..."
# Get file info
DMG_SIZE=$(du -m "$DMG_PATH" | cut -f1)
CHECKSUM=$(cat "$CHECKSUM_PATH")
echo "File: WebDropBridge.dmg ($DMG_SIZE MB)"
echo "Checksum: ${CHECKSUM:0:16}..."
# Create basic auth
BASIC_AUTH=$(echo -n "${FORGEJO_USER}:${FORGEJO_PASS}" | base64)
# Step 1: Create release
echo ""
echo "Creating release v$VERSION..."
RELEASE_URL="$FORGEJO_URL/api/v1/repos/$REPO/releases"
RELEASE_LOOKUP_URL="$FORGEJO_URL/api/v1/repos/$REPO/releases/tags/v$VERSION"
RELEASE_DATA=$(cat <<EOF
RESPONSE=$(curl -s -H "Authorization: Basic $BASIC_AUTH" "$RELEASE_LOOKUP_URL")
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
if [ -z "$RELEASE_ID" ]; then
RELEASE_DATA=$(cat <<EOF
{
"tag_name": "v$VERSION",
"name": "WebDropBridge v$VERSION",
"body": "WebDropBridge v$VERSION\n\nChecksum: $CHECKSUM",
"body": "Shared branded release for WebDrop Bridge v$VERSION",
"draft": false,
"prerelease": false
}
EOF
)
RESPONSE=$(curl -s -X POST \
-H "Authorization: Basic $BASIC_AUTH" \
-H "Content-Type: application/json" \
-d "$RELEASE_DATA" \
"$RELEASE_URL")
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
RESPONSE=$(curl -s -X POST \
-H "Authorization: Basic $BASIC_AUTH" \
-H "Content-Type: application/json" \
-d "$RELEASE_DATA" \
"$RELEASE_URL")
RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
fi
if [ -z "$RELEASE_ID" ]; then
echo "ERROR creating release:"
echo "ERROR creating or finding release"
echo "$RESPONSE"
exit 1
fi
echo "[OK] Release created (ID: $RELEASE_ID)"
# Step 2: Upload DMG as asset
echo "Uploading executable asset..."
UPLOAD_URL="$FORGEJO_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets"
for ARTIFACT in "${ARTIFACTS[@]}"; do
HTTP_CODE=$(curl -s -w "%{http_code}" -X POST \
-H "Authorization: Basic $BASIC_AUTH" \
-F "attachment=@$ARTIFACT" \
"$UPLOAD_URL" \
-o /tmp/curl_response.txt)
HTTP_CODE=$(curl -s -w "%{http_code}" -X POST \
-H "Authorization: Basic $BASIC_AUTH" \
-F "attachment=@$DMG_PATH" \
"$UPLOAD_URL" \
-o /tmp/curl_response.txt)
if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 200 ]; then
echo "[OK] DMG uploaded"
else
echo "ERROR uploading DMG (HTTP $HTTP_CODE)"
cat /tmp/curl_response.txt
exit 1
fi
# Step 3: Upload checksum as asset
echo "Uploading checksum asset..."
HTTP_CODE=$(curl -s -w "%{http_code}" -X POST \
-H "Authorization: Basic $BASIC_AUTH" \
-F "attachment=@$CHECKSUM_PATH" \
"$UPLOAD_URL" \
-o /tmp/curl_response.txt)
if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 200 ]; then
echo "[OK] Checksum uploaded"
else
echo "ERROR uploading checksum (HTTP $HTTP_CODE)"
cat /tmp/curl_response.txt
exit 1
fi
if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 200 ]; then
echo "[OK] Uploaded $(basename "$ARTIFACT")"
else
echo "ERROR uploading $(basename "$ARTIFACT") (HTTP $HTTP_CODE)"
cat /tmp/curl_response.txt
exit 1
fi
done
echo ""
echo "[OK] Release complete!"