#!/bin/bash
set -e
cd "$(dirname "$0")/.."
VERSION=$(git describe --tags --abbrev=0 2>/dev/null)
if [ -z "$VERSION" ]; then
echo "No git tag found. Create one first: git tag -a v1.0.0 -m 'v1.0.0'"
exit 1
fi
ARCH="$(uname -m)"
case "$ARCH" in
x86_64)
TARGET="x86_64-unknown-linux-gnu"
SUFFIX="linux-x64"
;;
aarch64)
TARGET="aarch64-unknown-linux-gnu"
SUFFIX="linux-arm64"
;;
*)
echo "Unsupported architecture: ${ARCH}"
exit 1
esac
DIST="dist/${VERSION}"
mkdir -p "$DIST"
echo "=== AtomCode Linux Release ${VERSION} ==="
echo "Target: ${TARGET}"
echo "Architecture: ${ARCH}"
echo ""
if [ -d webui ] && command -v npm >/dev/null 2>&1; then
echo "Building webui frontend..."
(cd webui && npm ci && npm run build)
else
echo "warning: skipping webui build (npm not found or webui/ missing); using committed webui/dist" >&2
fi
echo ""
echo "[1/2] Building ${TARGET} (native)..."
cargo build --release --target "$TARGET"
echo "[2/2] Copying artifacts..."
cp "target/${TARGET}/release/atomcode" "${DIST}/atomcode-${VERSION}-${SUFFIX}"
cp "target/${TARGET}/release/atomcode-daemon" "${DIST}/atomcode-daemon-${VERSION}-${SUFFIX}"
echo " -> ${DIST}/atomcode-${VERSION}-${SUFFIX}"
echo " -> ${DIST}/atomcode-daemon-${VERSION}-${SUFFIX}"
echo ""
echo "=== Packaging ==="
cd "$DIST"
rm -f *${SUFFIX}*.tar.gz 2>/dev/null
for f in atomcode-*${SUFFIX} atomcode-daemon-*${SUFFIX}; do
[ -f "$f" ] || continue
chmod +x "$f"
tar czf "${f}.tar.gz" "$f"
echo " -> ${f}.tar.gz"
done
echo ""
echo "=== SHA256 ==="
sha256sum *${SUFFIX}*.tar.gz | tee -a checksums.txt
echo ""
echo "Done. Release artifacts:"
ls -lh *${SUFFIX}*.tar.gz