Initial commit: Add install scripts and README
This commit is contained in:
201
push-release.sh
Executable file
201
push-release.sh
Executable file
@@ -0,0 +1,201 @@
|
||||
#!/bin/bash
|
||||
# push-release.sh - Push an existing release to Gitea
|
||||
# Usage: ./push-release.sh --version v1.0.0 --gitea-token TOKEN
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
BINARY_NAME="aideris-cli"
|
||||
GITEA_URL="https://gitea.clickthings.net"
|
||||
REPO_OWNER="whuang"
|
||||
REPO_NAME="aideris-cli-dist"
|
||||
|
||||
# Parse arguments
|
||||
VERSION=""
|
||||
GITEA_TOKEN=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--version)
|
||||
VERSION="$2"
|
||||
shift 2
|
||||
;;
|
||||
--gitea-token)
|
||||
GITEA_TOKEN="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Error: --version is required"
|
||||
echo "Usage: ./push-release.sh --version v1.0.0 --gitea-token TOKEN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
echo "Error: --gitea-token is required"
|
||||
echo "Usage: ./push-release.sh --version v1.0.0 --gitea-token TOKEN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BUILD_DIR="dist/${VERSION}"
|
||||
|
||||
if [ ! -d "$BUILD_DIR" ]; then
|
||||
echo "Error: Build directory not found: $BUILD_DIR"
|
||||
echo "Run the build first to create binaries"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "========================================"
|
||||
echo " Aideris CLI Release Push"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
echo "Version: $VERSION"
|
||||
echo "Build dir: $BUILD_DIR"
|
||||
echo ""
|
||||
|
||||
# Check if release notes exist
|
||||
RELEASE_NOTES="${BUILD_DIR}/RELEASE_NOTES.md"
|
||||
if [ ! -f "$RELEASE_NOTES" ]; then
|
||||
echo "Warning: Release notes not found at $RELEASE_NOTES"
|
||||
echo "Creating default release notes..."
|
||||
cat > "$RELEASE_NOTES" << EOF
|
||||
# Aideris CLI ${VERSION}
|
||||
|
||||
## Installation
|
||||
|
||||
### Quick Install
|
||||
\`\`\`bash
|
||||
curl -fsSL https://gitea.clickthings.net/${REPO_OWNER}/${REPO_NAME}/raw/branch/main/install.sh | sh
|
||||
\`\`\`
|
||||
|
||||
### Manual Download
|
||||
Download the binary for your platform from the Assets below.
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Check if checksums exist
|
||||
CHECKSUMS_FILE="${BUILD_DIR}/checksums.txt"
|
||||
if [ ! -f "$CHECKSUMS_FILE" ]; then
|
||||
echo "Generating checksums..."
|
||||
cd "$BUILD_DIR"
|
||||
sha256sum ${BINARY_NAME}-* > checksums.txt 2>/dev/null || true
|
||||
cd - > /dev/null
|
||||
fi
|
||||
|
||||
echo "Pushing to Gitea..."
|
||||
|
||||
# Function to make API calls with error handling
|
||||
gitea_api() {
|
||||
local method=$1
|
||||
local endpoint=$2
|
||||
local data=$3
|
||||
|
||||
if [ -z "$data" ]; then
|
||||
curl -fsSL -X "$method" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}${endpoint}" 2>&1
|
||||
else
|
||||
curl -fsSL -X "$method" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$data" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}${endpoint}" 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if release already exists
|
||||
echo "Checking for existing release..."
|
||||
EXISTING_RELEASE=$(gitea_api "GET" "/releases/tags/${VERSION}" 2>/dev/null || echo "{}")
|
||||
RELEASE_ID=$(echo "$EXISTING_RELEASE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
echo " ✓ Found existing release: ID $RELEASE_ID"
|
||||
else
|
||||
echo " Creating new release..."
|
||||
|
||||
# Escape release notes for JSON
|
||||
ESCAPED_BODY=$(cat "$RELEASE_NOTES" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read())[1:-1])' 2>/dev/null || cat "$RELEASE_NOTES" | sed 's/"/\\"/g' | tr '\n' ' ')
|
||||
|
||||
RELEASE_PAYLOAD=$(cat << EOF
|
||||
{
|
||||
"tag_name": "${VERSION}",
|
||||
"name": "${VERSION}",
|
||||
"body": "${ESCAPED_BODY}",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
CREATE_RESPONSE=$(gitea_api "POST" "/releases" "$RELEASE_PAYLOAD" 2>&1 || true)
|
||||
RELEASE_ID=$(echo "$CREATE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
echo " ✓ Release created: ID $RELEASE_ID"
|
||||
else
|
||||
echo " ✗ Failed to create release"
|
||||
echo "Response: $CREATE_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get list of existing assets
|
||||
echo ""
|
||||
echo "Fetching existing assets..."
|
||||
EXISTING_ASSETS=$(gitea_api "GET" "/releases/${RELEASE_ID}/assets" 2>/dev/null || echo "[]")
|
||||
|
||||
# Upload assets
|
||||
echo ""
|
||||
echo "Uploading assets..."
|
||||
|
||||
upload_count=0
|
||||
skip_count=0
|
||||
|
||||
for asset in ${BUILD_DIR}/${BINARY_NAME}-* ${BUILD_DIR}/checksums.txt; do
|
||||
if [ -f "$asset" ]; then
|
||||
FILENAME=$(basename "$asset")
|
||||
|
||||
# Check if asset already exists
|
||||
ASSET_EXISTS=$(echo "$EXISTING_ASSETS" | grep -o "\"name\":\"${FILENAME}\"" | head -1 || echo "")
|
||||
|
||||
if [ -n "$ASSET_EXISTS" ]; then
|
||||
echo " ⊘ Skipping (exists): $FILENAME"
|
||||
skip_count=$((skip_count + 1))
|
||||
else
|
||||
echo " ↑ Uploading: $FILENAME..."
|
||||
|
||||
UPLOAD_RESPONSE=$(curl -fsSL -X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"$asset" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets?name=${FILENAME}" 2>&1 || true)
|
||||
|
||||
UPLOADED_ID=$(echo "$UPLOAD_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||
|
||||
if [ -n "$UPLOADED_ID" ]; then
|
||||
echo " ✓ Uploaded: $FILENAME"
|
||||
upload_count=$((upload_count + 1))
|
||||
else
|
||||
echo " ✗ Failed to upload: $FILENAME"
|
||||
echo " Response: $UPLOAD_RESPONSE"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "========================================"
|
||||
echo " Push Complete"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
echo "Uploaded: $upload_count asset(s)"
|
||||
echo "Skipped: $skip_count existing asset(s)"
|
||||
echo ""
|
||||
echo "Release URL: ${GITEA_URL}/${REPO_OWNER}/${REPO_NAME}/releases/tag/${VERSION}"
|
||||
Reference in New Issue
Block a user