Skip to content

Commit 710a6ba

Browse files
committed
feat: Bootstrap project with Fx, Makefile and GitHub Actions
Establishes the initial Go project structure using Fx for dependency injection and lifecycle management. Includes foundational tooling and CI/CD setup. - Initializes core directory structure (cmd, internal, scripts, .github). - Integrates Uber Fx framework in main.go and internal/app. - Sets up zerolog logging with an Fx adapter (internal/log). - Creates a Makefile with targets for common tasks (build, run, test, fmt, lint, setup, tidy). - Adds a setup script (scripts/setup.sh) to install tools (templ, golangci-lint) and check PATH. - Configures GitHub Actions workflows for: - Go build/test/lint/format (go.yaml) - MegaLinter checks (mega-linter.yaml) - Semantic Release (release.yaml) - Adds comprehensive README with setup, usage and CI details. - Includes .gitignore file to avoid bloat. - Adds a dummy test (internal/app/app_test.go) to validate test execution.
1 parent 8eecc78 commit 710a6ba

File tree

10 files changed

+308
-8
lines changed

10 files changed

+308
-8
lines changed

.github/workflows/go.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Go CI
3+
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
build:
12+
name: Build & Test
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.21' # Or your desired Go version
22+
23+
- name: Setup tools
24+
run: make setup
25+
26+
- name: Tidy modules
27+
run: make tidy
28+
29+
- name: Check formatting
30+
run: |
31+
make fmt
32+
# Check if git status is clean after formatting
33+
if ! git diff --exit-code; then
34+
echo "Code is not formatted correctly. Run 'make fmt' locally."
35+
exit 1
36+
fi
37+
38+
- name: Lint code
39+
run: make lint
40+
41+
- name: Run tests
42+
run: make test
43+
44+
- name: Build application
45+
run: make build

.github/workflows/mega-linter.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
# MegaLinter GitHub Action configuration file
3+
# More info at https://megalinter.io
4+
name: MegaLinter
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
permissions: read-all
13+
14+
env: # Comment env block if you don't want to apply fixes
15+
# Apply linter fixes configuration
16+
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
17+
APPLY_FIXES_EVENT: none # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
18+
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
19+
20+
concurrency:
21+
group: ${{ github.ref }}-${{ github.workflow }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
megalinter:
26+
name: MegaLinter
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: read
30+
issues: write
31+
pull-requests: write
32+
steps:
33+
# Git Checkout
34+
- name: Checkout Code
35+
uses: actions/checkout@v4
36+
with:
37+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
38+
fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances
39+
# MegaLinter
40+
- name: MegaLinter
41+
id: ml
42+
# deployed v8.3.0, https://github.com/oxsecurity/megalinter/releases/tag/v8.3.0
43+
uses: oxsecurity/megalinter@1fc052d03c7a43c78fe0fee19c9d648b749e0c01
44+
env:
45+
# All available variables are described in documentation
46+
# https://megalinter.io/configuration/
47+
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
# Upload MegaLinter artifacts
50+
- name: Archive production artifacts
51+
if: success() || failure()
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: MegaLinter reports
55+
path: |
56+
megalinter-reports
57+
mega-linter.log
58+

.github/workflows/release.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Tag and Release
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Use Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 18
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run semantic-release
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE }}
28+
run: npx semantic-release --branches main

.mega-linter.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
# Configuration file for MegaLinter
3+
# See all available variables at https://megalinter.io/configuration/ and in linters documentation
4+
5+
DISABLE_LINTERS:
6+
- SPELL_CSPELL
7+
- SPELL_LYCHEE
8+
9+
DISABLE_ERRORS_LINTERS:
10+
- COPYPASTE_JSCPD
11+
- REPOSITORY_DEVSKIM
12+
- REPOSITORY_KICS
13+
14+
EMAIL_REPORTER: false
15+
FILEIO_REPORTER: false
16+
MARKDOWN_SUMMARY_REPORTER: true
17+
SHOW_ELAPSED_TIME: true

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help build run test fmt lint generate tidy all
1+
.PHONY: help build run test fmt lint generate tidy setup
22

33
# Default goal when 'make' is run without arguments
44
.DEFAULT_GOAL := help
@@ -13,13 +13,18 @@ help:
1313
@echo ""
1414
@echo "Targets:"
1515
@echo " help Show this help message (default)."
16+
@echo " setup Install required tools (templ, golangci-lint)."
1617
@echo " build Build the Go application binary into $(OUTPUT_DIR)/."
1718
@echo " run Build and run the Go application from $(OUTPUT_DIR)/."
1819
@echo " generate Generate code (e.g., templ files)."
1920
@echo " test Run Go tests."
2021
@echo " fmt Format Go and templ code."
21-
@echo " lint Run golangci-lint (requires installation)."
2222
@echo " tidy Tidy Go module files."
23+
@echo " lint Run golangci-lint (requires installation)."
24+
25+
setup:
26+
@echo "Running setup script..."
27+
@./scripts/setup.sh
2328

2429
build: generate
2530
@echo "Building $(BINARY_NAME) into $(OUTPUT_DIR)/..."
@@ -49,4 +54,4 @@ tidy:
4954

5055
lint:
5156
@echo "Linting code... (requires golangci-lint)"
52-
@golangci-lint run
57+
@golangci-lint run

README.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,93 @@
22

33
This repository contains the source code for the Agent Browser.
44

5-
## Project Setup (Golang)
5+
## Project Structure
66

7-
This project is being set up using Golang and the `fx` framework.
7+
This project uses Go modules and follows a standard Go project layout:
88

9-
Refer to `.cursor/TASK_LIST.md` for the setup tasks.
9+
* `/cmd`: Main application entry points.
10+
* `/internal`: Private application code (not intended for import by other projects).
11+
* `/app`: Core application setup and Fx module wiring.
12+
* `/config`: Configuration loading and management.
13+
* `/log`: Logging setup and utilities.
14+
* `/mcp`: MCP abstraction and utilities.
15+
* `/services`: Core business logic implementations.
16+
* `/sync`: Sync daemon. (PLACEHOLDER)
17+
* `/updater`: Software update logic. (PLACEHOLDER)
18+
* `/web`: Web server related code.
19+
* `/handlers`: HTTP request handlers.
20+
* `/templates`: HTML templates (using `templ`).
21+
* `/pkg`: Library code intended for external use (currently N/A).
22+
* `/scripts`: Scripts in Bash, Python, etc., for complex actions in this repository.
23+
* `/out`: Compiled binaries (ignored by git).
1024

1125
## Getting Started
1226

13-
ToDo
27+
### Prerequisites
28+
29+
1. **Go:** Ensure you have Go installed (version 1.21 or later recommended). You can download it from [https://go.dev/dl/](https://go.dev/dl/).
30+
2. **Bash:** The setup script uses `bash` specific features.
31+
3. **Environment Setup:** The setup script (`make setup`) will check if your `$GOPATH/bin` directory is in your `PATH` and provide instructions if it isn't. This directory is needed to run Go tools installed via `go install`.
32+
33+
You can manually verify by running `go env GOPATH` and checking your shell's configuration (e.g., `.zshrc`, `.bashrc`). Example:
34+
```bash
35+
export GOPATH="$(go env GOPATH)" # Or explicitly set, e.g., export GOPATH="$HOME/go"
36+
export PATH="$PATH:$GOPATH/bin"
37+
```
38+
39+
### Installation & Setup
40+
41+
1. **Clone the repository:**
42+
43+
```bash
44+
git clone https://github.com/co-browser/agent-browser.git
45+
cd agent-browser
46+
```
47+
48+
2. **Install Tools & Dependencies:** Run the setup command. This executes `scripts/setup.sh` which installs required Go tools (`templ`, `golangci-lint`) and checks your `PATH`.
49+
50+
```bash
51+
make setup
52+
```
53+
54+
3. **Download Go Modules:**
55+
56+
```bash
57+
make tidy
58+
```
59+
60+
### Running the Application
61+
62+
1. **Build and Run:**
63+
64+
```bash
65+
make run
66+
```
67+
68+
This will compile the application into the `out/` directory and start the server (defaulting to `localhost:8080`).
69+
70+
2. **Access the UI (Placeholder):** Open your browser to `http://localhost:8080/ui`.
71+
72+
## Development
73+
74+
### Common Makefile Targets
75+
76+
* `make setup`: Runs `scripts/setup.sh` to install/update necessary development tools (`templ`, `golangci-lint`) and check `PATH`.
77+
* `make build`: Compile the application binary into `out/agent-browser`.
78+
* `make run`: Build and run the application.
79+
* `make generate`: Generate Go code from `.templ` files.
80+
* `make test`: Run Go tests.
81+
* `make fmt`: Format Go code (`gofmt`) and `.templ` files (`templ fmt`).
82+
* `make tidy`: Tidy `go.mod` and `go.sum` files.
83+
* `make lint`: Run the Go linter (`golangci-lint`).
84+
* `make help`: Show all available targets.
85+
86+
## Continuous Integration
87+
88+
This project uses GitHub Actions for Continuous Integration (CI) and release automation. The workflows are defined in the `.github/workflows/` directory.
89+
90+
* **Go CI (`go.yaml`):** This workflow runs on pushes and pull requests to the `main` and `develop` branches. It checks out the code, sets up Go, runs `make setup`, `make tidy`, formatting checks (`make fmt`), linting (`make lint`), tests (`make test`) and builds the project (`make build`) to ensure Go code quality and stability.
91+
92+
* **MegaLinter (`mega-linter.yaml`):** This workflow runs on pushes and pull requests to the `main` branch. It utilizes [MegaLinter](https://megalinter.io/) to analyze the entire codebase using a wide range of linters for various languages and formats (including Go, YAML, Markdown, Shell scripts, etc.). This helps maintain consistent coding standards and identify potential issues across the whole project. Reports are uploaded as artifacts.
93+
94+
* **Release (`release.yaml`):** This workflow runs only on pushes to the `main` branch. It uses [semantic-release](https://github.com/semantic-release/semantic-release) to automate version management and package publishing. Based on conventional commit messages, it determines the next version number, generates release notes, and creates a Git tag and GitHub release.

internal/app/app_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package app_test
2+
3+
import (
4+
"testing"
5+
)
6+
7+
// TestAppDummy is a placeholder test.
8+
// It verifies that the test suite runs.
9+
// TODO: Replace with actual application tests.
10+
func TestAppDummy(t *testing.T) {
11+
// Keep t parameter used
12+
_ = t
13+
// This test doesn't do anything yet, but confirms tests can be discovered and run.
14+
// t.Log("Dummy application test executed successfully.")
15+
}

internal/services/services.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package services

internal/web/templates/index.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ templ IndexPage() {
1414
<!-- Add more content here -->
1515
</body>
1616
</html>
17-
}
17+
}

scripts/setup.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
5+
cd "$SCRIPT_DIR"
6+
7+
# Function to print messages
8+
log() {
9+
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
10+
}
11+
12+
# Function to print success messages (green)
13+
echo_success() {
14+
printf "\033[0;32m✓ %s\033[0m\n" "$1"
15+
}
16+
17+
# Function to print warning messages (yellow)
18+
echo_warn() {
19+
printf "\033[0;33mWARN: %s\033[0m\n" "$1"
20+
}
21+
22+
log "Starting setup..."
23+
24+
log "Installing templ..."
25+
go install github.com/a-h/templ/cmd/templ@latest
26+
27+
log "Installing golangci-lint..."
28+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
29+
30+
log "Checking PATH environment variable..."
31+
32+
# Determine GOPATH/bin
33+
GOPATH_BIN=$(go env GOPATH)/bin
34+
35+
# Check if GOPATH/bin could be determined
36+
if [ -z "$GOPATH_BIN" ] || [ "$GOPATH_BIN" = "/bin" ]; then
37+
echo_warn "Could not determine GOPATH/bin. Please ensure GOPATH is set correctly."
38+
else
39+
# Use awk to check if GOPATH_BIN is a distinct component in PATH
40+
if echo "$PATH" | awk -v path_to_check="$GOPATH_BIN" 'BEGIN { FS=":"; found=0 } { for(i=1; i<=NF; i++) if ($i == path_to_check) { found=1; exit 0 } } END { exit !found }'; then
41+
echo_success "$GOPATH_BIN appears to be in your PATH."
42+
else
43+
echo_warn "$GOPATH_BIN does not appear to be in your PATH."
44+
echo " Please add it to your shell configuration (e.g., .zshrc, .bashrc):"
45+
echo " export PATH=\"$PATH:$GOPATH_BIN\""
46+
fi
47+
fi
48+
49+
# Use printf for the final success message too
50+
printf "\033[0;32m✓ %s\033[0m\n" "Setup complete."

0 commit comments

Comments
 (0)