#!/usr/bin/env bash set -euo pipefail # ๐Ÿงช Load local environment overrides if [[ -f .localenv.sh ]]; then # If a custom path or other environment variables are needed, include them in .localenv.sh source .localenv.sh fi # ๐Ÿงญ Config VERSION=$(grep "^const.*version\ *=\ *" main.go | sed -E 's/.*"([^"]+)".*/\1/') TAG="v${VERSION}" BIN_NAME="x11proxy" DIST_DIR="dist/X11Proxy" ARCHIVE_NAME="X11Proxy-${VERSION}-linux-x86_64.tar.gz" REPO="ezterry/X11Proxy" GITEA_URL="https://git-hojo.devnull.name" if [[ -z "$VERSION" ]]; then echo "โŒ Failed to extract version from main.go" echo "please fix the version constant in main.go" exit 1 fi echo "$BIN_NAME build script (version: $VERSION)" # ๐Ÿงน Clean build artifacts clean() { rm -f "$BIN_NAME" rm -rf dist "$ARCHIVE_NAME" } # ๐Ÿ› ๏ธ Build binary build_binary() { echo "๐Ÿ”จ Building $BIN_NAME..." go build -ldflags "-X main.version=${VERSION}" -o "$BIN_NAME" . } # ๐Ÿ“ฆ Build distribution package build_dist() { clean build_binary echo "๐Ÿ“ฆ Creating distribution package..." mkdir -p "$DIST_DIR" cp "$BIN_NAME" hello_xclock.sh README.md LICENSE.md "$DIST_DIR" tar -czvf "$ARCHIVE_NAME" -C dist X11Proxy echo "โœ… Built: $ARCHIVE_NAME" } # ๐Ÿš€ Publish release to Gitea publish_release() { #verify we will not run into an issue from a missing jq command command -v jq >/dev/null || { echo "โŒ 'jq' is required but not installed. Please install it to continue." exit 1 } build_dist echo "๐Ÿ” Enter Gitea token (will not be saved):" read -r -s GITEA_TOKEN echo echo "๐Ÿท๏ธ Tagging release: $TAG" if git rev-parse "$TAG" >/dev/null 2>&1; then echo "โŒ Tag $TAG already exists" exit 1 fi git tag -a "$TAG" -m "Release $TAG" git push origin $TAG echo "๐Ÿ“ค Creating release on Gitea..." RELEASE_JSON=$(curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases" \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d @- <