Skip to content

Commit deb2602

Browse files
committed
Initial commit
0 parents  commit deb2602

27 files changed

+4646
-0
lines changed

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
name: Build and Package All Binaries
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.23'
22+
check-latest: true
23+
24+
- name: Install Terraform
25+
uses: hashicorp/setup-terraform@v2
26+
with:
27+
terraform_version: 1.8.5
28+
29+
- name: Install UPX
30+
run: |
31+
sudo apt-get update
32+
sudo apt-get install -y upx
33+
34+
- name: Build and Compress All Binaries
35+
run: |
36+
mkdir -p build
37+
VERSION=$(git describe --tags --always --dirty || echo "unknown")
38+
COMMIT=$(git rev-parse --short HEAD || echo "unknown")
39+
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
40+
SHA256SUM_FILE="build/SHA256SUMS"
41+
> $SHA256SUM_FILE
42+
for os in linux windows darwin; do
43+
for arch in amd64 arm64; do
44+
EXT=""
45+
if [ "$os" == "windows" ]; then EXT=".exe"; fi
46+
OUTPUT="build/tmcg-${os}-${arch}${EXT}"
47+
echo "Building $OUTPUT..."
48+
GOOS=$os GOARCH=$arch go build -ldflags="-s -w -X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}' -X 'main.buildDate=${BUILD_DATE}'" -o $OUTPUT ./cmd/tmcg
49+
50+
# Compress the binary with UPX if supported
51+
if [[ "$os" == "darwin" || ( "$os" == "windows" && "$arch" == "arm64" ) ]]; then
52+
echo "Skipping UPX compression for $OUTPUT as it is not supported on macOS or Windows ARM."
53+
else
54+
echo "Compressing $OUTPUT..."
55+
upx --best --lzma "$OUTPUT"
56+
fi
57+
58+
# Generate SHA256 checksum for the binary
59+
echo "Generating checksum for $OUTPUT..."
60+
sha256sum "$OUTPUT" >> $SHA256SUM_FILE
61+
done
62+
done
63+
echo "All checksums written to $SHA256SUM_FILE"
64+
65+
- name: Upload Binaries
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: tmcg-binaries
69+
path: build/*
70+
71+
release:
72+
name: Create GitHub Release
73+
runs-on: ubuntu-latest
74+
needs: build
75+
76+
steps:
77+
- name: Download Binaries
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: tmcg-binaries
81+
82+
- name: Create Release
83+
uses: softprops/action-gh-release@v2
84+
with:
85+
files: |
86+
tmcg-*
87+
SHA256SUMS
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
paths-ignore:
11+
- '**/README.md'
12+
- '**/*.md'
13+
workflow_dispatch:
14+
15+
jobs:
16+
test:
17+
name: Test Code
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: '1.23'
28+
cache: true
29+
30+
- name: Install Terraform
31+
uses: hashicorp/setup-terraform@v2
32+
with:
33+
terraform_version: 1.8.5
34+
terraform_wrapper: false
35+
36+
- name: Install Dependencies
37+
run: |
38+
go mod tidy
39+
go mod download
40+
41+
- name: Install golangci-lint
42+
uses: golangci/golangci-lint-action@v3
43+
with:
44+
version: v1.62.2
45+
skip-cache: true
46+
47+
- name: Lint Code
48+
run: golangci-lint run ./...
49+
50+
- name: Install gotestsum
51+
run: go install gotest.tools/gotestsum@latest
52+
53+
- name: Run Unit Tests with Coverage
54+
run: |
55+
mkdir -p test-reports
56+
gotestsum --format=short-verbose --junitfile=test-reports/unit-test-report.xml -- -coverprofile=test-reports/coverage.txt ./...
57+
58+
- name: Upload Test Report
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: test-reports
62+
path: test-reports/
63+
64+
- name: Upload Coverage to Codecov
65+
uses: codecov/codecov-action@v5
66+
with:
67+
token: ${{ secrets.CODECOV_TOKEN }}
68+
files: test-reports/coverage.txt
69+
flags: unittests
70+
fail_ci_if_error: true
71+
verbose: true

.gitignore

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Binaries
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
*.out
8+
*.o
9+
10+
# Build directories
11+
/build/
12+
/bin/
13+
#/cmd/
14+
15+
# Dependency directories
16+
/vendor/
17+
18+
# Go specific files
19+
*.test
20+
*.prof
21+
*.log
22+
*.modcache/
23+
24+
# IDE and editor specific
25+
.idea/
26+
.vscode/
27+
*.swp
28+
*~
29+
.DS_Store
30+
*.sublime-workspace
31+
*.sublime-project
32+
33+
# Logs and runtime files
34+
*.log
35+
*.tmp
36+
*.pid
37+
*.lock
38+
39+
# Coverage files
40+
*.cover
41+
*.cov
42+
coverage.out
43+
44+
# Test results
45+
testdata/
46+
*_testresult.txt
47+
48+
# Other system files
49+
Thumbs.db
50+
51+
/terraform/
52+
/tmcg
53+
unit-test-report.xml
54+
coverage.*

.golangci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
run:
2+
timeout: 3m
3+
modules-download-mode: readonly
4+
5+
linters:
6+
enable:
7+
- revive
8+
- errcheck
9+
- gosimple
10+
- staticcheck
11+
- unused
12+
13+
issues:
14+
exclude-use-default: false
15+
max-issues-per-linter: 0
16+
max-same-issues: 0
17+
18+
linters-settings:
19+
revive:
20+
rules:
21+
- name: var-naming
22+
arguments:
23+
- ["ID", "HTTP", "URL"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 kbcz1989
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Variables
2+
APP_NAME := tmcg
3+
SRC_DIR := ./cmd/tmcg
4+
BUILD_DIR := ./bin
5+
TERRAFORM_DIR := ./terraform
6+
GOFLAGS := -v
7+
PLATFORMS := linux/amd64 linux/arm64 windows/amd64 windows/arm64 darwin/amd64 darwin/arm64
8+
OUTPUT_DIR := build
9+
VERSION := $(shell git describe --tags --always --dirty)
10+
COMMIT := $(shell git rev-parse --short HEAD)
11+
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
12+
13+
# Default target is to build the app
14+
.PHONY: all
15+
all: clean build
16+
17+
# Build target
18+
.PHONY: build
19+
build:
20+
@echo "Building the application..."
21+
@mkdir -p $(BUILD_DIR)
22+
mkdir -p $(OUTPUT_DIR)
23+
for platform in $(PLATFORMS); do \
24+
EXT=""; \
25+
if [ $${platform%/*} = "windows" ]; then EXT=".exe"; fi; \
26+
GOOS=$${platform%/*} GOARCH=$${platform#*/} go build -ldflags="-X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.buildDate=$(BUILD_DATE)'" -o $(OUTPUT_DIR)/$(APP_NAME)-$${platform%/*}-$${platform#*/}$$EXT $(SRC_DIR); \
27+
done
28+
29+
# Clean target to remove build artifacts and the terraform directory
30+
.PHONY: clean
31+
clean:
32+
@echo "Cleaning build artifacts..."
33+
@if [ -d $(BUILD_DIR) ]; then rm -vrf $(BUILD_DIR); fi
34+
@if [ -d $(TERRAFORM_DIR) ]; then rm -vrf $(TERRAFORM_DIR); fi
35+
@if [ -d $(OUTPUT_DIR) ]; then rm -vrf $(OUTPUT_DIR); fi
36+
37+
# Run target to run the built binary
38+
.PHONY: run
39+
run: build
40+
@echo "Running the application..."
41+
$(BUILD_DIR)/$(APP_NAME)
42+
43+
# Test target to run unit tests
44+
.PHONY: test
45+
test:
46+
@echo "Running tests..."
47+
gotestsum --format=short-verbose --junitfile=unit-test-report.xml ./...
48+
49+
# Lint target to check code with golangci-lint
50+
.PHONY: lint
51+
lint:
52+
@echo "Linting code..."
53+
@golangci-lint run ./...
54+
55+
# Format target to ensure code style
56+
.PHONY: fmt
57+
fmt:
58+
@echo "Formatting code..."
59+
@go fmt ./...
60+
61+
# Help target to list available commands
62+
.PHONY: help
63+
help:
64+
@echo "Makefile targets:"
65+
@echo " all - Build the application (default)."
66+
@echo " build - Build the application."
67+
@echo " clean - Clean the build artifacts and terraform directory."
68+
@echo " run - Run the application."
69+
@echo " test - Run tests."
70+
@echo " lint - Run linter."
71+
@echo " fmt - Format code."
72+
@echo " help - Show this help message."
73+

0 commit comments

Comments
 (0)