-
Notifications
You must be signed in to change notification settings - Fork 2
194 lines (168 loc) · 6.58 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Build and Release gptree CLI
on:
push:
tags:
- 'v*' # Trigger on version tags like v1.0.0
workflow_dispatch: # Allow manual triggering
jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v4
# Set up Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
# Install dependencies
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install pyinstaller pathspec pyperclip
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
sudo apt-get update && sudo apt-get install -y upx
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
brew install upx
fi
# Build binary with PyInstaller and optimize
- name: Build executable with PyInstaller
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
pyinstaller --onefile --noconsole --name gptree.exe cli_tool_gptree/main.py
else
# Dynamically find UPX path
UPX_PATH=$(which upx || echo "")
echo "Using UPX path: $UPX_PATH"
if [ -n "$UPX_PATH" ]; then
pyinstaller --onefile --noconsole --upx-dir=$(dirname "$UPX_PATH") --name gptree cli_tool_gptree/main.py
else
echo "UPX not found; skipping compression."
pyinstaller --onefile --noconsole --name gptree cli_tool_gptree/main.py
fi
fi
# Rename binaries for platform-specific names
- name: Rename binaries for upload
shell: bash # Use Bash explicitly
run: |
if [ "${{ matrix.os }}" = "macos-latest" ]; then
mv dist/gptree dist/gptree-macos
elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
mv dist/gptree dist/gptree-ubuntu
elif [ "${{ matrix.os }}" = "windows-latest" ]; then
mv dist/gptree.exe dist/gptree-windows.exe
fi
# Upload binary as artifact
- name: Upload binary as artifact
uses: actions/upload-artifact@v4
with:
name: gptree-${{ matrix.os }}
path: |
dist/gptree-macos
dist/gptree-ubuntu
dist/gptree-windows.exe
release:
name: Create Release
needs: build # Waits for the build job to complete
runs-on: ubuntu-latest
permissions:
contents: write # Grants permission to create a release and upload files
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
# Download all artifacts from the build job
- name: Download all binaries
uses: actions/download-artifact@v4
with:
path: artifacts
# List downloaded files for debugging
- name: List downloaded binaries
run: ls -R artifacts
# Create GitHub Release and upload binaries
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: artifacts/**/* # Match all files recursively in artifacts/
body: "Release of gptree CLI tool.\n\nDownload the appropriate binary for your operating system."
tag_name: ${{ github.ref_name }}
name: 'GPTree Release ${{ github.ref_name }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Update Homebrew Tap Formula
- name: Update Homebrew Tap Formula
run: |
# Clone the Homebrew tap repository
git clone https://github.com/travisvn/homebrew-tap.git
cd homebrew-tap
# Define variables for version and compute SHA256 checksums
VERSION=${{ github.ref_name }}
MACOS_URL="https://github.com/travisvn/gptree/releases/download/${VERSION}/gptree-macos"
LINUX_URL="https://github.com/travisvn/gptree/releases/download/${VERSION}/gptree-ubuntu"
# Calculate SHA256 checksums
MACOS_SHA=$(curl -L $MACOS_URL | shasum -a 256 | cut -d' ' -f1)
LINUX_SHA=$(curl -L $LINUX_URL | shasum -a 256 | cut -d' ' -f1)
echo "MacOS SHA256: $MACOS_SHA"
echo "Linux SHA256: $LINUX_SHA"
# Update the gptree.rb formula
cat <<EOF > Formula/gptree.rb
class Gptree < Formula
desc "Project tree structure and file content aggregator for providing LLM context"
homepage "https://github.com/travisvn/gptree"
license "MIT"
version "${VERSION}"
depends_on "[email protected]" => :optional
def install
if system("which pip3")
# Attempt to install via pip
pip_success = system("pip3", "install", "gptree-cli==${VERSION}", "--prefix=#{prefix}")
unless pip_success
opoo "pip3 installation failed. Falling back to binary installation."
download_and_install_binary
end
else
# Fallback to binary installation if pip3 isn't available
download_and_install_binary
end
end
def download_and_install_binary
if OS.mac?
url = "${MACOS_URL}"
sha256 = "${MACOS_SHA}"
fetch_and_install(url, sha256, "gptree-macos")
elsif OS.linux?
url = "${LINUX_URL}"
sha256 = "${LINUX_SHA}"
fetch_and_install(url, sha256, "gptree-ubuntu")
end
end
def fetch_and_install(url, sha256, filename)
# Download the file manually
resource filename do
url url
sha256 sha256
end
resource(filename).stage do
bin.install filename => "gptree"
end
end
test do
assert_match "usage", shell_output("#{bin}/gptree --help")
end
end
EOF
# Commit and push the changes
git config user.name "github-actions"
git config user.email "[email protected]"
git add Formula/gptree.rb
git commit -m "Update gptree formula to version ${VERSION}"
git push https://x-access-token:${{ secrets.HOMEBREW_TAP_TOKEN }}@github.com/travisvn/homebrew-tap.git main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}