forked from lunny/changelog
Reviewed-on: https://gitea.com/gitea/changelog/pulls/65 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: John Olheiser <john+gitea@jolheiser.com> Co-committed-by: John Olheiser <john+gitea@jolheiser.com>
84 lines
2.4 KiB
Makefile
84 lines
2.4 KiB
Makefile
DIST := dist
|
|
GO ?= go
|
|
SED_INPLACE := sed -i
|
|
SHASUM ?= shasum -a 256
|
|
|
|
ifneq ($(DRONE_TAG),)
|
|
VERSION ?= $(subst v,,$(DRONE_TAG))
|
|
LONG_VERSION ?= $(VERSION)
|
|
else
|
|
ifneq ($(DRONE_BRANCH),)
|
|
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
|
|
else
|
|
VERSION ?= master
|
|
endif
|
|
LONG_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
|
endif
|
|
|
|
LDFLAGS := $(LDFLAGS) -X "code.gitea.io/changelog/cmd.Version=$(LONG_VERSION)"
|
|
|
|
.PHONY: build
|
|
build:
|
|
$(GO) build -ldflags '-s -w $(LDFLAGS)'
|
|
|
|
.PHONY: test
|
|
test:
|
|
$(GO) test -race -v ./...
|
|
|
|
.PHONY: lint
|
|
lint:
|
|
$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 run --timeout 5m
|
|
|
|
.PHONY: fmt
|
|
fmt:
|
|
$(GO) fmt ./...
|
|
|
|
.PHONY: release
|
|
release: release-dirs check-xgo release-windows release-linux release-darwin release-copy release-compress release-check
|
|
|
|
.PHONY: check-xgo
|
|
check-xgo:
|
|
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
$(GO) get -u src.techknowlogick.com/xgo; \
|
|
fi
|
|
|
|
.PHONY: release-dirs
|
|
release-dirs:
|
|
mkdir -p $(DIST)/binaries $(DIST)/release
|
|
|
|
.PHONY: release-windows
|
|
release-windows:
|
|
xgo -dest $(DIST)/binaries -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out changelog-$(VERSION) .
|
|
ifeq ($(CI),drone)
|
|
cp /build/* $(DIST)/binaries
|
|
endif
|
|
|
|
.PHONY: release-linux
|
|
release-linux:
|
|
xgo -dest $(DIST)/binaries -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out changelog-$(VERSION) .
|
|
ifeq ($(CI),drone)
|
|
cp /build/* $(DIST)/binaries
|
|
endif
|
|
|
|
.PHONY: release-darwin
|
|
release-darwin:
|
|
xgo -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out changelog-$(VERSION) .
|
|
ifeq ($(CI),drone)
|
|
cp /build/* $(DIST)/binaries
|
|
endif
|
|
|
|
.PHONY: release-copy
|
|
release-copy:
|
|
cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
|
|
|
|
.PHONY: release-check
|
|
release-check:
|
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
|
|
|
|
.PHONY: release-compress
|
|
release-compress:
|
|
@hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
$(GO) install github.com/ulikunitz/xz/cmd/gxz@latest; \
|
|
fi
|
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
|