diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..276c201 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,67 @@ +name: Auto Build + +on: + push: + branches: + - main + tags: + - 'alpha*' + - 'beta*' + - 'v*' + +jobs: + build: + name: Build binaries + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + - uses: actions/checkout@v3 + + - uses: dtolnay/rust-toolchain@stable + + - name: Build & Install Binary + shell: bash + env: + OS_NAME: ${{ runner.os }} + run: | + cargo install --path . --root dist + if [[ "$OS_NAME" == "Windows" ]]; then + mv dist/bin/pipe.exe pipe-windows-amd64.exe + elif [[ "$OS_NAME" == "macOS" ]]; then + cp dist/bin/pipe pipe-macos-amd64 + else + cp dist/bin/pipe pipe-linux-amd64 + fi + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: pipe-${{ runner.os }} + path: pipe-* + + release: + name: Upload Release + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') # ⬅️ hanya jalan saat push tag + + steps: + - name: Download All Artifacts + uses: actions/download-artifact@v4 + with: + path: ./dist + + - name: Flatten Artifact Folder + run: | + find ./dist -type f -exec cp {} . \; + + - name: Upload to GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: | + pipe-* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 854d1f3..4a15a5c 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,7 @@ Download pre-built binaries for your platform from the [latest release](https:// #### Linux/macOS Installation ```bash # Download the binary (replace URL with your platform's binary) -wget https://github.com/PipeNetwork/pipe/releases/latest/download/pipe-linux-amd64 - -# Make it executable -chmod +x pipe-linux-amd64 - -# Move to PATH -sudo mv pipe-linux-amd64 /usr/local/bin/pipe +sudo wget -O /usr/local/bin/pipe https://github.com/PipeNetwork/pipe/releases/latest/download/pipe-linux-amd64 && chmod +x /usr/local/bin/pipe # Verify installation pipe --version diff --git a/setup.sh b/setup.sh index 12ede39..99a3f10 100644 --- a/setup.sh +++ b/setup.sh @@ -1,7 +1,8 @@ #!/bin/bash -set -e +set -euo pipefail +# Color codes GREEN='\033[0;32m' RED='\033[0;31m' CYAN='\033[0;36m' @@ -11,6 +12,12 @@ NC='\033[0m' # No Color echo -e "${CYAN}🎯 Installing system dependencies...${NC}" sudo apt update && sudo apt install -y build-essential pkg-config libssl-dev git curl +# Version check helper +version_lt() { + [ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" != "$2" ] +} + +# Rust install/check MIN_RUST_VERSION="1.70.0" should_install_rust=false @@ -18,11 +25,11 @@ if command -v rustc &> /dev/null && command -v cargo &> /dev/null; then INSTALLED_RUST_VERSION=$(rustc --version | awk '{print $2}') echo -e "${CYAN}🔍 Detected rustc ${INSTALLED_RUST_VERSION}${NC}" - if [ "$(printf '%s\n' "$INSTALLED_RUST_VERSION" "$MIN_RUST_VERSION" | sort -V | head -n1)" != "$MIN_RUST_VERSION" ]; then - echo -e "${YELLOW}⚠️ Rust version is too old (< ${MIN_RUST_VERSION}). Updating via rustup...${NC}" + if version_lt "$INSTALLED_RUST_VERSION" "$MIN_RUST_VERSION"; then + echo -e "${YELLOW}⚠️ Rust version too old (< ${MIN_RUST_VERSION}). Updating...${NC}" should_install_rust=true else - echo -e "${GREEN}✅ Rust version is sufficient. Skipping installation.${NC}" + echo -e "${GREEN}✅ Rust version is sufficient. Skipping install.${NC}" fi else echo -e "${YELLOW}🚫 Rust or Cargo not found.${NC}" @@ -30,13 +37,29 @@ else fi if [ "$should_install_rust" = true ]; then - echo -e "${CYAN}🚀 Installing rustup (Rust & Cargo)...${NC}" + echo -e "${CYAN}🚀 Installing Rust via rustup...${NC}" curl https://sh.rustup.rs -sSf | sh -s -- -y - source $HOME/.cargo/env + source "$HOME/.cargo/env" + + if ! command -v cargo &> /dev/null; then + echo -e "${RED}❌ Cargo not found after install. Exiting.${NC}" + exit 1 + fi fi -# Handle --force flag -if [[ "$1" == "--force" ]]; then +# Ensure cargo bin path is in PATH +export PATH="$HOME/.cargo/bin:$PATH" + +# Parse flags +FORCE=false +for arg in "$@"; do + if [[ "$arg" == "--force" ]]; then + FORCE=true + fi +done + +# Clone if not exists or force +if [ "$FORCE" = true ]; then echo -e "${YELLOW}⚠️ --force enabled. Removing existing 'pipe' folder...${NC}" rm -rf pipe fi @@ -47,9 +70,11 @@ else echo -e "${CYAN}📦 Cloning Pipe repo...${NC}" git clone https://github.com/PipeNetwork/pipe.git fi + cd pipe echo -e "${CYAN}🔧 Building Pipe CLI...${NC}" + if cargo install --path .; then echo -e "${GREEN}✅ Build successful!${NC}" else @@ -57,10 +82,12 @@ else exit 1 fi +# Final check if command -v pipe &> /dev/null; then echo -e "\n${GREEN}🚀 All set! You can now run:${NC}" echo -e " ${CYAN}pipe --help${NC}\n" + echo -e "${CYAN}📍 Installed binary: $(which pipe)${NC}" else - echo -e "\n${RED}⚠️ Setup complete, but 'pipe' command not found in PATH.${NC}" - echo -e "${YELLOW}You might need to restart your terminal or add ~/.cargo/bin to PATH.${NC}\n" + echo -e "\n${RED}⚠️ Build completed, but 'pipe' not found in PATH.${NC}" + echo -e "${YELLOW}Try running: export PATH=\"\$HOME/.cargo/bin:\$PATH\"${NC}" fi