Skip to content

Refactor project structure and add development tooling #281

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dh-make-golang
dh-make-golang.1
_build/
*~
*.sw[op]
Expand Down
184 changes: 184 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Development Guide for dh-make-golang

This document provides comprehensive information about the development structure, contribution guidelines, and file organization of the dh-make-golang project.

## Project Overview

dh-make-golang is a tool that automates the creation of Debian packaging for Go packages. It follows the [pkg-go packaging guidelines](https://go-team.pages.debian.net/packaging.html) and is designed to simplify the process of creating Debian packages for Go libraries and programs.

## Repository Structure

The project is organized as follows:

```
dh-make-golang/
├── cmd/ # Command implementation files
│ ├── check_depends.go # Check dependencies command
│ ├── clone.go # Clone command
│ ├── completion.go # Shell completion
│ ├── make.go # Main make command
│ ├── root.go # Root command definition
│ └── ...
├── .github/ # GitHub-specific files
│ └── workflows/ # CI/CD workflow definitions
├── main.go # Application entry point
├── make.go # Package creation logic
├── version.go # Version information
├── go.mod # Go module definition
├── go.sum # Go module checksums
└── ... # Other utility files
```

### Key Components

- **cmd/**: Contains the implementation of all CLI commands using the Cobra framework
- **main.go**: Entry point that initializes the application and GitHub client
- **make.go**: Core functionality for creating Debian packages
- **version.go**: Version information and management
- **description.go**: Package description handling
- **clone.go**: Repository cloning functionality
- **estimate.go**: Dependency estimation functionality

## Build and Run

### Build from source

```bash
# Clone the repository
git clone https://github.com/Debian/dh-make-golang.git
cd dh-make-golang

# Build the binary
go build -o dh-make-golang

# Install (optional)
sudo install -m755 dh-make-golang /usr/local/bin/
```

### Run

```bash
# Basic usage
dh-make-golang make github.com/example/package

# Get help
dh-make-golang --help

# Get help for a specific command
dh-make-golang make --help
```

## Development Workflow

### Setting up the Development Environment

1. Ensure you have Go 1.21+ installed
2. Clone the repository
3. Install development dependencies:
```bash
go get -v ./...
```

### Using the Makefile

The project includes a Makefile to simplify common development tasks. To see all available commands:

```bash
make help
```

#### Available Make Commands

| Command | Description | Example |
|---------|-------------|---------|
| `make build` | Builds the binary | `make build` |
| `make test` | Runs all tests | `make test` |
| `make lint` | Runs formatting and linting checks | `make lint` |
| `make fmt` | Formats code using gofmt | `make fmt` |
| `make vet` | Runs go vet for static analysis | `make vet` |
| `make clean` | Removes build artifacts | `make clean` |
| `make install` | Installs binary to /usr/local/bin | `make install` |
| `make man` | Generates man page from markdown | `make man` |

### Testing

The project uses Go's standard testing framework. Run tests with:

```bash
make test
```

Or directly with Go:

```bash
go test -v ./...
```

### Code Style

The project follows Go standard code style. Before submitting changes:

1. Format your code:
```bash
make fmt
```
2. Run linting:
```bash
make lint
```

### Environment Variables

The following environment variables can be used during development:

- `GITHUB_USERNAME`: GitHub username for API authentication
- `GITHUB_PASSWORD`: GitHub password or token for API authentication
- `GITHUB_OTP`: One-time password for GitHub 2FA (if enabled)

## Continuous Integration

The project uses GitHub Actions for CI/CD. The workflow:

1. Runs on multiple Go versions (1.21, 1.22)
2. Checks code formatting
3. Builds the project
4. Runs tests
5. Performs static analysis
6. Tests package creation with a real-world example

## Making Contributions

### Pull Request Process

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests and ensure they pass
5. Submit a pull request

### Commit Guidelines

- Use clear, descriptive commit messages
- Reference issue numbers when applicable
- Keep commits focused on single changes

### Documentation

When adding new features or modifying existing ones:

1. Update relevant documentation
2. Add comments to complex code sections
3. Update the man page if necessary (generated from dh-make-golang.md)

## Release Process

1. Update version information in version.go
2. Update changelog
3. Create a tag for the new version
4. Build and test the release
5. Push the tag to trigger release workflows

## Additional Resources

- [pkg-go packaging guidelines](https://go-team.pages.debian.net/packaging.html)
- [Debian Salsa](https://wiki.debian.org/Salsa)
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.PHONY: build test lint fmt vet clean install man help

BINARY_NAME=dh-make-golang
GO=go
GOFMT=gofmt
PANDOC=pandoc

help:
@echo "Available targets:"
@echo " build - Build the binary"
@echo " test - Run tests"
@echo " lint - Run linting checks"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " clean - Remove build artifacts"
@echo " install - Install binary to /usr/local/bin"
@echo " man - Generate man page"

build:
$(GO) build -o $(BINARY_NAME)

test:
$(GO) test -v ./...

lint: fmt vet

fmt:
$(GOFMT) -w -s .

vet:
$(GO) vet ./...

clean:
rm -f $(BINARY_NAME)
rm -f $(BINARY_NAME).1

install: build
install -m755 $(BINARY_NAME) /usr/local/bin/

man:
$(PANDOC) -f markdown -t man -s dh-make-golang.md -o $(BINARY_NAME).1
15 changes: 15 additions & 0 deletions cmd/check_depends.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"github.com/spf13/cobra"
)

// checkDependsCmd represents the check-depends command
var checkDependsCmd = &cobra.Command{
Use: "check-depends",
Short: "Compare go.mod and d/control to check for changes",
Long: `Compare go.mod and d/control to check for changes in dependencies.`,
Run: func(cmd *cobra.Command, args []string) {
execCheckDepends(args)
},
}
17 changes: 17 additions & 0 deletions cmd/clone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/spf13/cobra"
)

// cloneCmd represents the clone command
var cloneCmd = &cobra.Command{
Use: "clone <package-name>",
Short: "Clone a Go package from Salsa",
Long: `Clone a Go package from Salsa and download the appropriate tarball.`,
Example: "dh-make-golang clone golang-github-mmcdole-goxpp",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
execClone(args)
},
}
43 changes: 43 additions & 0 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
)

// completionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish]",
Short: "Generate shell completion scripts",
Long: `Generate shell completion scripts for dh-make-golang.
To load completions:

Bash:
$ source <(dh-make-golang completion bash)

Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ dh-make-golang completion zsh > "${fpath[1]}/_dh-make-golang"

Fish:
$ dh-make-golang completion fish | source
`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
}
},
}
17 changes: 17 additions & 0 deletions cmd/create_salsa_project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/spf13/cobra"
)

// createSalsaProjectCmd represents the create-salsa-project command
var createSalsaProjectCmd = &cobra.Command{
Use: "create-salsa-project <project-name>",
Short: "Create a project for hosting Debian packaging",
Long: `Create a project for hosting Debian packaging on Salsa.`,
Example: "dh-make-golang create-salsa-project golang-github-mattn-go-sqlite3",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
execCreateSalsaProject(args)
},
}
31 changes: 31 additions & 0 deletions cmd/estimate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"github.com/spf13/cobra"
)

var (
// Estimate command flags
estimateGitRevision string
)

// estimateCmd represents the estimate command
var estimateCmd = &cobra.Command{
Use: "estimate <go-module-importpath>",
Short: "Estimate the amount of work for a package",
Long: `Estimates the work necessary to bring <go-module-importpath> into Debian
by printing all currently unpacked repositories.`,
Example: "dh-make-golang estimate github.com/Debian/dh-make-golang",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
execEstimate(args)
},
}

func init() {
// Add flags to the estimate command
estimateCmd.Flags().StringVar(&estimateGitRevision, "git-revision", "",
"git revision (see gitrevisions(7)) of the specified Go package\n"+
"to estimate, defaulting to the default behavior of go get.\n"+
"Useful in case you do not want to estimate the latest version.")
}
37 changes: 37 additions & 0 deletions cmd/exports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

// This file contains exported functions from the main package
// that are used by the cobra commands.

// These functions should be imported from the main package
// and properly implemented here.

// Placeholder declarations for the exec* functions
// These should be replaced with the actual implementations
// from the main package.

var (
execSearch func(args []string)
execCreateSalsaProject func(args []string)
execEstimate func(args []string)
execMake func(args []string, usage func())
execClone func(args []string)
execCheckDepends func(args []string)
)

// SetExecFunctions sets the exec functions from the main package
func SetExecFunctions(
search func(args []string),
createSalsaProject func(args []string),
estimate func(args []string),
make func(args []string, usage func()),
clone func(args []string),
checkDepends func(args []string),
) {
execSearch = search
execCreateSalsaProject = createSalsaProject
execEstimate = estimate
execMake = make
execClone = clone
execCheckDepends = checkDepends
}
Loading