Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit d1b1b22

Browse files
author
Tuxx
committed
project structure, build system & git hooks.
- Moved all non-main Go files into internal/ for cleaner separation - Introduced Makefile with multi-arch support (amd64, arm64, arm) - Embedded version metadata (git tag, commit, build date) via ldflags - Updated GitHub Actions to use Makefile for builds and packaging - Added native `-v` flag using embedded version info - Updated README.md with new build instructions and make targets - Added .githooks to run go fmt before commit. This sets up FancyLock for clean CI builds, multi-platform releases (thought we still only builds amd64 for now), and future expansion 🎉 (*HAPPY HAKKR NOISES*)
1 parent b965402 commit d1b1b22

File tree

15 files changed

+273
-60
lines changed

15 files changed

+273
-60
lines changed

.githooks/pre-commit

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
echo "🔧 Running go fmt on staged Go files..."
4+
5+
staged_go_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
6+
7+
if [ -z "$staged_go_files" ]; then
8+
echo "✅ No Go files staged. Skipping go fmt."
9+
exit 0
10+
fi
11+
12+
formatted_any=0
13+
14+
for file in $staged_go_files; do
15+
if [ -f "$file" ]; then
16+
original_hash=$(git hash-object "$file")
17+
go fmt "$file" > /dev/null
18+
new_hash=$(git hash-object "$file")
19+
if [ "$original_hash" != "$new_hash" ]; then
20+
git add "$file"
21+
echo "✨ Formatted and re-staged: $file"
22+
formatted_any=1
23+
fi
24+
fi
25+
done
26+
27+
if [ "$formatted_any" -eq 1 ]; then
28+
echo "go fmt was applied." > .git/.gofmt-flag
29+
fi
30+
31+
echo "✅ Formatting complete."
32+
exit 0

.githooks/prepare-commit-msg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Only append note if gofmt flag is present
4+
if [ -f .git/.gofmt-flag ]; then
5+
echo "" >> "$1"
6+
echo "[auto] go fmt applied to staged files" >> "$1"
7+
rm .git/.gofmt-flag
8+
fi
9+

.githooks/setup-hooks.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
echo "🔧 Setting up Git hooks..."
3+
git config core.hooksPath .githooks
4+
echo "✅ Git hooks installed!"

.github/workflows/build.yml

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11-
env:
12-
GOOS: linux
13-
GOARCH: amd64
1411
outputs:
1512
build_success: ${{ steps.build_step.outputs.build_success }}
1613
steps:
@@ -20,36 +17,36 @@ jobs:
2017
- name: Set up Go
2118
uses: actions/setup-go@v4
2219
with:
23-
go-version: '1.24.0' # adjust as needed
20+
go-version: '1.24.0'
2421

25-
- name: Install dependencies and build binary
26-
id: build_step
22+
- name: Install dependencies
2723
run: |
28-
# Install PAM development libraries
2924
sudo apt-get update
30-
sudo apt-get install -y libpam0g-dev
31-
32-
# Build the project and produce the binary "fancylock"
33-
go build -ldflags="-s -w" -o fancylock .
34-
35-
# If we get here, build succeeded
25+
sudo apt-get install -y libpam0g-dev make
26+
27+
- name: Build all binaries with Makefile
28+
id: build_step
29+
run: |
30+
make amd64
31+
make package
3632
echo "build_success=true" >> $GITHUB_OUTPUT
3733
continue-on-error: true
3834

35+
- name: Print version info
36+
if: steps.build_step.outputs.build_success == 'true'
37+
run: |
38+
./bin/fancylock-linux-amd64 --version || echo "Version info not available"
39+
3940
- name: Check if build succeeded
4041
if: steps.build_step.outputs.build_success != 'true'
4142
run: exit 1
4243

43-
- name: Archive binary
44-
if: steps.build_step.outputs.build_success == 'true'
45-
run: tar -czvf fancylock-linux.tar.gz fancylock
46-
47-
- name: Upload artifact for release job
44+
- name: Upload dist/ artifacts
4845
if: steps.build_step.outputs.build_success == 'true'
49-
uses: actions/upload-artifact@v4.6.2
46+
uses: actions/upload-artifact@v4
5047
with:
51-
name: fancylock-artifact
52-
path: fancylock-linux.tar.gz
48+
name: fancylock-artifacts
49+
path: dist/
5350
retention-days: 1
5451

5552
release:
@@ -59,11 +56,12 @@ jobs:
5956
steps:
6057
- name: Checkout code
6158
uses: actions/checkout@v3
62-
63-
- name: Download build artifact
59+
60+
- name: Download artifacts
6461
uses: actions/download-artifact@v4
6562
with:
66-
name: fancylock-artifact
63+
name: fancylock-artifacts
64+
path: dist/
6765

6866
- name: Get commit message for release notes
6967
id: get_release_notes
@@ -73,12 +71,12 @@ jobs:
7371
echo "EOF" >> $GITHUB_OUTPUT
7472
7573
- name: Create GitHub Release
76-
id: create_release
7774
uses: softprops/action-gh-release@v1
7875
with:
7976
tag_name: ${{ github.ref_name }}
8077
name: Release ${{ github.ref_name }}
8178
body: ${{ steps.get_release_notes.outputs.release_notes }}
82-
files: fancylock-linux.tar.gz
79+
files: dist/*.tar.gz
8380
env:
8481
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
APP := fancylock
2+
ARCHES := amd64 arm64 arm
3+
BIN := bin
4+
DIST := dist
5+
INSTALL_PATH := /usr/local/bin
6+
7+
# Git version metadata
8+
GIT_COMMIT := $(shell git rev-parse --short HEAD)
9+
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
10+
VERSION := $(shell git describe --tags --always --dirty)
11+
12+
# ldflags for embedding version info
13+
LDFLAGS := -ldflags="-s -w \
14+
-X github.com/tuxx/fancylock/internal.Version=$(VERSION) \
15+
-X github.com/tuxx/fancylock/internal.Commit=$(GIT_COMMIT) \
16+
-X github.com/tuxx/fancylock/internal.BuildDate=$(BUILD_DATE)"
17+
18+
.PHONY: all clean native package install check-go $(ARCHES)
19+
20+
all: check-go $(ARCHES)
21+
22+
$(BIN):
23+
mkdir -p $(BIN)
24+
25+
$(DIST):
26+
mkdir -p $(DIST)
27+
28+
check-go:
29+
@command -v go >/dev/null 2>&1 || { echo >&2 "Go is not installed. Please install Go before continuing."; exit 1; }
30+
31+
$(ARCHES): | $(BIN)
32+
GOOS=linux GOARCH=$@ CGO_ENABLED=1 go build $(LDFLAGS) -o $(BIN)/$(APP)-linux-$@ main.go
33+
34+
native: check-go | $(BIN)
35+
CGO_ENABLED=1 go build $(LDFLAGS) -o $(BIN)/$(APP)-native main.go
36+
37+
package: | $(DIST)
38+
@for arch in $(ARCHES); do \
39+
tar -czvf $(DIST)/$(APP)-linux-$$arch.tar.gz -C $(BIN) $(APP)-linux-$$arch ; \
40+
done
41+
@if [ -f $(BIN)/$(APP)-native ]; then \
42+
tar -czvf $(DIST)/$(APP)-native.tar.gz -C $(BIN) $(APP)-native ; \
43+
fi
44+
45+
install: native
46+
@install -Dm755 $(BIN)/$(APP)-native $(INSTALL_PATH)/$(APP)
47+
@echo "Installed $(APP)-native to $(INSTALL_PATH)/$(APP)"
48+
49+
clean:
50+
rm -rf $(BIN) $(DIST)

0 commit comments

Comments
 (0)