Skip to content

Commit

Permalink
Merge pull request #7 from ryarnyah/feat/some-cleaning-2021
Browse files Browse the repository at this point in the history
Doing some updates for 2021
  • Loading branch information
ryarnyah committed Oct 12, 2021
2 parents 4550957 + 072cc5c commit c4aa3e4
Show file tree
Hide file tree
Showing 530 changed files with 371 additions and 200,573 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Go build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Build
run: |
make dev-dependencies
make
make cover
make release
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '35 19 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
26 changes: 26 additions & 0 deletions .github/workflows/go-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Go release

on:
push:
tags:
- '*.*.*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Build
run: |
make dev-dependencies
make release
- uses: softprops/action-gh-release@v1
with:
files: "build/local-dns-proxy-*"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
local-dns-proxy
.vscode
167 changes: 144 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,151 @@
BUILD_IMAGE := ryarnyah/docker-golang-builder:latest
RELEASE_IMAGE := ryarnyah/docker-github-release:latest
GITHUB_USER := ryarnyah
GITHUB_REPO := local-dns-proxy
GIT_TAG := v1.0.0
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)

PLATFORMS := linux/arm linux/amd64 windows/amd64 windows/386
# Setup name variables for the package/tool
BASE_REPOSITORY := ryarnyah
BINARIES := local-dns-proxy
BASE_PKG := github.com/$(BASE_REPOSITORY)
BASE_BINARIES := .

all: $(PLATFORMS)
# Set any default go build tags
BUILDTAGS :=

temp = $(subst /, ,$@)
os = $(word 1, $(temp))
arch = $(word 2, $(temp))
# Set the build dir, where built cross-compiled binaries will be output
BASE_BUILD_DIR := build
BUILDDIR := ${PREFIX}/${BASE_BUILD_DIR}

$(PLATFORMS):
docker run --rm -e GOOS=${os} -e GOARCH=${arch} -v ${PWD}:/go/src/github.com/$(GITHUB_USER)/${GITHUB_REPO} -w /go/src/github.com/${GITHUB_USER}/${GITHUB_REPO} ${BUILD_IMAGE}
# Populate version variables
# Add to compile time flags
VERSION := $(shell cat VERSION.txt)
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
CTIMEVAR=-X $(BASE_PKG)/$(1)/version.GITCOMMIT=$(GITCOMMIT) -X $(BASE_PKG)/$(1)/version.VERSION=$(VERSION)
GO_LDFLAGS=-ldflags "-w $(call CTIMEVAR,$(1))"
GO_LDFLAGS_STATIC=-ldflags "-w $(call CTIMEVAR,$(1)) -extldflags -static"

release: $(PLATFORMS)
@- $(foreach XYZ,$^, \
$(eval temp = $(subst /, ,${XYZ})) \
$(eval os = $(word 1, $(temp))) \
$(eval arch = $(word 2, $(temp))) \
\
$(shell docker run --rm -e GITHUB_USER=${GITHUB_USER} -e GITHUB_REPO=${GITHUB_REPO} -e GIT_TAG=${GIT_TAG} -e BINARY_NAME=${GITHUB_REPO}-${os}-${arch} -e GITHUB_TOKEN=${GITHUB_TOKEN} -v ${PWD}:/go/src/github.com/${GITHUB_USER}/${GITHUB_REPO} -w /go/src/github.com/${GITHUB_USER}/${GITHUB_REPO} ${RELEASE_IMAGE}) \
)
# List the GOOS and GOARCH to build
GOOSARCHES = linux/arm linux/amd64 linux/arm64 windows/amd64 windows/386

clean:
rm -f ${GITHUB_REPO}-*
all: clean build fmt lint test staticcheck vet ## Runs a clean, build, fmt, lint, test, staticcheck, vet

.PHONY: all $(PLATFORMS) release
.PHONY: build
build: $(BINARIES) ## Builds a dynamic executable or package

$(BINARIES): VERSION.txt
@echo "+ $@"
GO111MODULE=on CGO_ENABLED=0 go build -tags "$(BUILDTAGS)" $(call GO_LDFLAGS,$@) -o $@ $(BASE_BINARIES)

.PHONY: static
static: ## Builds a static executable
@echo "+ $@"
$(foreach BINARY,$(BINARIES),GO111MODULE=on CGO_ENABLED=0 go build -tags "$(BUILDTAGS) static_build" $(call GO_LDFLAGS_STATIC $(BINARY)) -o $(BINARY) $(BASE_BINARIES)/$(BINARY))

.PHONY: fmt
fmt: ## Verifies all files have men `gofmt`ed
@echo "+ $@"
@gofmt -s -l . | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr

.PHONY: lint
lint: ## Verifies `golint` passes
@echo "+ $@"
@golint ./... | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr

.PHONY: test
test: ## Runs the go tests
@echo "+ $@"
@go test -v -tags "$(BUILDTAGS) cgo" $(shell go list ./... | grep -v vendor)

.PHONY: vet
vet: ## Verifies `go vet` passes
@echo "+ $@"
@go vet $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr

.PHONY: staticcheck
staticcheck: ## Verifies `staticcheck` passes
@echo "+ $@"
@staticcheck $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr

.PHONY: cover
cover: ## Runs go test with coverage
@echo "" > coverage.txt
@for d in $(shell go list ./... | grep -v vendor); do \
go test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
if [ -f profile.out ]; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi; \
done;

define buildpretty
mkdir -p $(BUILDDIR)/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) GO111MODULE=on CGO_ENABLED=0 go build \
-o $(BUILDDIR)/$(1)/$(2)/$(3) \
-a -tags "$(BUILDTAGS) static_build netgo" \
-installsuffix netgo $(call GO_LDFLAGS_STATIC,$3) $(BASE_BINARIES)/$(3);
md5sum $(BUILDDIR)/$(1)/$(2)/$(3) > $(BUILDDIR)/$(1)/$(2)/$(3).md5;
sha256sum $(BUILDDIR)/$(1)/$(2)/$(3) > $(BUILDDIR)/$(1)/$(2)/$(3).sha256;
endef

.PHONY: cross
cross: VERSION.txt ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary)
@echo "+ $@"
$(foreach BINARY,$(BINARIES), $(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)),$(BINARY))))

define buildrelease
GOOS=$(1) GOARCH=$(2) GO111MODULE=on CGO_ENABLED=0 go build \
-o $(BUILDDIR)/$(3)-$(1)-$(2) \
-a -tags "$(BUILDTAGS) static_build netgo" \
-installsuffix netgo $(call GO_LDFLAGS_STATIC,$3) $(BASE_BINARIES);
md5sum $(BUILDDIR)/$(3)-$(1)-$(2) > $(BUILDDIR)/$(3)-$(1)-$(2).md5;
sha256sum $(BUILDDIR)/$(3)-$(1)-$(2) > $(BUILDDIR)/$(3)-$(1)-$(2).sha256;
endef

.PHONY: release
release: VERSION.txt ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH)
@echo "+ $@"
$(foreach BINARY,$(BINARIES), $(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH)),$(BINARY))))

.PHONY: bump-version
BUMP := patch
bump-version: ## Bump the version in the version file. Set BUMP to [ patch | major | minor ]
$(eval NEW_VERSION = $(shell sembump --kind $(BUMP) $(VERSION)))
@echo "Bumping VERSION.txt from $(VERSION) to $(NEW_VERSION)"
echo $(NEW_VERSION) > VERSION.txt
@echo "Updating links to download binaries in README.md"
sed -e s/$(VERSION)/$(NEW_VERSION)/g README.md > README.md.tmp
mv README.md.tmp README.md
git add VERSION.txt README.md
git commit -vsm "Bump version to $(NEW_VERSION)"
@echo "Run make tag to create and push the tag for new version $(NEW_VERSION)"

.PHONY: tag
tag: ## Create a new git tag to prepare to build a release
git tag -sa $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build."

.PHONY: AUTHORS
AUTHORS:
@$(file >$@,# This file lists all individuals having contributed content to the repository.)
@$(file >>$@,# For how it is generated, see `make AUTHORS`.)
@echo "$(shell git log --format='\n%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf)" > $@
git add AUTHORS
git commit -vsm "Updated AUTHORS"

.PHONY: clean
clean: ## Cleanup any build binaries or packages
@echo "+ $@"
$(foreach BINARY,$(BINARIES), $(RM) $(BINARY))
$(RM) -r $(BUILDDIR)

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: dev-dependencies
dev-dependencies: ## Install all dev dependencies
@GO111MODULE=off go get -u github.com/jessfraz/junk/sembump
@GO111MODULE=off go get -u honnef.co/go/tools/cmd/staticcheck
@GO111MODULE=off go get -u golang.org/x/lint/golint
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Local DNS Proxy
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fryarnyah%2Flocal-dns-proxy.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fryarnyah%2Flocal-dns-proxy?ref=badge_shield)
# Local DNS Proxy [![Build Status](https://github.com/ryarnyah/local-dns-proxy/actions/workflows/build.yml/badge.svg)](https://github.com/ryarnyah/local-dns-proxy/) #


## Build
$ go build



## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fryarnyah%2Flocal-dns-proxy.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fryarnyah%2Flocal-dns-proxy?ref=badge_large)
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.0
24 changes: 0 additions & 24 deletions glide.lock

This file was deleted.

8 changes: 0 additions & 8 deletions glide.yaml

This file was deleted.

26 changes: 26 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/ryarnyah/local-dns-proxy

go 1.17

require (
github.com/Sirupsen/logrus v1.0.6
github.com/karlseguin/ccache v2.0.3+incompatible
github.com/miekg/dns v1.1.43
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a // indirect
github.com/karlseguin/expect v1.0.8 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
)
Loading

0 comments on commit c4aa3e4

Please sign in to comment.