From cbc3c5dd0559ff5a186f02e687afc8d81dff38bc Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Tue, 11 Jun 2019 14:59:00 +0300 Subject: [PATCH] Add travis config --- .gitignore | 1 + .travis.yml | 39 +++++++++++++++++++++++++++++++++++++++ Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++++ main.go | 20 +++++++++++++------- 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 .travis.yml create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 833bce3..f664340 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea dnslookup +build diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..df320e2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,39 @@ +language: go +sudo: false + +os: + - linux + +env: + - GO111MODULE=on + - GIMME_GO_VERSION=1.x + +go: + - 1.x + - 1.11 + +script: + # Windows-386 build + - GOOS=windows GOARCH=386 VERSION=${TRAVIS_TAG:-dev} make release + # Windows-amd64 build + - GOOS=windows GOARCH=amd64 VERSION=${TRAVIS_TAG:-dev} make release + # Linux-386 build + - GOOS=linux GOARCH=386 VERSION=${TRAVIS_TAG:-dev} make release + # Linux-amd64 build + - GOOS=linux GOARCH=amd64 VERSION=${TRAVIS_TAG:-dev} make release + # Darwin-amd64 build + - GOOS=darwin GOARCH=amd64 VERSION=${TRAVIS_TAG:-dev} make release + # List build output + - ls -l build/dnslookup-* + +deploy: + provider: releases + api_key: $GITHUB_TOKEN + file: + - build/dnslookup-*.zip + - build/dnslookup-*.tar.gz + on: + repo: ameshkov/dnslookup + tags: true + file_glob: true + skip_cleanup: true \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c064938 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +NAME=dnslookup +BASE_BUILDDIR=build +BUILDNAME=$(GOOS)-$(GOARCH) +BUILDDIR=$(BASE_BUILDDIR)/$(BUILDNAME) +VERSION?=dev + +ifeq ($(GOOS),windows) + ext=.exe + archiveCmd=zip -9 -r $(NAME)-$(BUILDNAME)-$(VERSION).zip $(BUILDNAME) +else + ext= + archiveCmd=tar czpvf $(NAME)-$(BUILDNAME)-$(VERSION).tar.gz $(BUILDNAME) +endif + +.PHONY: default +default: build + +build: clean test + go build + +release: check-env-release + mkdir -p $(BUILDDIR) + cp LICENSE $(BUILDDIR)/ + cp README.md $(BUILDDIR)/ + GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "-X main.VersionString=$(VERSION)" -o $(BUILDDIR)/$(NAME)$(ext) + cd $(BASE_BUILDDIR) ; $(archiveCmd) + +test: + go test -race -v -bench=. ./... + +clean: + go clean + rm -rf $(BASE_BUILDDIR) + +check-env-release: + @ if [ "$(GOOS)" = "" ]; then \ + echo "Environment variable GOOS not set"; \ + exit 1; \ + fi + @ if [ "$(GOARCH)" = "" ]; then \ + echo "Environment variable GOOS not set"; \ + exit 1; \ + fi \ No newline at end of file diff --git a/README.md b/README.md index 524f785..7ab4c41 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![Build Status](https://travis-ci.org/ameshkov/dnslookup.svg?branch=master)](https://travis-ci.org/ameshkov/dnslookup) +[![Go Report Card](https://goreportcard.com/badge/github.com/ameshkov/dnslookup)](https://goreportcard.com/report/ameshkov/dnslookup) +[![GolangCI](https://golangci.com/badges/github.com/ameshkov/dnslookup.svg)](https://golangci.com/r/github.com/ameshkov/dnslookup) + # dnslookup Simple command line utility to make DNS lookups to the specified server. diff --git a/main.go b/main.go index 70b8c54..f69e19a 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/hex" + "fmt" "log" "os" "strings" @@ -13,7 +14,12 @@ import ( "github.com/miekg/dns" ) +// See the makefile +var VersionString = "undefined" + func main() { + os.Stdout.WriteString(fmt.Sprintf("dnslookup %s", VersionString)) + if len(os.Args) != 3 && len(os.Args) != 5 { log.Printf("Wrong number of arguments") usage() @@ -60,14 +66,14 @@ func main() { log.Fatalf("Cannot make the DNS request: %s", err) } - _,_ = os.Stdout.WriteString("dnslookup result:") - _,_ = os.Stdout.WriteString(reply.String()) + os.Stdout.WriteString("dnslookup result:") + os.Stdout.WriteString(reply.String()) } func usage() { - log.Print("Usage: dnslookup [ ]") - log.Print(": mandatory, domain name to lookup") - log.Print(": mandatory, server address. Supported: plain, tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt)") - log.Print(": optional, DNSCrypt provider name") - log.Print(": optional, DNSCrypt server public key") + os.Stdout.WriteString("Usage: dnslookup [ ]") + os.Stdout.WriteString(": mandatory, domain name to lookup") + os.Stdout.WriteString(": mandatory, server address. Supported: plain, tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt)") + os.Stdout.WriteString(": optional, DNSCrypt provider name") + os.Stdout.WriteString(": optional, DNSCrypt server public key") }