Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Build Binaries

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build Cross-Platform Binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Linux builds
- goos: linux
goarch: amd64
name: jail-linux-amd64
- goos: linux
goarch: arm64
name: jail-linux-arm64
# macOS builds
- goos: darwin
goarch: amd64
name: jail-darwin-amd64
- goos: darwin
goarch: arm64
name: jail-darwin-arm64

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
check-latest: true

- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download dependencies
run: go mod download

- name: Verify dependencies
run: go mod verify

- name: Build binary
run: |
# Set target for cross-compilation
export GOOS=${{ matrix.goos }}
export GOARCH=${{ matrix.goarch }}
export CGO_ENABLED=0

# Add version info if available
VERSION="dev-${{ github.sha }}"
if [ "${{ github.ref_type }}" = "tag" ]; then
VERSION="${{ github.ref_name }}"
fi

# Build using Go directly for cross-compilation
go build -ldflags="-s -w -X main.version=$VERSION" -o ${{ matrix.name }} .

- name: Upload binary as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
retention-days: 30

summary:
name: Build Summary
needs: build
runs-on: ubuntu-latest
if: always()

steps:
- name: Build Summary
run: |
echo "## πŸ› οΈ Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Cross-platform binaries have been built and are available as artifacts." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ“¦ Available Binaries" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- 🐧 **Linux (x64)**: jail-linux-amd64" >> $GITHUB_STEP_SUMMARY
echo "- 🐧 **Linux (ARM64)**: jail-linux-arm64" >> $GITHUB_STEP_SUMMARY
echo "- 🍎 **macOS (Intel)**: jail-darwin-amd64" >> $GITHUB_STEP_SUMMARY
echo "- 🍎 **macOS (Apple Silicon)**: jail-darwin-arm64" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ“Ž Download Instructions" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. Go to the **Actions** tab" >> $GITHUB_STEP_SUMMARY
echo "2. Click on this workflow run" >> $GITHUB_STEP_SUMMARY
echo "3. Scroll down to **Artifacts** section" >> $GITHUB_STEP_SUMMARY
echo "4. Download the binary for your platform" >> $GITHUB_STEP_SUMMARY
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: go mod verify

- name: Run tests
run: go test -v -race ./...
run: make test

- name: Run build
run: go build -v ./...
- name: Check build
run: make build
135 changes: 135 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Release

on:
push:
tags:
- 'v*' # Trigger on version tags like v1.0.0, v1.2.3, etc.
workflow_dispatch: # Allow manual triggering

jobs:
build:
name: Build Binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Linux builds
- goos: linux
goarch: amd64
name: jail-linux-amd64
- goos: linux
goarch: arm64
name: jail-linux-arm64
# macOS builds
- goos: darwin
goarch: amd64
name: jail-darwin-amd64
- goos: darwin
goarch: arm64
name: jail-darwin-arm64

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
check-latest: true

- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download dependencies
run: go mod download

- name: Verify dependencies
run: go mod verify

- name: Build binary
run: |
# Set target for cross-compilation
export GOOS=${{ matrix.goos }}
export GOARCH=${{ matrix.goarch }}
export CGO_ENABLED=0

# Build using Go directly for cross-compilation
go build -ldflags="-s -w -X main.version=${{ github.ref_name }}" -o ${{ matrix.name }} .

- name: Upload binary as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
retention-days: 7

release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./binaries

- name: Prepare release assets
run: |
cd binaries
# Create compressed archives for each binary
for dir in */; do
binary_name=$(basename "$dir")
cd "$dir"
# Unix: create tar.gz
tar -czf "../${binary_name}.tar.gz" "$binary_name"
cd ..
done
# List all release assets
ls -la *.tar.gz

- name: Generate release notes
id: release_notes
run: |
echo "## πŸš€ Release ${{ github.ref_name }}" > release_notes.md
echo "" >> release_notes.md
echo "### πŸ“¦ Downloads" >> release_notes.md
echo "" >> release_notes.md
echo "Choose the appropriate binary for your platform:" >> release_notes.md
echo "" >> release_notes.md
echo "- **Linux (x64)**: \`jail-linux-amd64.tar.gz\`" >> release_notes.md
echo "- **Linux (ARM64)**: \`jail-linux-arm64.tar.gz\`" >> release_notes.md
echo "- **macOS (Intel)**: \`jail-darwin-amd64.tar.gz\`" >> release_notes.md
echo "- **macOS (Apple Silicon)**: \`jail-darwin-arm64.tar.gz\`" >> release_notes.md
echo "" >> release_notes.md
echo "### πŸ› οΈ Installation" >> release_notes.md
echo "" >> release_notes.md
echo "1. Download the appropriate binary for your platform" >> release_notes.md
echo "2. Extract the archive" >> release_notes.md
echo "3. Make the binary executable (Unix): `chmod +x jail`" >> release_notes.md
echo "4. Move to your PATH: `sudo mv jail /usr/local/bin/` (Unix)" >> release_notes.md
echo "" >> release_notes.md
echo "### βœ… Verification" >> release_notes.md
echo "" >> release_notes.md
echo "Verify installation: `jail --help`" >> release_notes.md

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
binaries/*.tar.gz
body_path: release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Thumbs.db
*.pem
*.crt
*.key
build/
75 changes: 75 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Makefile for jail

# Variables
BINARY_NAME := jail
BUILD_DIR := build
VERSION := $(shell git describe --tags --exact-match 2>/dev/null || echo "dev-$(shell git rev-parse --short HEAD)")
LDFLAGS := -s -w -X main.version=$(VERSION)

# Default target
.PHONY: all
all: build

# Build for current platform
.PHONY: build
build:
@echo "Building $(BINARY_NAME) for current platform..."
@echo "Version: $(VERSION)"
go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME) .
@echo "βœ“ Built $(BINARY_NAME)"

# Build for all supported platforms
.PHONY: build-all
build-all:
@echo "Building $(BINARY_NAME) for all platforms..."
@echo "Version: $(VERSION)"
@mkdir -p $(BUILD_DIR)
@echo "Building Linux amd64..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
@echo "Building Linux arm64..."
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
@echo "Building macOS amd64..."
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
@echo "Building macOS arm64..."
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
@echo "βœ“ All binaries built successfully!"
@echo "Binaries are in the '$(BUILD_DIR)' directory:"
@ls -la $(BUILD_DIR)/

# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v -race ./...
@echo "βœ“ All tests passed!"

# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "βœ“ Coverage report generated: coverage.html"

# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -f $(BINARY_NAME)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
@echo "βœ“ Clean complete!"

# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
@echo "βœ“ Code formatted!"

# Lint code
.PHONY: lint
lint:
@echo "Linting code..."
golangci-lint run
@echo "βœ“ Linting complete!"
Loading
Loading