Skip to content

Commit b3dc2e4

Browse files
committed
feat: enhance install script with platform detection and binary download logic
1 parent e2c1121 commit b3dc2e4

File tree

2 files changed

+285
-8
lines changed

2 files changed

+285
-8
lines changed

.github/workflows/build.yml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
release:
9+
types: [published]
10+
11+
permissions:
12+
contents: write
13+
14+
env:
15+
CARGO_TERM_COLOR: always
16+
17+
jobs:
18+
build:
19+
name: Build for ${{ matrix.target }}
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
include:
25+
# Linux x86_64
26+
- target: x86_64-unknown-linux-gnu
27+
os: ubuntu-latest
28+
asset_name: aimit-linux-x86_64
29+
# # Linux ARM64
30+
# - target: aarch64-unknown-linux-gnu
31+
# os: ubuntu-latest
32+
# asset_name: aimit-linux-aarch64
33+
# macOS x86_64 (Intel)
34+
- target: x86_64-apple-darwin
35+
os: macos-latest
36+
asset_name: aimit-macos-x86_64
37+
# macOS ARM64 (Apple Silicon)
38+
- target: aarch64-apple-darwin
39+
os: macos-latest
40+
asset_name: aimit-macos-aarch64
41+
# Windows x86_64
42+
- target: x86_64-pc-windows-msvc
43+
os: windows-latest
44+
asset_name: aimit-windows-x86_64.exe
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Install Rust
51+
uses: dtolnay/rust-toolchain@stable
52+
with:
53+
targets: ${{ matrix.target }}
54+
55+
- name: Cache cargo registry
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/.cargo/registry
60+
~/.cargo/git
61+
target
62+
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
63+
restore-keys: |
64+
${{ runner.os }}-cargo-${{ matrix.target }}-
65+
66+
- name: Build
67+
run: cargo build --release --target ${{ matrix.target }}
68+
69+
- name: Upload artifact
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: ${{ matrix.asset_name }}
73+
path: target/${{ matrix.target }}/release/aimit${{ matrix.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
74+
75+
release:
76+
name: Create Release
77+
runs-on: ubuntu-latest
78+
needs: build
79+
if: github.event_name == 'release'
80+
steps:
81+
- name: Download all artifacts
82+
uses: actions/download-artifact@v4
83+
84+
- name: Create release archive
85+
run: |
86+
mkdir -p release-binaries
87+
for artifact_dir in */; do
88+
artifact_name=$(basename "$artifact_dir")
89+
echo "Processing artifact: $artifact_name"
90+
if [[ "$artifact_name" == *"windows"* ]]; then
91+
# Find the .exe file and copy it with a unique name
92+
exe_file=$(find "$artifact_dir" -name "*.exe" -type f | head -1)
93+
if [[ -n "$exe_file" ]]; then
94+
cp "$exe_file" "release-binaries/$artifact_name.exe"
95+
echo "Copied Windows binary: $exe_file -> release-binaries/$artifact_name.exe"
96+
fi
97+
else
98+
# Find the binary file and copy it with a unique name
99+
binary_file=$(find "$artifact_dir" -type f -executable | head -1)
100+
if [[ -n "$binary_file" ]]; then
101+
cp "$binary_file" "release-binaries/$artifact_name"
102+
echo "Copied binary: $binary_file -> release-binaries/$artifact_name"
103+
fi
104+
fi
105+
done
106+
107+
# List what we have
108+
echo "Files in release-binaries:"
109+
ls -la release-binaries/
110+
111+
# Create a zip file with all binaries
112+
cd release-binaries
113+
zip -r ../aimit-binaries.zip .
114+
cd ..
115+
116+
- name: Upload release assets
117+
uses: actions/upload-release-asset@v1
118+
env:
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
with:
121+
upload_url: ${{ github.event.release.upload_url }}
122+
asset_path: ./aimit-binaries.zip
123+
asset_name: aimit-binaries.zip
124+
asset_content_type: application/zip
125+
126+
update-binaries:
127+
name: Update Binary Files
128+
runs-on: ubuntu-latest
129+
needs: build
130+
if: github.ref == 'refs/heads/main'
131+
steps:
132+
- name: Checkout code
133+
uses: actions/checkout@v4
134+
with:
135+
token: ${{ secrets.GITHUB_TOKEN }}
136+
137+
- name: Download all artifacts
138+
uses: actions/download-artifact@v4
139+
140+
- name: Prepare binaries for bin directory
141+
run: |
142+
mkdir -p bin
143+
for artifact_dir in */; do
144+
artifact_name=$(basename "$artifact_dir")
145+
echo "Processing artifact: $artifact_name"
146+
147+
# Skip the bin directory itself
148+
if [[ "$artifact_name" == "bin" ]]; then
149+
echo "Skipping bin directory"
150+
continue
151+
fi
152+
153+
if [[ "$artifact_name" == *"windows"* ]]; then
154+
# Find the .exe file and copy it
155+
exe_file=$(find "$artifact_dir" -name "*.exe" -type f | head -1)
156+
if [[ -n "$exe_file" ]]; then
157+
cp "$exe_file" "bin/aimit.exe"
158+
echo "Copied Windows binary: $exe_file -> bin/aimit.exe"
159+
fi
160+
else
161+
# Find the binary file and copy it
162+
binary_file=$(find "$artifact_dir" -type f -executable | head -1)
163+
if [[ -n "$binary_file" ]]; then
164+
cp "$binary_file" "bin/aimit"
165+
echo "Copied binary: $binary_file -> bin/aimit"
166+
fi
167+
fi
168+
done
169+
170+
# List what we have
171+
echo "Files in bin directory:"
172+
ls -la bin/
173+
174+
- name: Commit and push binaries
175+
run: |
176+
git config --local user.email "action@github.com"
177+
git config --local user.name "GitHub Action"
178+
git add bin/
179+
if git diff --staged --quiet; then
180+
echo "No changes to commit"
181+
else
182+
git commit -m "Update binaries for release ${{ github.sha }}"
183+
git push
184+
fi

install_aimit.sh

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,112 @@
11
#!/bin/bash
22

3+
set -e
4+
35
REPO_URL="https://raw.githubusercontent.com/TutTrue/Aimit/refs/heads/main"
46
BINARY_NAME="aimit"
57
INSTALL_DIR="/usr/local/bin"
68

9+
detect_platform() {
10+
local os arch
11+
12+
# Detect OS
13+
case "$(uname -s)" in
14+
Linux*) os="linux" ;;
15+
Darwin*) os="macos" ;;
16+
CYGWIN* | MINGW* | MSYS*) os="windows" ;;
17+
*)
18+
echo "Unsupported operating system: $(uname -s)" >&2
19+
exit 1
20+
;;
21+
esac
22+
23+
# Detect architecture
24+
case "$(uname -m)" in
25+
x86_64 | amd64) arch="x86_64" ;;
26+
aarch64 | arm64) arch="aarch64" ;;
27+
armv7l) arch="armv7" ;;
28+
*)
29+
echo "Unsupported architecture: $(uname -m)" >&2
30+
exit 1
31+
;;
32+
esac
33+
34+
# Special case for macOS ARM64 (Apple Silicon)
35+
if [[ "$os" == "macos" && "$arch" == "aarch64" ]]; then
36+
arch="aarch64"
37+
fi
38+
39+
echo "${os}-${arch}"
40+
}
41+
42+
get_binary_name() {
43+
local platform="$1"
44+
case "$platform" in
45+
*windows*) echo "${BINARY_NAME}.exe" ;;
46+
*) echo "$BINARY_NAME" ;;
47+
esac
48+
}
49+
50+
download_binary() {
51+
local platform="$1"
52+
local binary_name="$2"
53+
local url="$REPO_URL/bin/$binary_name"
754

8-
echo "Downloading binary: $BINARY_NAME..."
9-
wget -q "$REPO_URL/bin/$BINARY_NAME" -O "$INSTALL_DIR/$BINARY_NAME"
55+
echo "Detected platform: $platform"
56+
echo "Downloading binary: $binary_name..."
1057

11-
chmod +x "$INSTALL_DIR/$BINARY_NAME"
58+
# Check if wget or curl is available
59+
if command -v wget >/dev/null 2>&1; then
60+
wget -q "$url" -O "$INSTALL_DIR/$binary_name"
61+
elif command -v curl >/dev/null 2>&1; then
62+
curl -sL "$url" -o "$INSTALL_DIR/$binary_name"
63+
else
64+
echo "Error: Neither wget nor curl is available. Please install one of them." >&2
65+
exit 1
66+
fi
67+
}
68+
69+
main() {
70+
echo "Installing aimit..."
71+
72+
# Detect platform
73+
platform=$(detect_platform)
74+
binary_name=$(get_binary_name "$platform")
75+
76+
# Create install directory if it doesn't exist
77+
if [[ ! -d "$INSTALL_DIR" ]]; then
78+
echo "Creating install directory: $INSTALL_DIR"
79+
sudo mkdir -p "$INSTALL_DIR"
80+
fi
81+
82+
# Download the appropriate binary
83+
download_binary "$platform" "$binary_name"
1284

13-
if [[ -f "$INSTALL_DIR/$BINARY_NAME" ]]; then
85+
# Make binary executable (skip for Windows)
86+
if [[ "$platform" != *"windows"* ]]; then
87+
chmod +x "$INSTALL_DIR/$binary_name"
88+
fi
89+
90+
# Verify installation
91+
if [[ -f "$INSTALL_DIR/$binary_name" ]]; then
1492
echo "Installation successful!"
15-
echo "Binary installed to: $INSTALL_DIR/$BINARY_NAME"
16-
else
17-
echo "Installation failed. Please check the script and repository."
93+
echo "Binary installed to: $INSTALL_DIR/$binary_name"
94+
echo "Platform: $platform"
95+
96+
# Test if the binary works
97+
if [[ "$platform" != *"windows"* ]]; then
98+
if "$INSTALL_DIR/$binary_name" --version >/dev/null 2>&1; then
99+
echo "Binary is working correctly!"
100+
else
101+
echo "Warning: Binary was installed but may not be working correctly."
102+
fi
103+
fi
104+
else
105+
echo "Installation failed. Please check the script and repository." >&2
18106
exit 1
19-
fi
107+
fi
108+
}
109+
110+
# Run main function
111+
main "$@"
112+

0 commit comments

Comments
 (0)