#!/bin/bash set -euo pipefail # Publishes bb64 to the Gitea Releases page for the repository. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" ARCH=$(uname -m) PROJECT="bb64" OUTPUT="${SCRIPT_DIR}/output" ARCH_ALIAS="amd64" if [ "$ARCH" = "aarch64" ]; then ARCH_ALIAS="arm64" fi # Get version from CMake timestamp VERSION=$(date +"%Y.%m%d.%H%M") TAG="v$VERSION" echo "Building version $VERSION" >&2 # build release version export CMAKE_BUILD_TYPE="Release" docker build \ -t "${PROJECT}-build" \ -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ --build-arg PROJECT="${PROJECT}" \ --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ --output "${OUTPUT}" \ "${SCRIPT_DIR}" if [ ! -f "${OUTPUT}/${PROJECT}" ]; then echo "Build failed." >&2 exit 1 fi cp "${OUTPUT}/${PROJECT}" "${OUTPUT}/${PROJECT}.${ARCH_ALIAS}" cp "${OUTPUT}/${PROJECT}" "${OUTPUT}/${PROJECT}.${ARCH}" # Find repo info from .git/config REPO_URL=$(git config --get remote.origin.url) if [[ ! $REPO_URL =~ gitea ]]; then echo "Remote origin is not a Gitea repository: $REPO_URL" >&2 exit 1 fi # Extract base URL, owner, and repo # Example: https://gitea.example.com/username/reponame.git BASE_URL=$(echo "$REPO_URL" | sed -E 's#(https?://[^/]+)/.*#\1#') OWNER=$(echo "$REPO_URL" | sed -E 's#.*/([^/]+)/[^/]+(\.git)?$#\1#') REPO=$(echo "$REPO_URL" | sed -E 's#.*/([^/]+)(\.git)?$#\1#') API_URL="$BASE_URL/api/v1/repos/$OWNER/$REPO" # Create release RELEASE_DATA=$(cat <&2 exit 1 fi # Create and push git tag echo "Creating git tag $TAG..." # Configure git identity if not set (for CI environments) if ! git config user.email >/dev/null 2>&1; then git config user.email "ci@gitea.jde.nz" git config user.name "CI Bot" fi # Check if tag already exists if git rev-parse "$TAG" >/dev/null 2>&1; then echo "Tag $TAG already exists, deleting it first..." git tag -d "$TAG" git push origin --delete "$TAG" || true fi git tag -a "$TAG" -m "Release $TAG" if ! git push origin "$TAG"; then echo "Failed to push tag $TAG to origin" >&2 # Try to delete local tag if push failed git tag -d "$TAG" exit 1 fi echo "Creating release $TAG on Gitea..." RELEASE_RESPONSE=$(curl -s -X POST "$API_URL/releases" \ -H "Content-Type: application/json" \ -H "Authorization: token $RELEASE_WRITE_TOKEN" \ -d "$RELEASE_DATA") echo "Release API response: $RELEASE_RESPONSE" RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) if [ -z "$RELEASE_ID" ]; then echo "Failed to create release on Gitea." >&2 echo "API URL: $API_URL/releases" >&2 echo "Release data: $RELEASE_DATA" >&2 exit 1 fi echo "Created release with ID: $RELEASE_ID" # Upload binaries and install.sh echo "Uploading assets to release..." for FILE in ${PROJECT}.${ARCH_ALIAS} ${PROJECT}.${ARCH} install.sh; do if [ -f "output/$FILE" ]; then filetoupload="output/$FILE" elif [ -f "$FILE" ]; then filetoupload="$FILE" else echo "Skipping $FILE - not found" continue fi echo "Uploading $filetoupload as $FILE..." # Auto-detect content type ctype=$(file --mime-type -b "$filetoupload") UPLOAD_RESPONSE=$(curl -s -X POST "$API_URL/releases/$RELEASE_ID/assets?name=$FILE" \ -H "Content-Type: $ctype" \ -H "Authorization: token $RELEASE_WRITE_TOKEN" \ --data-binary @"$filetoupload") if echo "$UPLOAD_RESPONSE" | grep -q '"id"'; then echo "✓ Uploaded $FILE to release $TAG as $ctype." else echo "✗ Failed to upload $FILE. Response: $UPLOAD_RESPONSE" >&2 exit 1 fi done echo "Published bb64 version $VERSION to $REPO_URL (tag $TAG) with binaries for $ARCH_ALIAS / $ARCH." #-------------------------------------------------------------------------------- echo "Publishing ${PROJECT} as tool to getpkg.xyz" # Create tool directory structure TOOLDIR="${OUTPUT}/tool" mkdir "${TOOLDIR}" cp "${OUTPUT}/${PROJECT}" "${TOOLDIR}/${PROJECT}" # Use getpkg to publish the tool GETPKG="${SCRIPT_DIR}/../getpkg/output/getpkg" if [ ! -f "$GETPKG" ]; then GETPKG="${SCRIPT_DIR}/../getpkg/getpkg" fi if [ -f "$GETPKG" ]; then echo "Publishing ${PROJECT} to getpkg.xyz using ${GETPKG}..." if "${GETPKG}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"; then echo "✓ Successfully published ${PROJECT} to getpkg.xyz" else echo "✗ Failed to publish ${PROJECT} to getpkg.xyz" >&2 exit 1 fi else echo "Warning: getpkg not found at $GETPKG, skipping tool publishing to getpkg.xyz" fi echo "✓ BB64 publish script completed successfully"