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-12-21 01:35:48 +00:00
TARGETOS ?= linux
TARGETARCH ?= amd64
2021-10-04 17:50:21 +00:00
VERSION ?= next
2022-02-24 14:35:11 +00:00
VERSION_NUMBER ?= 0.0.0
2021-11-25 19:43:31 +00:00
i f n e q ( $( CI_COMMIT_TAG ) , )
VERSION := $( CI_COMMIT_TAG:v%= %)
2022-02-24 14:35:11 +00:00
VERSION_NUMBER := ${ VERSION }
2021-06-22 11:12:26 +00:00
e n d i f
2021-10-04 17:50:21 +00:00
# append commit-sha to next version
2022-02-10 14:12:47 +00:00
BUILD_VERSION ?= $( VERSION)
2021-10-04 17:50:21 +00:00
i f e q ( $( BUILD_VERSION ) , n e x t )
2021-12-21 01:35:48 +00:00
CI_COMMIT_SHA ?= $( shell git rev-parse HEAD)
2021-11-25 19:43:31 +00:00
BUILD_VERSION := $( shell echo " next- $( shell echo ${ CI_COMMIT_SHA } | head -c 8) " )
2021-06-22 11:12:26 +00:00
e n d i f
2021-10-04 17:50:21 +00:00
LDFLAGS := -s -w -extldflags "-static" -X github.com/woodpecker-ci/woodpecker/version.Version= ${ BUILD_VERSION }
2022-03-01 15:40:24 +00:00
CGO_CFLAGS ?=
HAS_GO = $( shell hash go > /dev/null 2>& 1 && echo "GO" || echo "NOGO" )
i f e q ( $( HAS_GO ) , G O )
2022-06-16 23:57:02 +00:00
XGO_VERSION ?= go-1.18.x
2022-03-01 15:40:24 +00:00
CGO_CFLAGS ?= $( shell $( GO) env CGO_CFLAGS)
e n d i f
2021-06-22 11:12:26 +00:00
2022-02-10 14:12:47 +00:00
# If the first argument is "in_docker"...
i f e q ( i n _ d o c k e r , $( firstword $ ( MAKECMDGOALS ) ) )
# use the rest as arguments for "in_docker"
MAKE_ARGS := $( wordlist 2,$( words $( MAKECMDGOALS) ) ,$( MAKECMDGOALS) )
# Ignore the next args
$( eval $( MAKE_ARGS) :; @:)
in_docker:
2022-06-16 23:57:02 +00:00
@[ "1" -eq " $( shell docker image ls woodpecker/make:local -a | wc -l) " ] && docker build -f ./docker/Dockerfile.make -t woodpecker/make:local . || echo reuse existing docker image
2022-02-10 14:12:47 +00:00
@echo run in docker:
@docker run -it \
--user $( shell id -u) :$( shell id -g) \
-e VERSION = " $( VERSION) " \
-e BUILD_VERSION = " $( BUILD_VERSION) " \
-e CI_COMMIT_SHA = " $( CI_COMMIT_SHA) " \
-e GO_PACKAGES = " $( GO_PACKAGES) " \
-e TARGETOS = " $( TARGETOS) " \
-e TARGETARCH = " $( TARGETARCH) " \
-v $( PWD) :/build --rm woodpecker/make:local make $( MAKE_ARGS)
e l s e
# Proceed with normal make
2022-09-28 15:28:23 +00:00
##@ General
all : help
.PHONY : version
version : ## Print the current version
@echo ${ BUILD_VERSION }
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY : help
help : ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $( MAKEFILE_LIST)
2019-09-14 12:11:40 +00:00
2022-08-29 22:36:37 +00:00
.PHONY : vendor
2022-09-28 15:28:23 +00:00
vendor : ## Update the vendor directory
2021-08-30 17:14:04 +00:00
go mod tidy
go mod vendor
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
format : install -tools ## Format source code
2022-09-05 15:08:51 +00:00
@gofumpt -extra -w ${ GOFILES_NOVENDOR }
2019-09-14 12:11:40 +00:00
2021-06-22 10:34:35 +00:00
.PHONY : clean
2022-09-28 15:28:23 +00:00
clean : ## Clean build artifacts
2021-06-22 10:34:35 +00:00
go clean -i ./...
rm -rf build
2022-02-10 14:12:47 +00:00
@[ "1" != " $( shell docker image ls woodpecker/make:local -a | wc -l) " ] && docker image rm woodpecker/make:local || echo no docker image to clean
2021-06-22 10:34:35 +00:00
2022-09-28 15:28:23 +00:00
check-xgo : ## Check if xgo is installed
@hash xgo > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
$( GO) install src.techknowlogick.com/xgo@latest; \
fi
install-tools : ## Install development tools
@hash golangci-lint > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi ; \
hash lint > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
go install github.com/rs/zerolog/cmd/lint@latest; \
fi ; \
hash gofumpt > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
go install mvdan.cc/gofumpt@latest; \
fi
ui-dependencies : ## Install UI dependencies
( cd web/; yarn install --frozen-lockfile)
##@ Test
2021-10-13 16:48:43 +00:00
.PHONY : lint
2022-09-28 15:28:23 +00:00
lint : install -tools ## Lint code
2021-11-14 20:01:54 +00:00
@echo "Running golangci-lint"
2022-09-07 16:36:48 +00:00
golangci-lint run --timeout 10m
2021-10-13 16:48:43 +00:00
@echo "Running zerolog linter"
2022-06-16 23:57:02 +00:00
lint github.com/woodpecker-ci/woodpecker/cmd/agent
lint github.com/woodpecker-ci/woodpecker/cmd/cli
lint github.com/woodpecker-ci/woodpecker/cmd/server
2021-10-13 16:48:43 +00:00
2022-09-28 15:28:23 +00:00
lint-ui : ## Lint UI code
2021-11-30 16:46:19 +00:00
( cd web/; yarn)
( cd web/; yarn lesshint)
( cd web/; yarn lint --quiet)
2022-09-28 15:28:23 +00:00
test-agent : ## Test agent code
2022-02-01 18:34:56 +00:00
go test -race -cover -coverprofile agent-coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/agent github.com/woodpecker-ci/woodpecker/agent/...
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
test-server : ## Test server code
2022-02-01 18:34:56 +00:00
go test -race -cover -coverprofile server-coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/server $( shell go list github.com/woodpecker-ci/woodpecker/server/... | grep -v '/store' )
2021-11-30 16:46:19 +00:00
2022-09-28 15:28:23 +00:00
test-cli : ## Test cli code
2022-02-01 18:34:56 +00:00
go test -race -cover -coverprofile cli-coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/cli github.com/woodpecker-ci/woodpecker/cli/...
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
test-server-datastore : ## Test server datastore
2022-02-01 18:34:56 +00:00
go test -race -timeout 30s github.com/woodpecker-ci/woodpecker/server/store/...
2022-09-28 15:28:23 +00:00
test-server-datastore-coverage : ## Test server datastore with coverage report
2022-02-01 18:34:56 +00:00
go test -race -cover -coverprofile datastore-coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/server/store/...
2021-12-07 00:13:31 +00:00
2022-09-28 15:28:23 +00:00
test-ui : ui -dependencies ## Test UI code
2021-11-03 16:40:31 +00:00
( cd web/; yarn run lint)
( cd web/; yarn run formatcheck)
( cd web/; yarn run typecheck)
( cd web/; yarn run test )
2019-11-12 13:27:39 +00:00
2022-09-28 15:28:23 +00:00
test-lib : ## Test lib code
2021-12-21 01:35:48 +00:00
go test -race -cover -coverprofile coverage.out -timeout 30s $( shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server' )
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
test : test -agent test -server test -server -datastore test -cli test -lib test -ui ## Run all tests
##@ Build
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
build-ui : ## Build UI
2021-11-13 19:18:06 +00:00
( cd web/; yarn install --frozen-lockfile; yarn build)
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
build-server : build -ui ## Build server
2021-12-21 01:35:48 +00:00
CGO_ENABLED = 1 GOOS = ${ TARGETOS } GOARCH = ${ TARGETARCH } go build -ldflags '${LDFLAGS}' -o dist/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
build-agent : ## Build agent
2021-12-21 01:35:48 +00:00
CGO_ENABLED = 0 GOOS = ${ TARGETOS } GOARCH = ${ TARGETARCH } go build -ldflags '${LDFLAGS}' -o dist/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
2019-11-12 13:27:39 +00:00
2022-09-28 15:28:23 +00:00
build-cli : ## Build cli
2021-12-21 01:35:48 +00:00
CGO_ENABLED = 0 GOOS = ${ TARGETOS } GOARCH = ${ TARGETARCH } go build -ldflags '${LDFLAGS}' -o dist/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
2019-09-14 12:11:40 +00:00
2022-09-28 15:28:23 +00:00
build : build -agent build -server build -cli ## Build all binaries
2021-06-22 11:12:26 +00:00
2022-09-28 15:28:23 +00:00
release-frontend : build -frontend ## Build frontend
2022-03-01 15:40:24 +00:00
2022-09-28 15:28:23 +00:00
cross-compile-server : ## Cross compile the server
2022-03-01 15:40:24 +00:00
$( foreach platform,$( subst ; , ,$( PLATFORMS) ) ,\
TARGETOS = $( firstword $( subst | , ,$( platform) ) ) \
TARGETARCH_XGO = $( subst arm64/v8,arm64,$( subst arm/v7,arm-7,$( word 2,$( subst | , ,$( platform) ) ) ) ) \
TARGETARCH_BUILDX = $( subst arm64/v8,arm64,$( subst arm/v7,arm,$( word 2,$( subst | , ,$( platform) ) ) ) ) \
make release-server-xgo || exit 1; \
)
tree dist
2022-09-28 15:28:23 +00:00
release-server-xgo : check -xgo ## Create server binaries for release using xgo
2022-03-01 15:40:24 +00:00
@echo "Building for:"
@echo " os: $( TARGETOS) "
@echo " arch orgi: $( TARGETARCH) "
@echo " arch (xgo): $( TARGETARCH_XGO) "
@echo " arch (buildx): $( TARGETARCH_BUILDX) "
CGO_CFLAGS = " $( CGO_CFLAGS) " xgo -go $( XGO_VERSION) -dest ./dist/server/$( TARGETOS) -$( TARGETARCH_XGO) -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external $(LDFLAGS)' -targets '$(TARGETOS)/$(TARGETARCH_XGO)' -out woodpecker-server -pkg cmd/server .
mkdir -p ./dist/server/$( TARGETOS) /$( TARGETARCH_BUILDX)
mv /build/woodpecker-server-$( TARGETOS) -$( TARGETARCH_XGO) ./dist/server/$( TARGETOS) /$( TARGETARCH_BUILDX) /woodpecker-server
2022-09-28 15:28:23 +00:00
release-server : ## Create server binaries for release
2021-10-04 17:50:21 +00:00
# compile
GOOS = linux GOARCH = amd64 CGO_ENABLED = 1 go build -ldflags '${LDFLAGS}' -o dist/server/linux_amd64/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
# tar binary files
tar -cvzf dist/woodpecker-server_linux_amd64.tar.gz -C dist/server/linux_amd64 woodpecker-server
2022-09-28 15:28:23 +00:00
release-agent : ## Create agent binaries for release
2021-10-04 17:50:21 +00:00
# compile
2021-10-12 07:50:56 +00:00
GOOS = linux GOARCH = amd64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/agent/linux_amd64/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
GOOS = linux GOARCH = arm64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/agent/linux_arm64/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
GOOS = linux GOARCH = arm CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/agent/linux_arm/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
GOOS = windows GOARCH = amd64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/agent/windows_amd64/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
GOOS = darwin GOARCH = amd64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/agent/darwin_amd64/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
GOOS = darwin GOARCH = arm64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/agent/darwin_arm64/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
2021-10-04 17:50:21 +00:00
# tar binary files
2021-10-12 07:50:56 +00:00
tar -cvzf dist/woodpecker-agent_linux_amd64.tar.gz -C dist/agent/linux_amd64 woodpecker-agent
tar -cvzf dist/woodpecker-agent_linux_arm64.tar.gz -C dist/agent/linux_arm64 woodpecker-agent
tar -cvzf dist/woodpecker-agent_linux_arm.tar.gz -C dist/agent/linux_arm woodpecker-agent
tar -cvzf dist/woodpecker-agent_windows_amd64.tar.gz -C dist/agent/windows_amd64 woodpecker-agent
tar -cvzf dist/woodpecker-agent_darwin_amd64.tar.gz -C dist/agent/darwin_amd64 woodpecker-agent
tar -cvzf dist/woodpecker-agent_darwin_arm64.tar.gz -C dist/agent/darwin_arm64 woodpecker-agent
2021-06-22 11:12:26 +00:00
2022-09-28 15:28:23 +00:00
release-cli : ## Create cli binaries for release
2021-10-04 17:50:21 +00:00
# compile
2021-10-04 23:56:11 +00:00
GOOS = linux GOARCH = amd64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/cli/linux_amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS = linux GOARCH = arm64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/cli/linux_arm64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS = linux GOARCH = arm CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/cli/linux_arm/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS = windows GOARCH = amd64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/cli/windows_amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS = darwin GOARCH = amd64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/cli/darwin_amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS = darwin GOARCH = arm64 CGO_ENABLED = 0 go build -ldflags '${LDFLAGS}' -o dist/cli/darwin_arm64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
2021-10-04 17:50:21 +00:00
# tar binary files
tar -cvzf dist/woodpecker-cli_linux_amd64.tar.gz -C dist/cli/linux_amd64 woodpecker-cli
tar -cvzf dist/woodpecker-cli_linux_arm64.tar.gz -C dist/cli/linux_arm64 woodpecker-cli
tar -cvzf dist/woodpecker-cli_linux_arm.tar.gz -C dist/cli/linux_arm woodpecker-cli
tar -cvzf dist/woodpecker-cli_windows_amd64.tar.gz -C dist/cli/windows_amd64 woodpecker-cli
tar -cvzf dist/woodpecker-cli_darwin_amd64.tar.gz -C dist/cli/darwin_amd64 woodpecker-cli
tar -cvzf dist/woodpecker-cli_darwin_arm64.tar.gz -C dist/cli/darwin_arm64 woodpecker-cli
2022-09-28 15:28:23 +00:00
release-tarball : ## Create tarball for release
2022-06-16 23:57:02 +00:00
tar -cvzf dist/woodpecker-src-$( BUILD_VERSION) .tar.gz \
agent \
cli \
cmd \
go.??? \
LICENSE \
Makefile \
pipeline \
server \
shared \
vendor \
version \
woodpecker-go \
web/index.html \
web/node_modules \
web/package.json \
web/public \
web/src \
web/package.json \
web/tsconfig.* \
web/*.ts \
web/yarn.lock \
web/web.go
2022-09-28 15:28:23 +00:00
release-checksums : ## Create checksums for all release files
2021-06-22 11:26:37 +00:00
# generate shas for tar files
2022-01-29 12:58:55 +00:00
( cd dist/; sha256sum *.* > checksums.txt)
2021-10-04 17:50:21 +00:00
2022-09-28 15:28:23 +00:00
release : release -frontend release -server release -agent release -cli ## Release all binaries
2021-06-22 11:26:37 +00:00
2022-09-28 15:28:23 +00:00
bundle-prepare : ## Prepare the bundles
2021-10-21 16:34:49 +00:00
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.6.0
2021-10-20 19:55:09 +00:00
2022-09-28 15:28:23 +00:00
bundle-agent : bundle -prepare ## Create bundles for agent
2022-03-01 11:28:44 +00:00
VERSION_NUMBER = $( VERSION_NUMBER) nfpm package --config ./nfpm/nfpm-agent.yml --target ./dist --packager deb
VERSION_NUMBER = $( VERSION_NUMBER) nfpm package --config ./nfpm/nfpm-agent.yml --target ./dist --packager rpm
2021-10-20 19:55:09 +00:00
2022-09-28 15:28:23 +00:00
bundle-server : bundle -prepare ## Create bundles for server
2022-03-01 11:28:44 +00:00
VERSION_NUMBER = $( VERSION_NUMBER) nfpm package --config ./nfpm/nfpm-server.yml --target ./dist --packager deb
VERSION_NUMBER = $( VERSION_NUMBER) nfpm package --config ./nfpm/nfpm-server.yml --target ./dist --packager rpm
2021-10-20 19:55:09 +00:00
2022-09-28 15:28:23 +00:00
bundle-cli : bundle -prepare ## Create bundles for cli
2022-03-01 11:28:44 +00:00
VERSION_NUMBER = $( VERSION_NUMBER) nfpm package --config ./nfpm/nfpm-cli.yml --target ./dist --packager deb
VERSION_NUMBER = $( VERSION_NUMBER) nfpm package --config ./nfpm/nfpm-cli.yml --target ./dist --packager rpm
2021-10-20 19:55:09 +00:00
2022-09-28 15:28:23 +00:00
bundle : bundle -agent bundle -server bundle -cli ## Create all bundles
2021-10-20 19:55:09 +00:00
2022-09-28 15:28:23 +00:00
##@ Docs
.PHONY : docs
docs : ## Generate docs (currently only for the cli)
go generate cmd/cli/app.go
2022-02-10 14:12:47 +00:00
e n d i f