Skip to content

Commit 4e18cd1

Browse files
Initialize project with core structure, including go.mod, main package, database dump/restore utilities, S3 integration, install script, Makefile, and GitHub CI workflow for releases.
1 parent 212e76d commit 4e18cd1

File tree

8 files changed

+752
-0
lines changed

8 files changed

+752
-0
lines changed

.github/workflows/release.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Release
2+
3+
# This workflow is triggered on pushes to the repository that include a tag matching 'v*.*.*'
4+
on:
5+
push:
6+
tags:
7+
- 'v*.*.*'
8+
9+
jobs:
10+
build-and-release:
11+
# Job name
12+
name: Build and Release
13+
# The type of runner that the job will run on, based on the matrix
14+
runs-on: ${{ matrix.os }}
15+
# A matrix of configurations for each build
16+
strategy:
17+
matrix:
18+
include:
19+
# Linux x86_64 build
20+
- os: ubuntu-latest
21+
goos: linux
22+
goarch: amd64
23+
# Windows x86_64 build
24+
- os: windows-latest
25+
goos: windows
26+
goarch: amd64
27+
# macOS x86_64 build
28+
- os: macos-latest
29+
goos: darwin
30+
goarch: amd64
31+
# macOS Arm64 build
32+
- os: macos-latest
33+
goos: darwin
34+
goarch: arm64
35+
36+
steps:
37+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
# Sets up a Go environment
42+
- name: Set up Go
43+
uses: actions/setup-go@v5
44+
with:
45+
go-version: '1.24'
46+
47+
# Synchronize go.mod dependencies
48+
- name: Tidy
49+
run: go mod tidy
50+
51+
# Build the binary and create a compressed archive
52+
- name: Build
53+
id: build
54+
env:
55+
# Set the target operating system and architecture
56+
GOOS: ${{ matrix.goos }}
57+
GOARCH: ${{ matrix.goarch }}
58+
run: |
59+
# Define binary and asset names
60+
BINARY_NAME=dbdump
61+
ASSET_NAME="dbdump-${{ matrix.goos }}-${{ matrix.goarch }}"
62+
63+
# Adjust binary name for Windows and build
64+
if [ "${{ matrix.goos }}" = "windows" ]; then
65+
BINARY_NAME+=".exe"
66+
go build -ldflags="-s -w" -o ${BINARY_NAME} ./cmd/dbdump
67+
# Create a .zip archive for Windows
68+
7z a ${ASSET_NAME}.zip ${BINARY_NAME}
69+
echo "asset_path=${ASSET_NAME}.zip" >> $GITHUB_ENV
70+
else
71+
go build -ldflags="-s -w" -o ${BINARY_NAME} ./cmd/dbdump
72+
# Create a .tar.gz archive for Linux and macOS
73+
tar czvf ${ASSET_NAME}.tar.gz ${BINARY_NAME}
74+
echo "asset_path=${ASSET_NAME}.tar.gz" >> $GITHUB_ENV
75+
fi
76+
77+
# Create a GitHub release and upload the build artifact
78+
- name: Release
79+
uses: softprops/action-gh-release@v2
80+
with:
81+
# The files to upload to the release
82+
files: ${{ env.asset_path }}

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Makefile for the Go Database Backup Tool
2+
3+
# Define the name of the final binary
4+
BINARY_NAME=dbdump
5+
6+
# Define the path to the main package
7+
SRC_DIR=./cmd/dbdump
8+
9+
# Go linker flags to reduce binary size for release builds.
10+
# -s: Omit the symbol table.
11+
# -w: Omit the DWARF debug information.
12+
LDFLAGS_RELEASE = -ldflags="-s -w"
13+
14+
# Default target executed when you just run `make`
15+
.PHONY: all
16+
all: build
17+
18+
# Build the application binary for development (includes debug info)
19+
.PHONY: build
20+
build: tidy
21+
@echo "Building $(BINARY_NAME) for development..."
22+
@go build -o $(BINARY_NAME) $(SRC_DIR)
23+
@echo "$(BINARY_NAME) built successfully."
24+
25+
# Build a small, optimized release binary
26+
# This strips debug information to significantly reduce the file size.
27+
.PHONY: build-release
28+
build-release: tidy
29+
@echo "Building $(BINARY_NAME) for release (optimized for size)..."
30+
@go build $(LDFLAGS_RELEASE) -o $(BINARY_NAME) $(SRC_DIR)
31+
@echo "Release binary built successfully."
32+
33+
# Run the application
34+
# Example: make run ARGS="--all --type=postgres --pgpassword=your_pass"
35+
.PHONY: run
36+
run: build
37+
@echo "Running $(BINARY_NAME) with arguments: $(ARGS)"
38+
@./$(BINARY_NAME) $(ARGS)
39+
40+
# Tidy Go modules
41+
.PHONY: tidy
42+
tidy:
43+
@echo "Tidying Go modules..."
44+
@go mod tidy
45+
46+
# Clean up build artifacts
47+
.PHONY: clean
48+
clean:
49+
@echo "Cleaning up..."
50+
@rm -f $(BINARY_NAME)
51+
@echo "Cleanup complete."
52+
53+
# Display help message
54+
.PHONY: help
55+
help:
56+
@echo "Available commands:"
57+
@echo " build - Build the application binary for development."
58+
@echo " build-release - Build a small, optimized release binary."
59+
@echo " run - Build and run the application. Use ARGS=\"...\" to pass flags."
60+
@echo " Example: make run ARGS=\"--all --pgpassword=secret\""
61+
@echo " tidy - Synchronize go.mod dependencies."
62+
@echo " clean - Remove the compiled binary."
63+
@echo " help - Display this help message."
64+

0 commit comments

Comments
 (0)