Improve release (#400)

* improve make release

* improve release

* fix release workflow
This commit is contained in:
Anbraten 2021-10-04 19:50:21 +02:00 committed by GitHub
parent e3354e440f
commit 2084ff3a62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 45 deletions

3
.gitignore vendored
View file

@ -33,9 +33,8 @@ docker-compose.yml
*.out *.out
/.env /.env
extras/ extras/
release/
/build/ /build/
cli/release/ /dist/
server/swagger/files/*.json server/swagger/files/*.json
server/swagger/swagger_gen.go server/swagger/swagger_gen.go

View file

@ -41,20 +41,28 @@ pipeline:
build-frontend: build-frontend:
image: node:10.17.0-stretch image: node:10.17.0-stretch
commands: commands:
- make build-frontend - make release-frontend
build: build-server:
group: build
image: golang:1.16 image: golang:1.16
commands: commands:
- go get github.com/woodpecker-ci/togo - make release-server
- (cd web/; go generate ./...)
- make release build-agent:
group: build
image: golang:1.16
commands:
- make release-agent
build-cli: build-cli:
group: build
image: golang:1.16 image: golang:1.16
commands: make release-cli commands:
- make release-cli
publish-server: publish-server:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-server repo: woodpeckerci/woodpecker-server
dockerfile: docker/Dockerfile.server dockerfile: docker/Dockerfile.server
@ -66,6 +74,7 @@ pipeline:
event: push event: push
publish-server-alpine: publish-server-alpine:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-server repo: woodpeckerci/woodpecker-server
dockerfile: docker/Dockerfile.server.alpine dockerfile: docker/Dockerfile.server.alpine
@ -77,6 +86,7 @@ pipeline:
event: push event: push
publish-agent: publish-agent:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-agent repo: woodpeckerci/woodpecker-agent
dockerfile: docker/Dockerfile.agent dockerfile: docker/Dockerfile.agent
@ -88,6 +98,7 @@ pipeline:
event: push event: push
publish-agent-alpine: publish-agent-alpine:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-agent repo: woodpeckerci/woodpecker-agent
dockerfile: docker/Dockerfile.agent.alpine dockerfile: docker/Dockerfile.agent.alpine
@ -99,6 +110,7 @@ pipeline:
event: push event: push
release-server: release-server:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-server repo: woodpeckerci/woodpecker-server
dockerfile: docker/Dockerfile.server dockerfile: docker/Dockerfile.server
@ -108,6 +120,7 @@ pipeline:
event: tag event: tag
release-server-alpine: release-server-alpine:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-server repo: woodpeckerci/woodpecker-server
dockerfile: docker/Dockerfile.server.alpine dockerfile: docker/Dockerfile.server.alpine
@ -117,6 +130,7 @@ pipeline:
event: tag event: tag
release-agent: release-agent:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-agent repo: woodpeckerci/woodpecker-agent
dockerfile: docker/Dockerfile.agent dockerfile: docker/Dockerfile.agent
@ -126,6 +140,7 @@ pipeline:
event: tag event: tag
release-agent-alpine: release-agent-alpine:
group: docker
image: plugins/docker image: plugins/docker
repo: woodpeckerci/woodpecker-agent repo: woodpeckerci/woodpecker-agent
dockerfile: docker/Dockerfile.agent.alpine dockerfile: docker/Dockerfile.agent.alpine
@ -134,11 +149,21 @@ pipeline:
when: when:
event: tag event: tag
release-cli: checksums:
image: golang:1.16
commands:
- make release-checksums
when:
event: tag
# TODO: upload build artifacts for pushes to master
release:
image: plugins/github-release image: plugins/github-release
files: files:
- cli/release/woodpecker_*.tar.gz - dist/*.tar.gz
- cli/release/woodpecker_checksums.txt - dist/checksums.txt
title: ${DRONE_TAG##v}
secrets: secrets:
- source: github_token - source: github_token
target: github_release_api_key target: github_release_api_key

View file

@ -2,16 +2,18 @@ DOCKER_RUN_GO_VERSION=1.16
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*") GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/) GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
VERSION ?= ${DRONE_TAG} VERSION ?= next
ifeq ($(VERSION),) ifneq ($(DRONE_TAG),)
VERSION := $(shell echo ${DRONE_COMMIT_SHA} | head -c 8) VERSION := $(DRONE_TAG:v%=%)
endif endif
LDFLAGS ?= -extldflags "-static" # append commit-sha to next version
ifneq ($(VERSION),) BUILD_VERSION := $(VERSION)
LDFLAGS := ${LDFLAGS} -X github.com/woodpecker-ci/woodpecker/version.Version=${VERSION} ifeq ($(BUILD_VERSION),next)
BUILD_VERSION := $(shell echo "next-$(shell echo ${DRONE_COMMIT_SHA} | head -c 8)")
endif endif
LDFLAGS := -s -w -extldflags "-static" -X github.com/woodpecker-ci/woodpecker/version.Version=${BUILD_VERSION}
DOCKER_RUN?= DOCKER_RUN?=
_with-docker: _with-docker:
@ -53,39 +55,56 @@ test-lib:
test: test-lib test-agent test-server test: test-lib test-agent test-server
build-agent:
$(DOCKER_RUN) go build -o build/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
build-server:
$(DOCKER_RUN) go build -o build/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
build-frontend: build-frontend:
(cd web/; yarn; yarn run build) (cd web/; yarn; yarn build)
build: build-agent build-server build-server: build-frontend
$(DOCKER_RUN) go build -o dist/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
release-agent: build-agent:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '${LDFLAGS}' -o release/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent $(DOCKER_RUN) go build -o dist/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
build-cli:
$(DOCKER_RUN) go build -o dist/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
build: build-agent build-server build-cli
release-frontend: build-frontend
release-server: release-server:
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '${LDFLAGS}' -o release/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server # 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
release-agent:
# compile
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
# tar binary files
tar -cvzf dist/woodpecker-agent_linux_amd64.tar.gz -C dist/agent/linux_amd64 woodpecker-agent
release-cli: release-cli:
# disable CGO for cross-compiling # compile
export CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o dist/cli/linux_amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
# compile for all architectures GOOS=linux GOARCH=arm64 go build -ldflags '${LDFLAGS}' -o dist/cli/linux_arm64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
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=arm go build -ldflags '${LDFLAGS}' -o dist/cli/linux_arm/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=windows GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o dist/cli/windows_amd64/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=darwin GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o dist/cli/darwin_amd64/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=arm64 go build -ldflags '${LDFLAGS}' -o dist/cli/darwin_arm64/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 # tar binary files
# tar binary files prior to upload tar -cvzf dist/woodpecker-cli_linux_amd64.tar.gz -C dist/cli/linux_amd64 woodpecker-cli
tar -cvzf cli/release/woodpecker_linux_amd64.tar.gz -C cli/release/linux/amd64 woodpecker-cli tar -cvzf dist/woodpecker-cli_linux_arm64.tar.gz -C dist/cli/linux_arm64 woodpecker-cli
tar -cvzf cli/release/woodpecker_linux_arm64.tar.gz -C cli/release/linux/arm64 woodpecker-cli tar -cvzf dist/woodpecker-cli_linux_arm.tar.gz -C dist/cli/linux_arm woodpecker-cli
tar -cvzf cli/release/woodpecker_linux_arm.tar.gz -C cli/release/linux/arm woodpecker-cli tar -cvzf dist/woodpecker-cli_windows_amd64.tar.gz -C dist/cli/windows_amd64 woodpecker-cli
tar -cvzf cli/release/woodpecker_windows_amd64.tar.gz -C cli/release/windows/amd64 woodpecker-cli tar -cvzf dist/woodpecker-cli_darwin_amd64.tar.gz -C dist/cli/darwin_amd64 woodpecker-cli
tar -cvzf cli/release/woodpecker_darwin_amd64.tar.gz -C cli/release/darwin/amd64 woodpecker-cli tar -cvzf dist/woodpecker-cli_darwin_arm64.tar.gz -C dist/cli/darwin_arm64 woodpecker-cli
# generate shas for tar files
sha256sum cli/release/*.tar.gz > cli/release/woodpecker_checksums.txt
release: release-agent release-server release-checksums:
# generate shas for tar files
(cd dist/; sha256sum *.{tar.gz,apk,deb,rpm} > checksums.txt)
release: release-frontend release-server release-agent release-cli
.PHONY: version
version:
@echo ${VERSION}