Added .drone.yml for releasing and fixes in Makefile + linter changes
continuous-integration/drone/push Build was killed Details

pull/2/head
Darshil Chanpura 2021-09-18 11:41:38 +05:30
parent c99c96a587
commit 451a1d1f7e
3 changed files with 104 additions and 3 deletions

95
.drone.yml Normal file
View File

@ -0,0 +1,95 @@
---
kind: pipeline
type: docker
name: default
platform:
os: linux
arch: amd64
workspace:
path: /drone/src
steps:
- name: prerequisites
image: golang
commands:
- mkdir -p release
- go install honnef.co/go/tools/cmd/staticcheck@latest
- go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
volumes:
- name: cache
path: /go
- name: test
image: golang
commands:
- go test -v -race ./...
- go vet ./...
- staticcheck ./...
- gocyclo -over 19 $(find . -iname '*.go' -type f | grep -v /vendor/)
- golint -set_exit_status ./...
volumes:
- name: cache
path: /go
- name: build-darwin
image: golang
commands:
- mkdir -p release/darwin
- GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/darwin/dumb-http cmd/dumb-http/main.go
- tar -czf release/dumb-http-${DRONE_TAG:-latest}-darwin-amd64.tar.gz README.md -C release/darwin/ dumb-http
- GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/darwin/dumb-http cmd/dumb-http/main.go
- tar -czf release/dumb-http-${DRONE_TAG:-latest}-darwin-arm64.tar.gz README.md -C release/darwin/ dumb-http
- name: build-windows
image: golang
commands:
- mkdir -p release/windows
- GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/windows/dumb-http cmd/dumb-http/main.go
- tar -czf release/dumb-http-${DRONE_TAG:-latest}-windows-amd64.tar.gz README.md -C release/windows/ dumb-http
- name: build-linux
image: golang
commands:
- mkdir -p release/linux
- GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/linux/dumb-http cmd/dumb-http/main.go
- tar -czf release/dumb-http-${DRONE_TAG:-latest}-linux-amd64.tar.gz README.md -C release/linux/ dumb-http
- GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${DRONE_TAG:-latest}" -o release/linux/dumb-http cmd/dumb-http/main.go
- tar -czf release/dumb-http-${DRONE_TAG:-latest}-linux-arm64.tar.gz README.md -C release/linux/ dumb-http
- name: dummy-check
image: golang
commands:
- ls -lah release/
- ls -lah release/*
depends_on:
- build-linux
- build-darwin
- build-windows
- name: gitea-release
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://git.dcpri.me
checksum:
- sha256
files:
- release/*.tar.gz
- release/debs/*.deb
title: Version ${DRONE_TAG/v/}
when:
event:
- tag
depends_on:
- build-linux
- build-darwin
- build-windows
---
kind: signature
hmac: 679972f18fba9f3c277e6642a0456d9b94a59dbd0f5ae1755325ab093045c713
...

View File

@ -8,9 +8,8 @@ os = $(word 1, $@)
bootstrap:
@mkdir -p release
go get golang.org/x/lint # Linter
go get honnef.co/go/tools/cmd/staticcheck # Badass static analyzer/linter
go get github.com/fzipp/gocyclo # Cyclomatic complexity check
go install honnef.co/go/tools/cmd/staticcheck@latest # Badass static analyzer/linter
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest # Cyclomatic complexity check
test:
go test -v -race $(PKGS) # Normal Test

View File

@ -6,6 +6,9 @@ import (
"net/url"
)
// Proxy struct contains the mux for handling paths, rp for conditionally
// doing a reverse proxy to upstream and root as root directory for serving
// static content.
type Proxy struct {
mux *http.ServeMux
@ -13,6 +16,8 @@ type Proxy struct {
root string
}
// New will return a Proxy struct with a new server mux and
// set reverse proxy Proxy.rp in case if the upstream is not empty.
func New(upstream, root string) (*Proxy, error) {
if upstream == "" {
return &Proxy{
@ -32,6 +37,8 @@ func New(upstream, root string) (*Proxy, error) {
}, nil
}
// Routes will set routes based on the values of Proxy.rp and
// by default set / to file server.
func (p *Proxy) Routes(proxyPath string, stripPrefix bool) {
if p.rp == nil {
p.mux.Handle("/", http.FileServer(http.Dir(p.root)))