2021-06-22 10:34:35 +00:00
|
|
|
DOCKER_RUN_GO_VERSION=1.16
|
2019-09-14 12:11:40 +00:00
|
|
|
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
|
2021-06-22 10:34:35 +00:00
|
|
|
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
2019-09-14 12:11:40 +00:00
|
|
|
|
2021-06-22 11:12:26 +00:00
|
|
|
VERSION ?= ${DRONE_TAG}
|
|
|
|
ifeq ($(VERSION),)
|
|
|
|
VERSION := $(shell echo ${DRONE_COMMIT_SHA} | head -c 8)
|
|
|
|
endif
|
|
|
|
|
|
|
|
LDFLAGS ?= -extldflags "-static"
|
|
|
|
ifneq ($(VERSION),)
|
|
|
|
LDFLAGS := ${LDFLAGS} -X github.com/woodpecker-ci/woodpecker/version.Version=${VERSION}
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2019-10-06 20:07:31 +00:00
|
|
|
DOCKER_RUN?=
|
|
|
|
_with-docker:
|
2021-06-22 10:34:35 +00:00
|
|
|
$(eval DOCKER_RUN=docker run --rm -v $(shell pwd):/go/src/ -v $(shell pwd)/build:/build -w /go/src golang:$(DOCKER_RUN_GO_VERSION))
|
2019-10-06 20:07:31 +00:00
|
|
|
|
2021-09-09 17:39:59 +00:00
|
|
|
all: build
|
2019-09-14 12:11:40 +00:00
|
|
|
|
2021-08-30 17:14:04 +00:00
|
|
|
vendor:
|
|
|
|
go mod tidy
|
|
|
|
go mod vendor
|
2019-09-14 12:11:40 +00:00
|
|
|
|
|
|
|
formatcheck:
|
2021-06-22 10:34:35 +00:00
|
|
|
@([ -z "$(shell gofmt -d $(GOFILES_NOVENDOR) | head)" ]) || (echo "Source is unformatted"; exit 1)
|
2019-09-14 12:11:40 +00:00
|
|
|
|
|
|
|
format:
|
|
|
|
@gofmt -w ${GOFILES_NOVENDOR}
|
|
|
|
|
2021-06-22 10:34:35 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
go clean -i ./...
|
|
|
|
rm -rf build
|
|
|
|
|
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
|
|
|
@echo "Running go vet..."
|
|
|
|
@go vet $(GO_PACKAGES)
|
|
|
|
|
2019-09-14 12:11:40 +00:00
|
|
|
test-agent:
|
2021-09-21 15:06:13 +00:00
|
|
|
$(DOCKER_RUN) go test -race -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/agent $(GO_PACKAGES)
|
2019-09-14 12:11:40 +00:00
|
|
|
|
|
|
|
test-server:
|
2021-09-21 15:06:13 +00:00
|
|
|
$(DOCKER_RUN) go test -race -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/server
|
2019-09-14 12:11:40 +00:00
|
|
|
|
2019-11-12 13:27:39 +00:00
|
|
|
test-frontend:
|
2021-08-30 17:14:04 +00:00
|
|
|
(cd web/; yarn run test)
|
2019-11-12 13:27:39 +00:00
|
|
|
|
2019-09-14 12:11:40 +00:00
|
|
|
test-lib:
|
2019-10-08 10:09:31 +00:00
|
|
|
$(DOCKER_RUN) go test -race -timeout 30s $(shell go list ./... | grep -v '/cmd/')
|
2019-09-14 12:11:40 +00:00
|
|
|
|
|
|
|
test: test-lib test-agent test-server
|
|
|
|
|
|
|
|
build-agent:
|
2021-09-21 15:06:13 +00:00
|
|
|
$(DOCKER_RUN) go build -o build/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
|
2019-09-14 12:11:40 +00:00
|
|
|
|
|
|
|
build-server:
|
2021-09-21 15:06:13 +00:00
|
|
|
$(DOCKER_RUN) go build -o build/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
|
2019-09-14 12:11:40 +00:00
|
|
|
|
2019-11-12 13:27:39 +00:00
|
|
|
build-frontend:
|
|
|
|
(cd web/; yarn run build)
|
|
|
|
|
2019-09-14 12:11:40 +00:00
|
|
|
build: build-agent build-server
|
|
|
|
|
2021-06-22 11:12:26 +00:00
|
|
|
release-agent:
|
2021-09-21 15:06:13 +00:00
|
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
|
2021-06-22 11:12:26 +00:00
|
|
|
|
|
|
|
release-server:
|
2021-09-21 15:06:13 +00:00
|
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '${LDFLAGS}' -o release/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
|
2021-06-22 11:12:26 +00:00
|
|
|
|
2021-06-22 11:26:37 +00:00
|
|
|
release-cli:
|
|
|
|
# disable CGO for cross-compiling
|
|
|
|
export CGO_ENABLED=0
|
|
|
|
# compile for all architectures
|
2021-09-21 14:36:41 +00:00
|
|
|
GOOS=linux GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o cli/release/linux/amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
|
|
|
GOOS=linux GOARCH=arm64 go build -ldflags '${LDFLAGS}' -o cli/release/linux/arm64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
|
|
|
GOOS=linux GOARCH=arm go build -ldflags '${LDFLAGS}' -o cli/release/linux/arm/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
|
|
|
GOOS=windows GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o cli/release/windows/amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
|
|
|
GOOS=darwin GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o cli/release/darwin/amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
2021-06-22 11:26:37 +00:00
|
|
|
# tar binary files prior to upload
|
2021-09-21 14:36:41 +00:00
|
|
|
tar -cvzf cli/release/woodpecker_linux_amd64.tar.gz -C cli/release/linux/amd64 woodpecker-cli
|
|
|
|
tar -cvzf cli/release/woodpecker_linux_arm64.tar.gz -C cli/release/linux/arm64 woodpecker-cli
|
|
|
|
tar -cvzf cli/release/woodpecker_linux_arm.tar.gz -C cli/release/linux/arm woodpecker-cli
|
|
|
|
tar -cvzf cli/release/woodpecker_windows_amd64.tar.gz -C cli/release/windows/amd64 woodpecker-cli
|
|
|
|
tar -cvzf cli/release/woodpecker_darwin_amd64.tar.gz -C cli/release/darwin/amd64 woodpecker-cli
|
2021-06-22 11:26:37 +00:00
|
|
|
# generate shas for tar files
|
|
|
|
sha256sum cli/release/*.tar.gz > cli/release/woodpecker_checksums.txt
|
|
|
|
|
2021-06-22 11:12:26 +00:00
|
|
|
release: release-agent release-server
|