diff --git a/.gitignore b/.gitignore index 5b90e79..a02c7d1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +coverage.html # Dependency directories (remove the comment below to include it) # vendor/ @@ -25,3 +26,5 @@ go.work.sum # env file .env +# Dist +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..cf07385 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,140 @@ +version: 2 + +gitea_urls: + api: https://git.nakama.town/api/v1 + download: https://git.nakama.town + +before: + hooks: + - go mod tidy + +git: + ignore_tags: + - "{{ if not .IsNightly }}*-rc*{{ end }}" + +builds: + - binary: smtp2shoutrrr + main: ./cmd/smtp2shoutrrr + env: + - CGO_ENABLED=0 + - GIN_MODE=release + tags: + - netgo + - osusergo + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm + - arm64 + goarm: + - "7" + ignore: + - goos: darwin + goarch: arm + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + +archives: + - id: smtp2shoutrrr + name_template: >- + {{ .ProjectName }}_ + {{- if eq .Os "darwin" }}Darwin{{- else if eq .Os "linux" }}Linux{{- else if eq .Os "windows" }}Windows{{- else }}{{ .Os }}{{ end }}_ + {{- if eq .Arch "amd64" }}x86_64{{- else if eq .Arch "arm64" }}aarch64{{- else }}{{ .Arch }}{{ end }}_{{ .Version }} + format_overrides: + - goos: windows + format: zip + +dockers: +- image_templates: + - &amd64_image "git.nakama.town/fmartingr/smtp2shoutrrr:{{ .Version }}-amd64" + use: buildx + dockerfile: &dockerfile Containerfile + goos: linux + goarch: amd64 + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" +- image_templates: + - &arm64_image "git.nakama.town/fmartingr/smtp2shoutrrr:{{ .Version }}-arm64" + use: buildx + dockerfile: *dockerfile + goos: linux + goarch: arm64 + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" +# - image_templates: +# - &armv7_image "git.nakama.town/fmartingr/smtp2shoutrrr:{{ .Version }}-armv7" +# use: buildx +# dockerfile: *dockerfile +# goos: linux +# goarch: arm +# goarm: "7" +# build_flag_templates: +# - "--pull" +# - "--platform=linux/arm/v7" + +docker_manifests: + - name_template: "git.nakama.town/fmartingr/smtp2shoutrrr:{{ .Version }}" + image_templates: + - *amd64_image + - *arm64_image + # - *armv7_image + # - name_template: "git.nakama.town/fmartingr/smtp2shoutrrr:latest" + # image_templates: + # - *amd64_image + # - *arm64_image + # - *armv7_image + +upx: + - enabled: true + ids: + - smtp2shoutrrr + goos: [linux, darwin] + goarch: [amd64, arm, arm64] + goarm: ["7"] + +checksum: + name_template: 'checksums.txt' + +snapshot: + version_template: "{{ incpatch .Version }}-next" + +changelog: + sort: asc + groups: + - title: Features + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: "Fixes" + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: "Performance" + regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$' + order: 2 + - title: API + regexp: '^.*?api(\([[:word:]]+\))??!?:.+$' + order: 3 + - title: Documentation + regexp: '^.*?docs(\([[:word:]]+\))??!?:.+$' + order: 4 + - title: "Tests" + regexp: '^.*?test(\([[:word:]]+\))??!?:.+$' + order: 5 + - title: CI and Delivery + regexp: '^.*?ci(\([[:word:]]+\))??!?:.+$' + order: 6 + - title: Others + order: 999 + filters: + exclude: + - "^deps:" + - "^chore\\(deps\\):" + +release: + prerelease: auto diff --git a/.woodpecker/release.yml b/.woodpecker/release.yml new file mode 100644 index 0000000..83e4ec8 --- /dev/null +++ b/.woodpecker/release.yml @@ -0,0 +1,15 @@ +when: + - event: tag + branch: main + +steps: + - name: Release + image: goreleaser/goreleaser:latest + environment: + GITEA_TOKEN: + from_secret: GITEA_TOKEN + DOCKER_HOST: unix:///var/run/docker.sock + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + commands: + - goreleaser release --clean diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..ca8a292 --- /dev/null +++ b/Containerfile @@ -0,0 +1,25 @@ +# Build stage +ARG ALPINE_VERSION=3.18 + +FROM docker.io/library/alpine:${ALPINE_VERSION} AS builder +ARG TARGETARCH +ARG TARGETOS +ARG TARGETVARIANT +ARG BIN_NAME +COPY /smtp2shoutrrr /usr/bin/smtp2shoutrrr +RUN apk add --no-cache ca-certificates tzdata && \ + chmod +x /usr/bin/${BIN_NAME} + +# Server image +FROM scratch +ARG BIN_NAME +ARG SOURCE_URL +ARG MAINTAINER + +ENV PORT=8080 + +COPY --from=builder /usr/bin/smtp2shoutrrr /usr/bin/smtp2shoutrrr +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +ENTRYPOINT ["/usr/bin/smtp2shoutrrr"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8daaabb --- /dev/null +++ b/Makefile @@ -0,0 +1,92 @@ +PROJECT_NAME := smtp2shoutrrr + +SOURCE_FILES ?=./... + +TEST_OPTIONS ?= -v -failfast -race -bench=. -benchtime=100000x -cover -coverprofile=coverage.out +TEST_TIMEOUT ?=1m + +CLEAN_OPTIONS ?=-modcache -testcache + +CGO_ENABLED := 0 + +BUILDS_PATH := ./dist +FROM_MAKEFILE := y + +CONTAINER_RUNTIME := podman +CONTAINERFILE_NAME := Containerfile +CONTAINER_ALPINE_VERSION := 3.20 +CONTAINER_SOURCE_URL := "https://git.nakama.town/fmartingr/${PROJECT_NAME}" +CONTAINER_MAINTAINER := "Felipe Martin " +CONTAINER_BIN_NAME := ${PROJECT_NAME} + +BUILDX_PLATFORMS := linux/amd64,linux/arm64,linux/arm/v7 + +export PROJECT_NAME +export FROM_MAKEFILE + +export CGO_ENABLED + +export SOURCE_FILES +export TEST_OPTIONS +export TEST_TIMEOUT +export BUILDS_PATH + +export CONTAINER_RUNTIME +export CONTAINERFILE_NAME +export CONTAINER_ALPINE_VERSION +export CONTAINER_SOURCE_URL +export CONTAINER_MAINTAINER +export CONTAINER_BIN_NAME + +export BUILDX_PLATFORMS + +.PHONY: all +all: help + +# this is godly +# https://news.ycombinator.com/item?id=11939200 +.PHONY: help +help: ### this screen. Keep it first target to be default +ifeq ($(UNAME), Linux) + @grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \ + awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' +else + @# this is not tested, but prepared in advance for you, Mac drivers + @awk -F ':.*###' '$$0 ~ FS {printf "%15s%s\n", $$1 ":", $$2}' \ + $(MAKEFILE_LIST) | grep -v '@awk' | sort +endif + +.PHONY: clean +clean: ### clean test cache, build files + $(info: Make: Clean) + @rm -rf ${BUILDS_PATH} + @go clean ${CLEAN_OPTIONS} + @-docker buildx rm ${PROJECT_NAME}_builder + +.PHONY: build +build: clean ### builds the project for the setup os/arch combinations + $(info: Make: Build) + @goreleaser --clean --snapshot + +.PHONY: quick-run +quick-run: ### Executes the project using golang + CGO_ENABLED=${CGO_ENABLED} go run ./cmd/${PROJECT_NAME}/*.go + +.PHONY: run +run: ### Executes the project build locally + @make build + ${BUILDS_PATH}/${PROJECT_NAME} + +.PHONY: format +format: ### Executes the formatting pipeline on the project + $(info: Make: Format) + @bash scripts/format.sh + +.PHONY: lint +lint: ### Check the project for errors + $(info: Make: Lint) + @bash scripts/lint.sh + +.PHONY: test +test: ### Runs the test suite + @bash scripts/test.sh diff --git a/main.go b/cmd/smtp2shoutrrr/main.go similarity index 100% rename from main.go rename to cmd/smtp2shoutrrr/main.go