Skip to content

Commit 40f6237

Browse files
Add repo setup: release workflow, Makefile, docs, editorconfig, pre-commit, Go matrix CI
Agent-Logs-Url: https://github.com/scutuatua-crypto/gh-ost/sessions/bfcb407c-6969-4a6a-84ab-bbcbde06398a Co-authored-by: scutuatua-crypto <244154987+scutuatua-crypto@users.noreply.github.com>
1 parent ea72f75 commit 40f6237

9 files changed

Lines changed: 340 additions & 4 deletions

File tree

.editorconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = tab
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.go]
12+
indent_style = tab
13+
indent_size = 4
14+
15+
[*.{yml,yaml}]
16+
indent_style = space
17+
indent_size = 2
18+
19+
[*.{md,txt}]
20+
trim_trailing_whitespace = false
21+
22+
[Makefile]
23+
indent_style = tab
24+
25+
[*.sh]
26+
indent_style = tab
27+
indent_size = 4

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ updates:
55
directory: "/"
66
schedule:
77
interval: daily
8+
- package-ecosystem: gomod
9+
directory: "/"
10+
schedule:
11+
interval: weekly

.github/workflows/ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@ name: CI
22
permissions:
33
contents: read
44

5-
on: [pull_request]
5+
on:
6+
push:
7+
branches:
8+
- master
9+
pull_request:
610

711
jobs:
812
build:
9-
1013
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
go-version: ['1.22', '1.23']
1117

1218
steps:
1319
- uses: actions/checkout@v4
1420

15-
- name: Set up Go
21+
- name: Set up Go ${{ matrix.go-version }}
1622
uses: actions/setup-go@v6
1723
with:
18-
go-version-file: go.mod
24+
go-version: ${{ matrix.go-version }}
1925

2026
- name: Build
2127
run: script/cibuild
2228

2329
- name: Upload gh-ost binary artifact
30+
if: matrix.go-version == '1.23'
2431
uses: actions/upload-artifact@v4
2532
with:
2633
name: gh-ost

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v6
21+
with:
22+
go-version-file: go.mod
23+
24+
- name: Install fpm
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y ruby-dev build-essential
28+
sudo gem install fpm
29+
30+
- name: Build release binaries
31+
env:
32+
RELEASE_VERSION: ${{ github.ref_name }}
33+
run: |
34+
bash build.sh
35+
36+
- name: Create GitHub Release
37+
uses: softprops/action-gh-release@v2
38+
with:
39+
files: /tmp/gh-ost-release/gh-ost-binary-*
40+
generate_release_notes: true

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
exclude: '\.md$'
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
- id: check-json
10+
- id: check-merge-conflict
11+
- id: check-added-large-files
12+
args: ['--maxkb=1024']
13+
- id: mixed-line-ending
14+
args: ['--fix=lf']
15+
16+
- repo: https://github.com/dnephin/pre-commit-golang
17+
rev: v0.5.1
18+
hooks:
19+
- id: go-fmt
20+
- id: go-vet
21+
- id: go-unit-tests

CODE_OF_CONDUCT.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to a positive environment:
10+
- Using welcoming and inclusive language
11+
- Being respectful of differing viewpoints and experiences
12+
- Gracefully accepting constructive criticism
13+
- Focusing on what is best for the community
14+
15+
Examples of unacceptable behavior:
16+
- Harassment, trolling, or insulting comments
17+
- Publishing others' private information without permission
18+
- Other conduct which could reasonably be considered inappropriate
19+
20+
## Enforcement
21+
22+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the project maintainers. All complaints will be reviewed and investigated.
23+
24+
## Attribution
25+
26+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.

DEVELOPMENT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Development Guide
2+
3+
This document explains how to set up your local development environment for gh-ost.
4+
5+
## Prerequisites
6+
7+
- **Go 1.23+**[Install Go](https://golang.org/doc/install)
8+
- **MySQL 5.7+ or 8.0+** – for integration tests
9+
- **Docker & Docker Compose** – for running replica-based tests
10+
- **golangci-lint** – for linting (optional, also runs in CI)
11+
12+
## Getting Started
13+
14+
### 1. Clone the repository
15+
16+
```bash
17+
git clone https://github.com/scutuatua-crypto/gh-ost.git
18+
cd gh-ost
19+
```
20+
21+
### 2. Install dependencies
22+
23+
```bash
24+
go mod download
25+
```
26+
27+
### 3. Build the binary
28+
29+
```bash
30+
make build
31+
# Binary is placed in ./bin/gh-ost
32+
```
33+
34+
### 4. Run unit tests
35+
36+
```bash
37+
make test
38+
```
39+
40+
### 5. Run linting
41+
42+
Install golangci-lint:
43+
44+
```bash
45+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
46+
```
47+
48+
Then run:
49+
50+
```bash
51+
make lint
52+
```
53+
54+
## Using the Makefile
55+
56+
The repository ships with a `Makefile` for common tasks:
57+
58+
| Target | Description |
59+
|----------------|----------------------------------------------|
60+
| `make build` | Compile the gh-ost binary into `./bin/` |
61+
| `make test` | Run unit tests with coverage |
62+
| `make lint` | Run golangci-lint static analysis |
63+
| `make fmt` | Format all Go source files with `gofmt -s` |
64+
| `make vet` | Run `go vet` on all packages |
65+
| `make clean` | Remove build artifacts |
66+
| `make deps` | Download and tidy Go modules |
67+
| `make cibuild` | Full CI build (format, build, test) |
68+
69+
## Running Replica Integration Tests
70+
71+
Integration tests spin up a MySQL primary + replica using Docker Compose.
72+
73+
### Using Docker Compose directly
74+
75+
```bash
76+
# Start the test environment
77+
docker compose up -d
78+
79+
# Run the tests
80+
bash test.sh
81+
82+
# Tear down
83+
docker compose down
84+
```
85+
86+
### Using the helper script
87+
88+
```bash
89+
script/docker-gh-ost-replica-tests
90+
```
91+
92+
## Code Structure
93+
94+
```
95+
.
96+
├── go/
97+
│ ├── base/ – Core types, context, configuration
98+
│ ├── binlog/ – Binlog reader / DML event handling
99+
│ ├── cmd/ – Main entry point
100+
│ ├── logic/ – Migration orchestration (migrator, applier, inspector, throttler…)
101+
│ ├── mysql/ – MySQL binlog utilities and instance inspection
102+
│ └── sql/ – SQL parsing and query building
103+
├── localtests/ – Shell-based local integration tests
104+
├── resources/ – Packaging resources (systemd units, etc.)
105+
├── script/ – CI and development helper scripts
106+
└── vendor/ – Vendored Go dependencies
107+
```
108+
109+
## Code Style
110+
111+
- Follow the official [Effective Go](https://golang.org/doc/effective_go) guidelines.
112+
- Run `make fmt` before committing to ensure consistent formatting.
113+
- All new code must pass `go vet` and `golangci-lint`.
114+
115+
## Pre-commit Hooks (optional)
116+
117+
Install [pre-commit](https://pre-commit.com/) and set up the hooks:
118+
119+
```bash
120+
pip install pre-commit
121+
pre-commit install
122+
```
123+
124+
The hooks will automatically check formatting and run `go vet` on every commit.
125+
126+
## Submitting Changes
127+
128+
Please read [CONTRIBUTING.md](.github/CONTRIBUTING.md) before opening a pull request.

Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.PHONY: all build test lint fmt vet clean deps help
2+
3+
BINARY_NAME=gh-ost
4+
BUILD_DIR=bin
5+
GO_FILES=$(shell find go -name '*.go' -not -path '*/vendor/*')
6+
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
7+
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
8+
LDFLAGS=-ldflags "-X main.AppVersion=$(VERSION) -X main.GitCommit=$(COMMIT)"
9+
10+
all: build
11+
12+
## build: Build the gh-ost binary
13+
build:
14+
mkdir -p $(BUILD_DIR)
15+
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./go/cmd/gh-ost/main.go
16+
17+
## test: Run unit tests
18+
test:
19+
go test -v -covermode=atomic -coverprofile=coverage.out ./go/...
20+
21+
## test-cover: Run tests and open coverage report
22+
test-cover: test
23+
go tool cover -html=coverage.out
24+
25+
## lint: Run golangci-lint
26+
lint:
27+
golangci-lint run ./...
28+
29+
## fmt: Format code with gofmt
30+
fmt:
31+
gofmt -s -w go/
32+
33+
## vet: Run go vet
34+
vet:
35+
go vet ./go/...
36+
37+
## clean: Remove build artifacts
38+
clean:
39+
rm -rf $(BUILD_DIR)/ .gopath/ coverage.out
40+
41+
## deps: Download dependencies
42+
deps:
43+
go mod download
44+
go mod tidy
45+
46+
## vendor: Vendor dependencies
47+
vendor:
48+
go mod vendor
49+
50+
## cibuild: Run the full CI build (format check, build, test)
51+
cibuild:
52+
script/cibuild
53+
54+
## docker-test: Run replica tests in Docker
55+
docker-test:
56+
script/docker-gh-ost-replica-tests
57+
58+
## help: Show this help message
59+
help:
60+
@echo "Usage: make [target]"
61+
@echo ""
62+
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'

SECURITY.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
|---------|--------------------|
7+
| latest | :white_check_mark: |
8+
| older | :x: |
9+
10+
## Reporting a Vulnerability
11+
12+
Please **do not** report security vulnerabilities through public GitHub issues.
13+
14+
Instead, please report them by emailing the maintainers directly or using [GitHub's private vulnerability reporting](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability).
15+
16+
Include as much detail as possible:
17+
- A description of the vulnerability
18+
- Steps to reproduce
19+
- Potential impact
20+
21+
You should receive a response within 72 hours. If the issue is confirmed, a patch will be released as soon as possible.

0 commit comments

Comments
 (0)