Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Makefile text eol=lf
23 changes: 23 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
changelog:
exclude:
labels:
- chore
categories:
- title: 💥 Breaking Changes
labels:
- 💥 breaking-change
- title: ✨ Exciting New Features
labels:
- ✨ enhancement
- title: 🐞 Bug Fixes
labels:
- 🐞 bug
- title: 🛠️ Dependencies
labels:
- 🛠️ dependencies
- title: 📖 Documentation
labels:
- 📖 docs
- title: Other Changes
labels:
- "*"
98 changes: 98 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI

env:
# renovate: github=golangci/golangci-lint
GO_LINT_CI_VERSION: v1.60.3

on:
workflow_dispatch:
pull_request:
push:
tags:
- 'v*'
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
name: Build & Test
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0

- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'

- run: go mod tidy -diff
- run: go build
- run: go test ./... -timeout 20s -race -covermode=atomic -coverprofile=coverage.out -coverpkg=./...
- run: go test ./... -timeout 20s -bench . -benchmem -count 3

- uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: go build (with goreleaser)
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6
with:
version: '~> v2'
args: release --snapshot
env:
GITHUB_TOKEN: ""

- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: dists
path: dist/
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'

- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: ${{ env.GO_LINT_CI_VERSION }}

publish:
name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs:
- build
- lint
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'

- uses: sigstore/cosign-installer@v3.5.0

- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6
with:
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
22 changes: 22 additions & 0 deletions .github/workflows/speeling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Spell checking

# Trigger on pull requests, and pushes to master branch.
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: codespell-project/actions-codespell@406322ec52dd7b488e48c1c4b82e2a8b3a1bf630
with:
check_filenames: true
# When using this Action in other repos, the --skip option below can be removed
skip: ./.git,./CODE_OF_CONDUCT.md,go.mod,go.sum,go.work,go.work.sum,./internal/ui/assets/i18n
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ go.work.sum

# env file
.env

local/
63 changes: 63 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
linters:
enable-all: true
disable:
- depguard
- exhaustruct
- gomnd
- funlen
- execinquery
- mnd
- exportloopref
- err113
- tparallel
- paralleltest

issues:
exclude-rules:
- path: _test\.go
linters:
- lll
- gocognit
- cyclop
- wrapcheck
- maintidx
- dogsled
- contextcheck
- dupword
- dupl
- funlen
- gocyclo

linters-settings:
sloglint:
no-mixed-args: true
kv-only: false
attr-only: true
no-global: "all"
context: "scope"
static-msg: false
no-raw-keys: false
key-naming-case: snake
forbidden-keys:
- time
- level
- msg
- source
args-on-sep-lines: true
varnamelen:
ignore-names:
- tt
- tc
ignore-decls:
- i int
- a ...any
- err error
- ok bool
- id string
- w http.ResponseWriter
- rt http.RoundTripper
- r *http.Request
- l net.Listener
- t reflect.Type
lll:
line-length: 160
66 changes: 66 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: 2

builds:
- binary: __REPO__
goos:
- linux
goarch:
- amd64
- arm64
mod_timestamp: '{{ .CommitTimestamp }}'
env:
- CGO_ENABLED=0
flags:
- -trimpath
tags:
- netgo
- static_build
ldflags:
- >-
-s -w

kos:
- repository: ghcr.io/cloudeteer/azure-communication-gateway-smtp-bridge
tags:
- "{{.Version}}"
- latest
bare: true
base_image: gcr.io/distroless/static-debian12:nonroot # scratch is not supported, see https://github.com/ko-build/ko/pull/1350
preserve_import_paths: false
creation_time: "{{.CommitTimestamp}}"
ko_data_creation_time: "{{.CommitTimestamp}}"
platforms:
- linux/amd64
- linux/arm64
labels:
org.opencontainers.image.created: "{{.Date}}"
org.opencontainers.image.title: "{{.ProjectName}}"
org.opencontainers.image.revision: "{{.FullCommit}}"
org.opencontainers.image.version: "{{.Version}}"
org.opencontainers.image.source: "https://github.com/cloudeteer/azure-communication-gateway-smtp-bridge"
org.opencontainers.image.description: ""
docker_signs:
- artifacts: manifests
output: true
cmd: cosign
env:
- COSIGN_EXPERIMENTAL=1
args:
- sign
- '--oidc-issuer={{if index .Env "CI"}}https://token.actions.githubusercontent.com{{else}}https://oauth2.sigstore.dev/auth{{end}}'
- '--yes'
- '${artifact}'

report_sizes: true

metadata:
mod_timestamp: "{{ .CommitTimestamp }}"

gomod:
proxy: true

release:
prerelease: auto

changelog:
use: github-native
105 changes: 105 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
##
# Console Colors
##
GREEN := \033[0;32m
YELLOW := \033[0;33m
WHITE := \033[0;37m
CYAN := \033[0;36m
RESET := \033[0m

# Get the current working directory
CURRENT_DIR := $(CURDIR)

# Get the directory name of the current working directory
PROJECT_NAME := $(notdir $(CURRENT_DIR))

# Get the GOOS value
GOOS := $(shell go env GOOS)

# Determine the output file extension based on the GOOS value
ifeq ($(GOOS),windows)
EXT := .exe
else
EXT :=
endif

##
# Targets
##
.PHONY: help
help: ## show this help.
@echo "Project: $(PROJECT_NAME)"
@echo 'Usage:'
@echo " ${GREEN}make${RESET} ${YELLOW}<target>${RESET}"
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${GREEN}%-21s${YELLOW}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST) | sort

.PHONY: clean
clean: ## clean builds dir
@rm -rf "$(PROJECT_NAME)" "$(PROJECT_NAME).exe" dist/

.PHONY: check
check: test lint golangci ## Run all checks locally

.PHONY: update
update: ## Run dependency updates
@go get -u ./...
@go mod tidy
@go -C tools get -u
@go -C tools mod tidy

.PHONY: build ## Build the project
build: clean $(PROJECT_NAME)

$(PROJECT_NAME):
@go build -o $(PROJECT_NAME)$(EXT) .

.PHONY: test
test: ## Test the project
@go test -race ./...

.PHONY: lint
lint: golangci ## Run linter

.PHONY: fmt ## Format code
fmt: install-tools
@-go fmt ./...
@-tools/bin/gci write .
@-tools/bin/gofumpt -l -w .
@-tools/bin/goimports -l -w .
@-tools/bin/wsl -strict-append -test=true -fix ./...
@-tools/bin/perfsprint -fix ./...
@-tools/bin/godot -w .
@tools/bin/golangci-lint run ./... --fix

.PHONY: golangci
golangci:
@go run github.com/golangci/golangci-lint/cmd/golangci-lint@${GO_LINT_CI_VERSION} run ./...

.PHONY: 3rdpartylicenses
3rdpartylicenses:
@go run github.com/google/go-licenses@latest save . --save_path=3rdpartylicenses

# In order to help reduce toil related to managing tooling for the open telemetry collector
# this section of the makefile looks at only requiring command definitions to be defined
# as part of $(TOOLS_MOD_DIR)/tools.go, following the existing practice.
# Modifying the tools' `go.mod` file will trigger a rebuild of the tools to help
# ensure that all contributors are using the most recent version to make builds repeatable everywhere.
TOOLS_MOD_DIR := tools
TOOLS_MOD_REGEX := "\s+_\s+\".*\""
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"")
TOOLS_BIN_DIR := bin
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(TOOLS_PKG_NAMES)))

.PHONY: install-tools
install-tools: $(TOOLS_BIN_NAMES)

$(TOOLS_BIN_DIR):
@mkdir -p $@

$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
go build -C $(TOOLS_MOD_DIR) -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))
Loading
Loading