Skip to content

Commit

Permalink
Add travis config
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Jun 11, 2019
1 parent b9080d9 commit cbc3c5d
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
dnslookup
build
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/hex"
"fmt"
"log"
"os"
"strings"
Expand All @@ -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()
Expand Down Expand Up @@ -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 <domain> <server> [<providerName> <serverPk>]")
log.Print("<domain>: mandatory, domain name to lookup")
log.Print("<server>: mandatory, server address. Supported: plain, tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt)")
log.Print("<providerName>: optional, DNSCrypt provider name")
log.Print("<serverPk>: optional, DNSCrypt server public key")
os.Stdout.WriteString("Usage: dnslookup <domain> <server> [<providerName> <serverPk>]")
os.Stdout.WriteString("<domain>: mandatory, domain name to lookup")
os.Stdout.WriteString("<server>: mandatory, server address. Supported: plain, tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt)")
os.Stdout.WriteString("<providerName>: optional, DNSCrypt provider name")
os.Stdout.WriteString("<serverPk>: optional, DNSCrypt server public key")
}

0 comments on commit cbc3c5d

Please sign in to comment.