Skip to content

Commit

Permalink
chore(*): -
Browse files Browse the repository at this point in the history
  • Loading branch information
enenumxela committed Dec 1, 2024
1 parent 11c029e commit b1c1472
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 264 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ updates:
schedule:
interval: "weekly"
target-branch: "dev"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "Type: Maintenance"
-
package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
target-branch: "dev"
commit-message:
prefix: "chore"
include: "scope"
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ jobs:
with:
go-version: '>=1.23'
-
name: Checkout the repository
name: Code Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Go modules hygine
-
name: Go Module Management
run: |
go clean -modcache
go mod tidy
make go-mod-clean
make go-mod-tidy
working-directory: .
-
name: Go build
run: go build -v .
working-directory: ./cmd/xurlfind3r
name: Go Build
run: |
make go-build
working-directory: .
16 changes: 12 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
security-events: write
steps:
-
name: Checkout the repository
name: Code Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -38,9 +38,17 @@ jobs:
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
-
name: Autobuild
uses: github/codeql-action/autobuild@v3
-
name: Go Module Management
run: |
make go-mod-clean
make go-mod-tidy
working-directory: .
-
name: Go Build
run: |
make go-build
working-directory: .
-
name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
15 changes: 7 additions & 8 deletions .github/workflows/dockerhub-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
push:
name: DockerHub Push
name: DockerHub Push
runs-on: ubuntu-latest
permissions:
packages: write
Expand All @@ -18,24 +18,23 @@ jobs:
id-token: write
steps:
-
name: Checkout
name: Code Checkout
uses: actions/checkout@v4

with:
fetch-depth: 0
-
name: Get Github tag
name: Get Github Tag
id: meta
run: |
curl --silent "https://api.github.com/repos/hueristiq/xurlfind3r/releases/latest" | jq -r .tag_name | xargs -I {} echo TAG={} >> $GITHUB_OUTPUT
-
name: Log in to Docker Hub
uses: docker/login-action@v3
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

-
name: Build and push Docker image
name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ jobs:
go-version: '>=1.23'
cache: false
-
name: Checkout the repository
name: Code Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Run golangci-lint
name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0
version: v1.62.2
args: --timeout 5m
working-directory: .
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
with:
go-version: '>=1.23'
-
name: Checkout the repository
name: Code Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Run GoReleaser
name: GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
Expand All @@ -33,4 +33,4 @@ jobs:
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DISCORD_WEBHOOK_ID: "${{ secrets.DISCORD_WEBHOOK_ID }}"
DISCORD_WEBHOOK_TOKEN: "${{ secrets.DISCORD_WEBHOOK_TOKEN }}"
DISCORD_WEBHOOK_TOKEN: "${{ secrets.DISCORD_WEBHOOK_TOKEN }}"
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FROM golang:1.23.1-alpine3.20 AS build-stage
RUN <<EOF
apk --no-cache update
apk --no-cache upgrade

apk --no-cache add ca-certificates curl gcc g++ git make
EOF

Expand Down Expand Up @@ -49,9 +50,11 @@ FROM alpine:3.20.3
RUN <<EOF
apk --no-cache update
apk --no-cache upgrade

apk --no-cache add bind-tools ca-certificates

addgroup runners

adduser runner -D -G runners
EOF

Expand Down
92 changes: 23 additions & 69 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,143 +1,94 @@
# Set the default shell to `/bin/sh` for executing commands in the Makefile.
# `/bin/sh` is used as it is lightweight and widely available across UNIX systems.
SHELL = /bin/sh

# Define the project name for easy reference throughout the Makefile.
# This helps in maintaining a consistent project name and avoiding hardcoding it in multiple places.
PROJECT = "xurlfind3r"
PROJECT = xurlfind3r

# The default target that gets executed when the `make` command is run without arguments.
# In this case, it will trigger the `go-build` target.
all: go-build

# --- Prepare | Setup -------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------
# --- Prepare | Setup ------------------------------------------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------

.PHONY: prepare
prepare:
@# Install the latest version of Lefthook (a Git hooks manager) and set it up.
go install github.com/evilmartians/lefthook@latest && lefthook install

# --- Go(Golang) ------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------
# --- Go (Golang) ----------------------------------------------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------

# Define common Go commands with variables for reusability and easier updates.
GOCMD=go
GOCLEAN=$(GOCMD) clean
GOMOD=$(GOCMD) mod
GOGET=$(GOCMD) get
GOFMT=$(GOCMD) fmt
GOTEST=$(GOCMD) test
GOBUILD=$(GOCMD) build
GOINSTALL=$(GOCMD) install

# Define Go build flags for verbosity and linking.
# Verbose flag for Go commands, helpful for debugging and understanding output.
GOFLAGS := -v
# Linker flags:
# - `-s` removes the symbol table for a smaller binary size.
# - `-w` removes DWARF debugging information.
LDFLAGS := -s -w

# Enable static linking on non-macOS platforms.
# This embeds all dependencies directly into the binary, making it more portable.
ifneq ($(shell go env GOOS),darwin)
LDFLAGS := -extldflags "-static"
endif

# Define Golangci-lint command for linting Go code.
GOLANGCILINTCMD=golangci-lint
GOLANGCILINTRUN=$(GOLANGCILINTCMD) run

# --- Go Module Management
.PHONY: go-mod-clean
go-mod-clean:
$(GOCLEAN) -modcache

# Tidy Go modules
# This cleans up `go.mod` and `go.sum` by removing unused dependencies
# and ensuring that only the required packages are listed.
.PHONY: go-mod-tidy
go-mod-tidy:
$(GOMOD) tidy

# Update Go modules
# Updates all Go dependencies to their latest versions, including both direct and indirect dependencies.
# Useful for staying up-to-date with upstream changes and bug fixes.
.PHONY: go-mod-update
go-mod-update:
@# Update test dependencies.
$(GOGET) -f -t -u ./...
@# Update all other dependencies.
$(GOGET) -f -u ./...

# --- Go Code Quality and Testing

# Format Go code
# Formats all Go source files in the current module according to Go's standard rules.
# Consistent formatting is crucial for code readability and collaboration.
.PHONY: go-fmt
go-fmt:
$(GOFMT) ./...

# Lint Go code
# Runs static analysis checks on the Go code using Golangci-lint.
# Ensures the code adheres to best practices and is free from common issues.
# This target also runs `go-fmt` beforehand to ensure the code is formatted.
.PHONY: go-lint
go-lint: go-fmt
$(GOLANGCILINTRUN) $(GOLANGCILINT) ./...

# Run Go tests
# Executes all unit tests in the module with detailed output.
# The `GOFLAGS` variable is used to enable verbosity, making it easier to debug test results.
.PHONY: go-test
go-test:
$(GOTEST) $(GOFLAGS) ./...

# --- Go Build and Install

# Build Go program
# This target compiles the Go source code and generates a binary in the `bin/` directory.
# The output binary is named after the project (`xsubfind3r`), and the source entry point is the main file in `cmd/$(PROJECT)/main.go`.
# The `LDFLAGS` flag is passed to optimize the binary size by stripping debug information.
.PHONY: go-build
go-build:
$(GOBUILD) $(GOFLAGS) -ldflags '$(LDFLAGS)' -o bin/$(PROJECT) cmd/$(PROJECT)/main.go

# Install Go program
# This target installs the Go program by compiling and placing it in the system's Go bin directory.
# Use this to make the application globally available on the system.
.PHONY: go-install
go-install:
$(GOINSTALL) $(GOFLAGS) ./...

# --- Docker ------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------
# --- Docker ---------------------------------------------------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------

# Define common Docker commands with variables for reusability.
DOCKERCMD = docker
DOCKERBUILD = $(DOCKERCMD) build

# Define the path to the Dockerfile.
# The Dockerfile is located in the root directory by default.
DOCKERFILE := ./Dockerfile

# Define the Docker image name and tag.
# The image name is based on the project name, and the tag is extracted from the version in the configuration file.
IMAGE_NAME = hueristiq/$(PROJECT)
IMAGE_TAG = $(shell cat internal/configuration/configuration.go | grep "VERSION =" | sed 's/.*VERSION = "\([0-9.]*\)".*/\1/')
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)

# Build Docker image
# This target builds the Docker image using the Dockerfile.
# It tags the image with both the specific version and `latest` for convenience.
.PHONY: docker-build
docker-build:
@$(DOCKERBUILD) \
-f $(DOCKERFILE) \
-t $(IMAGE) \
-t $(IMAGE_NAME):latest \
.
@$(DOCKERBUILD) -f $(DOCKERFILE) -t $(IMAGE) -t $(IMAGE_NAME):latest .

# --- Help -----------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------------------------------------------------------
# --- Help -----------------------------------------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------

# Display help information
# This target prints out a detailed list of all available Makefile commands for ease of use.
# It's a helpful reference for developers using the Makefile.
.PHONY: help
help:
@echo ""
Expand All @@ -153,6 +104,7 @@ help:
@echo " prepare .................. prepare repository."
@echo ""
@echo " Go Commands:"
@echo " go-mod-clean ............. Clean Go module cache."
@echo " go-mod-tidy .............. Tidy Go modules."
@echo " go-mod-update ............ Update Go modules."
@echo " go-fmt ................... Format Go code."
Expand All @@ -165,5 +117,7 @@ help:
@echo " docker-build ............. Build Docker image."
@echo ""
@echo " Help Commands:"
@echo " help ..................... Display this help information"
@echo ""
@echo " help ..................... Display this help information."
@echo ""

.DEFAULT_GOAL = help
Loading

0 comments on commit b1c1472

Please sign in to comment.