diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d8cc16..4355fb5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,6 +24,13 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload install scripts + uses: actions/upload-artifact@v4 + with: + name: install-scripts + path: | + install.sh + install.ps1 test: runs-on: ubuntu-latest diff --git a/.goreleaser.yml b/.goreleaser.yml index e8b89e7..e1b9cfc 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -19,12 +19,12 @@ builds: main: ./cmd/buildtree archives: - format: tar.gz - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" files: - LICENSE - README.md checksum: - name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt" + name_template: "{{ .ProjectName }}_checksums.txt" snapshot: name_template: "{{ .ProjectName }}-SNAPSHOT-{{ .ShortCommit }}" changelog: @@ -33,4 +33,8 @@ changelog: exclude: - "^docs:" - "^test:" - - "^chore:" \ No newline at end of file + - "^chore:" +release: + github: + owner: neomen + name: buildtree \ No newline at end of file diff --git a/README.md b/README.md index 53b1934..3f7574b 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,27 @@ custom_login/ go install github.com/neomen/buildtree/cmd/buildtree@latest ``` +### Quick install (Linux/macOS) + +```bash +curl -sSL https://raw.githubusercontent.com/neomen/buildtree/main/install.sh | sh +``` +### Manual installation + +1. Download the latest release for your platform from the [releases page](https://github.com/neomen/buildtree/releases) +2. Extract the archive: + ```bash + tar xzf buildtree__.tar.gz + ``` +3. Move the binary to your PATH: + ```bash + # Linux/macOS + sudo mv buildtree /usr/local/bin/ + + # Windows + # Move buildtree.exe to a directory in your PATH + ``` + ## Usage ### Basic Example @@ -54,7 +75,7 @@ pbpaste | buildtree - ### From File ```bash -buildtree -f structure.txt +buildtree -i structure.txt ``` ### Multi-level Project diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..83da696 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,53 @@ +# Buildtree installer for Windows +Write-Host "Installing buildtree..." -ForegroundColor Green + +# Determine architecture +$Arch = if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { "amd64" } else { "arm64" } + +# Download URL +$Url = "https://github.com/neomen/buildtree/releases/latest/download/buildtree_windows_${Arch}.tar.gz" +$OutputFile = "buildtree_windows_${Arch}.tar.gz" + +Write-Host "Downloading from $Url..." + +# Download the file +try { + Invoke-WebRequest -Uri $Url -OutFile $OutputFile +} +catch { + Write-Host "Error downloading buildtree: $_" -ForegroundColor Red + exit 1 +} + +# Extract the archive +try { + tar -xzf $OutputFile + Remove-Item $OutputFile +} +catch { + Write-Host "Error extracting archive: $_" -ForegroundColor Red + exit 1 +} + +# Check if buildtree.exe was extracted +if (Test-Path "buildtree.exe") { + Write-Host "Download successful!" -ForegroundColor Green + + # Check if a bin directory exists in PATH + $LocalBin = "$env:USERPROFILE\bin" + $InPath = $env:PATH -split ";" | Where-Object { $_ -eq $LocalBin } + + if (-not $InPath) { + Write-Host "Consider adding a directory to your PATH for easier access." -ForegroundColor Yellow + Write-Host "You can create a bin directory and add it to your PATH:" -ForegroundColor Yellow + Write-Host "1. mkdir $LocalBin" -ForegroundColor Yellow + Write-Host "2. [Environment]::SetEnvironmentVariable('PATH', `"$LocalBin;`$env:PATH`", 'User')" -ForegroundColor Yellow + Write-Host "3. Move buildtree.exe to $LocalBin" -ForegroundColor Yellow + } + + Write-Host "`nRun buildtree from current directory: .\buildtree.exe -h" -ForegroundColor Green +} +else { + Write-Host "Error: buildtree.exe not found in downloaded archive" -ForegroundColor Red + exit 1 +} \ No newline at end of file diff --git a/install.sh b/install.sh index bcf0c49..0172297 100644 --- a/install.sh +++ b/install.sh @@ -1,20 +1,68 @@ #!/bin/sh -# install.sh +# Buildtree installer script set -e -# OS and Architecture definition +echo "Installing buildtree..." + +# Determine OS and Architecture OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) -[ "$ARCH" = "x86_64" ] && ARCH="amd64" -[ "$ARCH" = "aarch64" ] && ARCH="arm64" -# Download -URL="https://github.com/neomen/buildtree/releases/latest/download/buildtree_${OS}_${ARCH}.tar.gz" -echo "Download from the $URL..." -curl -L "$URL" | tar xz +case $ARCH in + x86_64) ARCH="amd64" ;; + aarch64) ARCH="arm64" ;; + arm64) ARCH="arm64" ;; + *) echo "Unsupported architecture: $ARCH"; exit 1 ;; +esac + +# Check if the OS is supported +if [ "$OS" != "linux" ] && [ "$OS" != "darwin" ] && [ "$OS" != "windows" ]; then + echo "Unsupported OS: $OS. This script supports Linux, macOS, and Windows (via WSL)." + exit 1 +fi + +# For Windows, we need to adjust the binary name +if [ "$OS" = "windows" ]; then + BINARY_NAME="buildtree.exe" + ARCHIVE_NAME="buildtree_windows_${ARCH}.tar.gz" +else + BINARY_NAME="buildtree" + ARCHIVE_NAME="buildtree_${OS}_${ARCH}.tar.gz" +fi + +# Download URL +URL="https://github.com/neomen/buildtree/releases/latest/download/${ARCHIVE_NAME}" +echo "Downloading from $URL..." + +# Download and extract +if command -v curl >/dev/null 2>&1; then + curl -sSL "$URL" | tar xz +elif command -v wget >/dev/null 2>&1; then + wget -q -O - "$URL" | tar xz +else + echo "Error: curl or wget is required to download buildtree" + exit 1 +fi # Installation -sudo mv buildtree /usr/local/bin/ -echo "Installed in /usr/local/bin/buildtree" -buildtree -h \ No newline at end of file +if [ "$OS" = "windows" ]; then + # For Windows, offer to install to a directory in PATH + echo "Windows installation:" + echo "1. Move $BINARY_NAME to a directory in your PATH" + echo "2. Or run directly from current directory: .\\$BINARY_NAME" + mv "$BINARY_NAME" ./ + echo "Binary downloaded to current directory: $BINARY_NAME" +else + # For Unix systems, install to /usr/local/bin + sudo mv "$BINARY_NAME" /usr/local/bin/ + echo "Installed in /usr/local/bin/$BINARY_NAME" + + # Test the installation + if command -v "$BINARY_NAME" >/dev/null 2>&1; then + echo "Installation successful. You can now use '$BINARY_NAME'" + "$BINARY_NAME" -v + else + echo "Installation completed, but the binary is not in your PATH." + fi +fi \ No newline at end of file