Skip to content

Added optimizations to the build.yml file #8

Added optimizations to the build.yml file

Added optimizations to the build.yml file #8

Workflow file for this run

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 }}