-
Notifications
You must be signed in to change notification settings - Fork 0
Implement cross-platform build system with automatic versioning for main branch deployments #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
streed
merged 3 commits into
main
from
copilot/fix-caaaf750-fced-4d98-af58-2dbcf63cc3e4
Aug 30, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| name: Main Branch Build | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
|
|
||
| env: | ||
| GO_VERSION: '1.23' | ||
|
|
||
| permissions: | ||
| contents: write # Needed to push VERSION file changes | ||
| actions: read | ||
|
|
||
| jobs: | ||
| build-and-version: | ||
| name: Build Cross-Platform Binaries | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| cache: true | ||
|
|
||
| - name: Install dependencies | ||
| run: go mod download | ||
|
|
||
| - name: Run tests | ||
| run: go test -v ./... | ||
|
|
||
| - name: Read current version and increment | ||
| id: version | ||
| run: | | ||
| CURRENT_VERSION=$(cat VERSION) | ||
| echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| # Increment patch version for main branch builds | ||
| IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" | ||
| MAJOR=${VERSION_PARTS[0]} | ||
| MINOR=${VERSION_PARTS[1]} | ||
| PATCH=${VERSION_PARTS[2]} | ||
|
|
||
| NEW_PATCH=$((PATCH + 1)) | ||
| NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" | ||
|
|
||
| echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
| echo "$NEW_VERSION" > VERSION | ||
|
|
||
| echo "Version incremented from $CURRENT_VERSION to $NEW_VERSION" | ||
|
|
||
| - name: Commit version update | ||
| run: | | ||
| git config --local user.email "action@github.com" | ||
| git config --local user.name "GitHub Action" | ||
| git add VERSION | ||
| if git diff --staged --quiet; then | ||
| echo "No version changes to commit" | ||
| else | ||
| git commit -m "Bump version to ${{ steps.version.outputs.new }} [skip ci]" | ||
| git push | ||
| fi | ||
|
|
||
| - name: Create release directory | ||
| run: mkdir -p dist | ||
|
|
||
| - name: Build for Linux AMD64 | ||
| env: | ||
| GOOS: linux | ||
| GOARCH: amd64 | ||
| CGO_ENABLED: 1 | ||
| run: | | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-linux-amd64 ./cmd/lil-rag | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-server-linux-amd64 ./cmd/lil-rag-server | ||
|
|
||
| - name: Build for Linux ARM64 | ||
| env: | ||
| GOOS: linux | ||
| GOARCH: arm64 | ||
| CGO_ENABLED: 1 | ||
| CC: aarch64-linux-gnu-gcc | ||
| run: | | ||
| sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-linux-arm64 ./cmd/lil-rag | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-server-linux-arm64 ./cmd/lil-rag-server | ||
|
|
||
| - name: Build for macOS AMD64 | ||
| env: | ||
| GOOS: darwin | ||
| GOARCH: amd64 | ||
| CGO_ENABLED: 1 | ||
| run: | | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-darwin-amd64 ./cmd/lil-rag | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-server-darwin-amd64 ./cmd/lil-rag-server | ||
|
|
||
| - name: Build for macOS ARM64 | ||
| env: | ||
| GOOS: darwin | ||
| GOARCH: arm64 | ||
| CGO_ENABLED: 1 | ||
| run: | | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-darwin-arm64 ./cmd/lil-rag | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-server-darwin-arm64 ./cmd/lil-rag-server | ||
|
|
||
| - name: Build for Windows AMD64 | ||
| env: | ||
| GOOS: windows | ||
| GOARCH: amd64 | ||
| CGO_ENABLED: 1 | ||
| CC: x86_64-w64-mingw32-gcc | ||
| run: | | ||
| sudo apt-get install -y gcc-mingw-w64 | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-windows-amd64.exe ./cmd/lil-rag | ||
| go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.new }}" -o dist/lil-rag-server-windows-amd64.exe ./cmd/lil-rag-server | ||
|
|
||
| - name: Create archives | ||
| run: | | ||
| # Linux AMD64 | ||
| tar -czf dist/lil-rag-${{ steps.version.outputs.new }}-linux-amd64.tar.gz -C dist lil-rag-linux-amd64 lil-rag-server-linux-amd64 | ||
|
|
||
| # Linux ARM64 | ||
| tar -czf dist/lil-rag-${{ steps.version.outputs.new }}-linux-arm64.tar.gz -C dist lil-rag-linux-arm64 lil-rag-server-linux-arm64 | ||
|
|
||
| # macOS AMD64 | ||
| tar -czf dist/lil-rag-${{ steps.version.outputs.new }}-darwin-amd64.tar.gz -C dist lil-rag-darwin-amd64 lil-rag-server-darwin-amd64 | ||
|
|
||
| # macOS ARM64 | ||
| tar -czf dist/lil-rag-${{ steps.version.outputs.new }}-darwin-arm64.tar.gz -C dist lil-rag-darwin-arm64 lil-rag-server-darwin-arm64 | ||
|
|
||
| # Windows AMD64 | ||
| zip -j dist/lil-rag-${{ steps.version.outputs.new }}-windows-amd64.zip dist/lil-rag-windows-amd64.exe dist/lil-rag-server-windows-amd64.exe | ||
|
|
||
| - name: Generate checksums | ||
| run: | | ||
| cd dist | ||
| sha256sum *.tar.gz *.zip > checksums.txt | ||
|
|
||
| - name: Upload build artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: lil-rag-${{ steps.version.outputs.new }}-binaries | ||
| path: | | ||
| dist/*.tar.gz | ||
| dist/*.zip | ||
| dist/checksums.txt | ||
| retention-days: 30 | ||
|
|
||
| - name: Display build summary | ||
| run: | | ||
| echo "## Build Summary" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Version:** ${{ steps.version.outputs.new }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Platforms:** Linux (AMD64, ARM64), macOS (AMD64, ARM64), Windows (AMD64)" >> $GITHUB_STEP_SUMMARY | ||
| echo "**Artifacts:** $(ls -1 dist/*.tar.gz dist/*.zip | wc -l) archives created" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### Files Generated:" >> $GITHUB_STEP_SUMMARY | ||
| ls -la dist/ >> $GITHUB_STEP_SUMMARY | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Lil-RAG - A simple RAG system with SQLite and Ollama | ||
|
|
||
| .PHONY: build test clean install fmt vet lint help dev examples deps coverage | ||
| .PHONY: build test clean install fmt vet lint help dev examples deps coverage build-cross clean-dist version | ||
|
|
||
| # Build binary names | ||
| BINARY_CLI=lil-rag | ||
|
|
@@ -19,6 +19,10 @@ GOVET=$(GOCMD) vet | |
| LDFLAGS=-ldflags="-s -w" | ||
| BUILDFLAGS=-trimpath | ||
|
|
||
| # Get version from VERSION file if it exists, otherwise use "dev" | ||
| VERSION=$(shell if [ -f VERSION ]; then cat VERSION; else echo "dev"; fi) | ||
| LDFLAGS_WITH_VERSION=-ldflags="-s -w -X main.version=$(VERSION)" | ||
|
|
||
| # Default target | ||
| help: ## Show this help message | ||
| @echo 'Lil-RAG Build System' | ||
|
|
@@ -30,21 +34,21 @@ help: ## Show this help message | |
| @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
|
|
||
| build: ## Build CLI and server binaries | ||
| @echo "Building $(BINARY_CLI) and $(BINARY_SERVER)..." | ||
| @echo "Building $(BINARY_CLI) and $(BINARY_SERVER) version $(VERSION)..." | ||
| @mkdir -p bin | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS) -o bin/$(BINARY_CLI) ./cmd/lil-rag | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS) -o bin/$(BINARY_SERVER) ./cmd/lil-rag-server | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o bin/$(BINARY_CLI) ./cmd/lil-rag | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o bin/$(BINARY_SERVER) ./cmd/lil-rag-server | ||
| @echo "Build complete!" | ||
|
|
||
| build-cli: ## Build only the CLI binary | ||
| @echo "Building $(BINARY_CLI)..." | ||
| @echo "Building $(BINARY_CLI) version $(VERSION)..." | ||
| @mkdir -p bin | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS) -o bin/$(BINARY_CLI) ./cmd/lil-rag | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o bin/$(BINARY_CLI) ./cmd/lil-rag | ||
|
|
||
| build-server: ## Build only the server binary | ||
| @echo "Building $(BINARY_SERVER)..." | ||
| @echo "Building $(BINARY_SERVER) version $(VERSION)..." | ||
| @mkdir -p bin | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS) -o bin/$(BINARY_SERVER) ./cmd/lil-rag-server | ||
| $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o bin/$(BINARY_SERVER) ./cmd/lil-rag-server | ||
|
|
||
| test: ## Run tests | ||
| $(GOTEST) -v ./pkg/... ./internal/... ./cmd/... | ||
|
|
@@ -58,6 +62,7 @@ clean: ## Clean build artifacts | |
| $(GOCLEAN) | ||
| rm -f bin/$(BINARY_CLI) bin/$(BINARY_SERVER) | ||
| rm -f coverage.out coverage.html | ||
| rm -rf dist/ | ||
|
|
||
| install: build ## Install binaries to $GOPATH/bin | ||
| @echo "Installing binaries to $(GOPATH)/bin..." | ||
|
|
@@ -91,4 +96,30 @@ examples: build ## Build and validate example programs | |
| all: clean deps lint test build examples ## Run all checks and build everything | ||
| @echo "All tasks completed successfully!" | ||
|
|
||
| build-cross: ## Build binaries for all platforms | ||
| @echo "Building cross-platform binaries version $(VERSION)..." | ||
|
||
| @mkdir -p dist | ||
| @echo "Building for Linux AMD64..." | ||
| GOOS=linux GOARCH=amd64 CGO_ENABLED=1 $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_CLI)-linux-amd64 ./cmd/lil-rag | ||
| GOOS=linux GOARCH=amd64 CGO_ENABLED=1 $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_SERVER)-linux-amd64 ./cmd/lil-rag-server | ||
| @echo "Building for Linux ARM64..." | ||
| GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_CLI)-linux-arm64 ./cmd/lil-rag | ||
| GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_SERVER)-linux-arm64 ./cmd/lil-rag-server | ||
| @echo "Building for macOS AMD64..." | ||
| GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_CLI)-darwin-amd64 ./cmd/lil-rag | ||
| GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_SERVER)-darwin-amd64 ./cmd/lil-rag-server | ||
| @echo "Building for macOS ARM64..." | ||
| GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_CLI)-darwin-arm64 ./cmd/lil-rag | ||
| GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_SERVER)-darwin-arm64 ./cmd/lil-rag-server | ||
| @echo "Building for Windows AMD64..." | ||
| GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_CLI)-windows-amd64.exe ./cmd/lil-rag | ||
| GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc $(GOBUILD) $(BUILDFLAGS) $(LDFLAGS_WITH_VERSION) -o dist/$(BINARY_SERVER)-windows-amd64.exe ./cmd/lil-rag-server | ||
| @echo "Cross-platform build complete!" | ||
|
|
||
| clean-dist: ## Clean distribution artifacts | ||
| rm -rf dist/ | ||
|
|
||
| version: ## Show current version | ||
| @echo "$(VERSION)" | ||
|
|
||
| .DEFAULT_GOAL := help | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow will fail on the first run because it attempts to increment a version before any version bump commits exist. The
git diff --staged --quietcheck will always be false since VERSION is always modified in the previous step, making the conditional logic ineffective.