-
Notifications
You must be signed in to change notification settings - Fork 2
158 lines (136 loc) · 5.2 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
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
run: |
python -m pip install --upgrade pip
pip install pyinstaller pathspec pyperclip
if [ "${{ matrix.os }}" != "windows-latest" ]; then
sudo apt-get update && sudo apt-get install -y upx
fi
# Build binary with PyInstaller and optimize
- name: Build executable with PyInstaller
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
pyinstaller --onefile --noconsole --name gptree.exe cli_tool_gptree/main.py
else
pyinstaller --onefile --noconsole --name gptree --upx-dir=/usr/bin --no-lzma cli_tool_gptree/main.py
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}"
on_macos do
url "${MACOS_URL}"
sha256 "${MACOS_SHA}"
end
on_linux do
url "${LINUX_URL}"
sha256 "${LINUX_SHA}"
end
def install
if OS.mac?
bin.install "gptree-macos" => "gptree"
elsif OS.linux?
bin.install "gptree-ubuntu" => "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 }}