Skip to content

Commit 65c67ab

Browse files
committed
Setup CI/CD, installation scripts, and Homebrew formula
1 parent 1b274b5 commit 65c67ab

File tree

7 files changed

+347
-0
lines changed

7 files changed

+347
-0
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: dtolnay/rust-toolchain@stable
19+
- uses: Swatinem/rust-cache@v2
20+
- name: Run tests
21+
run: cargo test --verbose
22+
23+
fmt:
24+
name: Rustfmt
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: dtolnay/rust-toolchain@stable
29+
with:
30+
components: rustfmt
31+
- name: Check formatting
32+
run: cargo fmt --all -- --check
33+
34+
clippy:
35+
name: Clippy
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v3
39+
- uses: dtolnay/rust-toolchain@stable
40+
with:
41+
components: clippy
42+
- uses: Swatinem/rust-cache@v2
43+
- name: Clippy check
44+
run: cargo clippy -- -D warnings

.github/workflows/release.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- 'v[0-9]+*' # Matches v1.0.0, v20.15.10, etc.
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
RELEASE_BIN: smart-tree
11+
12+
jobs:
13+
create-release:
14+
name: Create Release
15+
runs-on: ubuntu-latest
16+
outputs:
17+
upload_url: ${{ steps.create_release.outputs.upload_url }}
18+
version: ${{ steps.get_version.outputs.version }}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Get version from branch
24+
id: get_version
25+
run: |
26+
VERSION=${GITHUB_REF#refs/heads/v}
27+
echo "version=$VERSION" >> $GITHUB_OUTPUT
28+
echo "Detected version: $VERSION"
29+
30+
- name: Create Release
31+
id: create_release
32+
uses: actions/create-release@v1
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
with:
36+
tag_name: v${{ steps.get_version.outputs.version }}
37+
release_name: Release v${{ steps.get_version.outputs.version }}
38+
draft: false
39+
prerelease: false
40+
41+
build-and-upload:
42+
name: Build and upload
43+
needs: create-release
44+
runs-on: ${{ matrix.os }}
45+
strategy:
46+
matrix:
47+
os: [ubuntu-latest, macOS-latest, windows-latest]
48+
include:
49+
- os: ubuntu-latest
50+
target: x86_64-unknown-linux-gnu
51+
asset_name: smart-tree-linux-amd64
52+
- os: macOS-latest
53+
target: x86_64-apple-darwin
54+
asset_name: smart-tree-macos-amd64
55+
- os: windows-latest
56+
target: x86_64-pc-windows-msvc
57+
asset_name: smart-tree-windows-amd64.exe
58+
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v3
62+
63+
- name: Setup Rust toolchain
64+
uses: dtolnay/rust-toolchain@stable
65+
with:
66+
targets: ${{ matrix.target }}
67+
68+
- name: Build release binary
69+
run: cargo build --release --target ${{ matrix.target }}
70+
71+
- name: Prepare binary (Unix)
72+
if: matrix.os != 'windows-latest'
73+
run: |
74+
cd target/${{ matrix.target }}/release
75+
strip ${{ env.RELEASE_BIN }}
76+
cp ${{ env.RELEASE_BIN }} ${{ matrix.asset_name }}
77+
78+
- name: Prepare binary (Windows)
79+
if: matrix.os == 'windows-latest'
80+
run: |
81+
cd target/${{ matrix.target }}/release
82+
cp ${{ env.RELEASE_BIN }}.exe ${{ matrix.asset_name }}
83+
84+
- name: Upload Release Asset
85+
uses: actions/upload-release-asset@v1
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
with:
89+
upload_url: ${{ needs.create-release.outputs.upload_url }}
90+
asset_path: ./target/${{ matrix.target }}/release/${{ matrix.asset_name }}
91+
asset_name: ${{ matrix.asset_name }}
92+
asset_content_type: application/octet-stream

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
name = "smart-tree"
33
version = "0.1.0"
44
edition = "2021"
5+
authors = ["Erik Balfe"]
6+
description = "A modern directory tree viewer with intelligent folding and display options"
7+
homepage = "https://github.com/erik-balfe/smart-tree"
8+
repository = "https://github.com/erik-balfe/smart-tree"
9+
license = "MIT"
10+
readme = "README.MD"
11+
keywords = ["cli", "tree", "directory", "filesystem"]
12+
categories = ["command-line-utilities", "filesystem"]
513

614
[dev-dependencies]
715
pretty_assertions = "1.4"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Erik Balfe
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.MD

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ Planned enhancements for future versions:
258258

259259
## Installation
260260

261+
### Quick Install (Linux, macOS)
262+
263+
```bash
264+
# Easy install script
265+
curl -sSL https://raw.githubusercontent.com/erik-balfe/smart-tree/master/install.sh | sh
266+
```
267+
268+
### macOS via Homebrew
269+
270+
```bash
271+
# Homebrew installation will be available soon
272+
brew install erik-balfe/tap/smart-tree
273+
```
274+
275+
### Manual Installation
276+
261277
```bash
262278
# Install from source
263279
git clone https://github.com/erik-balfe/smart-tree.git
@@ -268,6 +284,10 @@ cargo install --path .
268284
smart-tree [path] [options]
269285
```
270286

287+
### Pre-built Binaries
288+
289+
You can also download pre-built binaries for your platform from the [GitHub Releases page](https://github.com/erik-balfe/smart-tree/releases).
290+
271291
## Usage
272292

273293
```bash

homebrew-formula/smart-tree.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class SmartTree < Formula
2+
desc "A modern directory tree viewer with intelligent folding and display options"
3+
homepage "https://github.com/erik-balfe/smart-tree"
4+
url "https://github.com/erik-balfe/smart-tree/archive/refs/tags/v0.1.0.tar.gz"
5+
sha256 "UPDATE_WITH_REAL_HASH_WHEN_AVAILABLE"
6+
license "MIT"
7+
head "https://github.com/erik-balfe/smart-tree.git", branch: "master"
8+
9+
depends_on "rust" => :build
10+
11+
def install
12+
system "cargo", "install", *std_cargo_args
13+
end
14+
15+
test do
16+
# Create a simple directory structure
17+
(testpath/"test_dir").mkpath
18+
(testpath/"test_dir/file1.txt").write("Hello")
19+
(testpath/"test_dir/file2.txt").write("World")
20+
(testpath/"test_dir/subdir").mkpath
21+
(testpath/"test_dir/subdir/file3.txt").write("!")
22+
23+
# Run smart-tree on the test directory
24+
output = shell_output("#{bin}/smart-tree #{testpath}/test_dir")
25+
26+
# Verify expected output
27+
assert_match "test_dir", output
28+
assert_match "file1.txt", output
29+
assert_match "file2.txt", output
30+
assert_match "subdir", output
31+
end
32+
end

install.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/sh
2+
# Smart Tree Installation Script
3+
4+
set -e
5+
6+
GITHUB_REPO="erik-balfe/smart-tree"
7+
BINARY_NAME="smart-tree"
8+
INSTALL_DIR="/usr/local/bin"
9+
10+
# Colors for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
BLUE='\033[0;34m'
14+
YELLOW='\033[1;33m'
15+
NC='\033[0m' # No Color
16+
17+
# Print message with color
18+
print_message() {
19+
printf "${2}${1}${NC}\n"
20+
}
21+
22+
# Detect platform
23+
detect_platform() {
24+
OS="$(uname -s)"
25+
ARCH="$(uname -m)"
26+
27+
case "$OS" in
28+
Linux)
29+
PLATFORM="linux"
30+
;;
31+
Darwin)
32+
PLATFORM="macos"
33+
;;
34+
MINGW* | MSYS* | CYGWIN*)
35+
PLATFORM="windows"
36+
;;
37+
*)
38+
print_message "Unsupported operating system: $OS" "$RED"
39+
exit 1
40+
;;
41+
esac
42+
43+
case "$ARCH" in
44+
x86_64 | amd64)
45+
ARCHITECTURE="amd64"
46+
;;
47+
arm64 | aarch64)
48+
ARCHITECTURE="arm64"
49+
print_message "Warning: ARM64 is not officially supported yet, trying with amd64 version" "$YELLOW"
50+
ARCHITECTURE="amd64"
51+
;;
52+
*)
53+
print_message "Unsupported architecture: $ARCH" "$RED"
54+
exit 1
55+
;;
56+
esac
57+
58+
if [ "$PLATFORM" = "windows" ]; then
59+
BINARY_URL="https://github.com/${GITHUB_REPO}/releases/latest/download/${BINARY_NAME}-${PLATFORM}-${ARCHITECTURE}.exe"
60+
BINARY_PATH="${BINARY_NAME}.exe"
61+
else
62+
BINARY_URL="https://github.com/${GITHUB_REPO}/releases/latest/download/${BINARY_NAME}-${PLATFORM}-${ARCHITECTURE}"
63+
BINARY_PATH="${BINARY_NAME}"
64+
fi
65+
}
66+
67+
# Check if curl or wget is installed
68+
check_downloader() {
69+
if command -v curl >/dev/null 2>&1; then
70+
DOWNLOADER="curl"
71+
elif command -v wget >/dev/null 2>&1; then
72+
DOWNLOADER="wget"
73+
else
74+
print_message "Error: neither curl nor wget is installed. Please install one of them and try again." "$RED"
75+
exit 1
76+
fi
77+
}
78+
79+
# Download the binary
80+
download_binary() {
81+
TMP_DIR="$(mktemp -d)"
82+
TMP_FILE="${TMP_DIR}/${BINARY_PATH}"
83+
84+
print_message "Downloading ${BINARY_NAME} for ${PLATFORM}/${ARCHITECTURE}..." "$BLUE"
85+
86+
if [ "$DOWNLOADER" = "curl" ]; then
87+
curl -sL "$BINARY_URL" -o "$TMP_FILE"
88+
else
89+
wget -q "$BINARY_URL" -O "$TMP_FILE"
90+
fi
91+
92+
if [ ! -f "$TMP_FILE" ]; then
93+
print_message "Failed to download ${BINARY_NAME}" "$RED"
94+
exit 1
95+
fi
96+
}
97+
98+
# Install the binary
99+
install_binary() {
100+
chmod +x "$TMP_FILE"
101+
102+
# Check if we need sudo
103+
if [ -w "$INSTALL_DIR" ]; then
104+
mv "$TMP_FILE" "${INSTALL_DIR}/${BINARY_PATH}"
105+
else
106+
print_message "Elevated permissions required to install to ${INSTALL_DIR}" "$YELLOW"
107+
sudo mv "$TMP_FILE" "${INSTALL_DIR}/${BINARY_PATH}"
108+
fi
109+
110+
rm -rf "$TMP_DIR"
111+
112+
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
113+
print_message "${BINARY_NAME} installed successfully to ${INSTALL_DIR}/${BINARY_PATH}" "$GREEN"
114+
print_message "Run '${BINARY_NAME} --help' to get started" "$BLUE"
115+
else
116+
print_message "Installation successful, but ${BINARY_NAME} is not in your PATH" "$YELLOW"
117+
print_message "Installed to: ${INSTALL_DIR}/${BINARY_PATH}" "$BLUE"
118+
fi
119+
}
120+
121+
main() {
122+
print_message "Smart Tree Installer" "$GREEN"
123+
124+
check_downloader
125+
detect_platform
126+
download_binary
127+
install_binary
128+
}
129+
130+
main

0 commit comments

Comments
 (0)