Skip to content

Commit cd55e2f

Browse files
committed
chore: Add Makefile
1 parent 884b90d commit cd55e2f

2 files changed

Lines changed: 104 additions & 15 deletions

File tree

Makefile

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Makefile for github-org-repos-sync
2+
3+
# Variables
4+
BINARY_NAME := github-org-repos-sync
5+
MODULE_NAME := github.com/xbglowx/github-org-repos-sync
6+
VERSION_PACKAGE := $(MODULE_NAME)/cmd
7+
BUILD_DIR := ./bin
8+
9+
# Version detection - use git tags if available, otherwise use short git SHA for source builds
10+
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null)
11+
GIT_TAG := $(shell git describe --tags --exact-match 2>/dev/null)
12+
# Dirty detection: Repository is "clean" only if ALL conditions are true:
13+
# 1. No unstaged changes (git diff --quiet returns 0)
14+
# 2. No staged changes (git diff --quiet --cached returns 0)
15+
# 3. No untracked files (git status --porcelain is empty)
16+
# If ANY condition fails, the && chain fails and executes || echo "-dirty"
17+
GIT_DIRTY := $(shell git diff --quiet 2>/dev/null && git diff --quiet --cached 2>/dev/null && [ -z "$$(git status --porcelain 2>/dev/null)" ] || echo "-dirty")
18+
19+
# If we have an exact tag match, use it; otherwise use git SHA for source builds
20+
ifdef GIT_TAG
21+
VERSION := $(GIT_TAG)$(GIT_DIRTY)
22+
else ifdef GIT_SHA
23+
VERSION := $(GIT_SHA)$(GIT_DIRTY)
24+
else
25+
VERSION := dev-unknown
26+
endif
27+
28+
# Go build flags
29+
LDFLAGS := -X $(VERSION_PACKAGE).Version=$(VERSION)
30+
BUILD_FLAGS := -ldflags "$(LDFLAGS)"
31+
32+
# Platform detection for local builds
33+
GOOS := $(shell go env GOOS)
34+
GOARCH := $(shell go env GOARCH)
35+
GO_VERSION := $(shell go version)
36+
37+
# Cross-compilation targets
38+
PLATFORMS := \
39+
linux/amd64 \
40+
linux/arm64 \
41+
darwin/amd64 \
42+
darwin/arm64 \
43+
windows/amd64 \
44+
windows/arm64
45+
46+
.PHONY: help build build-all test version info clean
47+
48+
# Default target
49+
all: test build
50+
51+
# Help target
52+
help:
53+
@printf "%s\n" \
54+
"Available targets:" \
55+
" build - Build binary for current platform" \
56+
" build-all - Build binaries for all platforms" \
57+
" test - Run tests" \
58+
" clean - Clean build artifacts" \
59+
" version - Show version that would be built" \
60+
" info - Show build information" \
61+
" help - Show this help message"
62+
63+
# Show version
64+
version:
65+
@echo "Version: $(VERSION)"
66+
67+
# Build for current platform
68+
build:
69+
@echo "Building $(BINARY_NAME) v$(VERSION) for $(GOOS)/$(GOARCH)..."
70+
@mkdir -p $(BUILD_DIR)
71+
go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
72+
73+
# Build for all platforms
74+
build-all:
75+
@echo "Building $(BINARY_NAME) v$(VERSION) for all platforms..."
76+
@mkdir -p $(BUILD_DIR)
77+
@$(foreach platform,$(PLATFORMS), \
78+
echo "Building for $(platform)..."; \
79+
GOOS=$(word 1,$(subst /, ,$(platform))) \
80+
GOARCH=$(word 2,$(subst /, ,$(platform))) \
81+
go build $(BUILD_FLAGS) \
82+
-o $(BUILD_DIR)/$(BINARY_NAME)-$(word 1,$(subst /, ,$(platform)))-$(word 2,$(subst /, ,$(platform)))$(if $(findstring windows,$(platform)),.exe) . && \
83+
) true
84+
85+
# Run tests
86+
test:
87+
@echo "Running tests..."
88+
go test -v -race ./...
89+
90+
# Clean build artifacts
91+
clean:
92+
@echo "Cleaning build artifacts..."
93+
rm -rf $(BUILD_DIR)
94+
95+
# Print build information
96+
info:
97+
@printf "%s\n" \
98+
"Build Information:" \
99+
" Binary Name: $(BINARY_NAME)" \
100+
" Module: $(MODULE_NAME)" \
101+
" Version: $(VERSION)" \
102+
" Go Version: $(GO_VERSION)" \
103+
" Platform: $(GOOS)/$(GOARCH)" \
104+
" Build Dir: $(BUILD_DIR)"

go.sum

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
21
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
32
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
43
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@@ -10,24 +9,10 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17
109
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
1110
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1211
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
13-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
14-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
15-
github.com/spf13/cobra v1.9.0 h1:Py5fIuq/lJsRYxcxfOtsJqpmwJWCMOUy2tMJYV8TNHE=
16-
github.com/spf13/cobra v1.9.0/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
1712
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
1813
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
19-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
20-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
2114
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
2215
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
23-
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
24-
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
25-
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
26-
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
27-
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
28-
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
29-
golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98=
30-
golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
3116
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
3217
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
3318
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 commit comments

Comments
 (0)