github.com/section/sectionctl@v1.12.3/Makefile (about)

     1  .PHONY: test
     2  
     3  export PATH := bin:$(PATH)
     4  export HEAPAPPID := 892134159
     5  
     6  staticcheck := /home/runner/go/bin/staticcheck
     7  
     8  ifeq ($(OS),Windows_NT)     # is Windows_NT on XP, 2000, 7, Vista, 10...
     9      detected_OS := Windows
    10  else
    11      detected_OS := $(shell uname)  # same as "uname -s"
    12  endif
    13  
    14  
    15  all: test
    16  
    17  cidep:
    18  	go get -u honnef.co/go/tools/cmd/staticcheck
    19  	go get -u github.com/kisielk/errcheck
    20  
    21  test: gotest gostaticcheck goerrcheck
    22  
    23  gotest:
    24  	go test ./... -v -timeout=45s -failfast
    25  
    26  gostaticcheck:
    27  	staticcheck ./...
    28  
    29  goerrcheck:
    30  	errcheck -exclude .lint/errcheck-excludes -blank -ignoretests ./...
    31  
    32  build: clean
    33  	go build -o sectionctl -ldflags "-X 'github.com/section/sectionctl/version.Version=$(shell echo $(VERSION) | cut -c 2-)'"
    34  
    35  
    36  build-release: clean check_version
    37  	@if [ -z "$(GOOS)" ]; then echo "Missing GOOS"; exit 1 ; fi
    38  	@if [ -z "$(GOARCH)" ]; then echo "Missing GOARCH"; exit 1 ; fi
    39  	go build -o sectionctl -ldflags "-X 'github.com/section/sectionctl/version.Version=$(shell echo $(VERSION) | cut -c 2-)'"
    40  	mkdir -p dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH)/
    41  	cp README.md LICENSE sectionctl dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH)/
    42  	chmod +x dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH)/sectionctl
    43  	@if [ "$(GOOS)" = "windows" ]; then mv dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH)/sectionctl dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH)/sectionctl.exe  ; fi
    44  	tar --create --gzip --verbose --file dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH).tar.gz --directory dist/sectionctl-$(VERSION)-$(GOOS)-$(GOARCH) .
    45  
    46  clean:
    47  	rm -rf dist bin
    48  
    49  check_version:
    50  	@if [ -z "$(VERSION)" ]; then echo "Missing VERSION"; exit 1 ; fi
    51  	@if [ "$(shell echo $(VERSION) | cut -c 1)" != "v" ]; then echo "VERSION must be in the format v0.0.5"; exit 1 ; fi
    52  
    53  release: check_version
    54  	@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "main" ]; then echo "Must be on the 'main' branch"; exit 1 ; fi
    55  	@git update-index --refresh
    56  	@git diff-index --quiet HEAD --
    57  	git tag -f -a $(VERSION) -m ''
    58  	git push origin main
    59  	git push origin refs/tags/$(VERSION)
    60  
    61  test-release: check_version
    62  	@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "v0.0.0-test" ]; then echo "Must be on the 'v0.0.0-test' branch"; exit 1 ; fi
    63  	@git update-index --refresh
    64  	@git diff-index --quiet HEAD --
    65  	git tag -f -a $(VERSION) -m ''
    66  	git push origin v0.0.0-test
    67  	git push origin refs/tags/$(VERSION)
    68  
    69  
    70  
    71  ifeq ($(detected_OS),Windows)
    72  windows-installer: nsis-windows
    73  else
    74  windows-installer: nsis-ubuntu
    75  endif
    76  
    77  ifeq ($(detected_OS),Linux)
    78  windows-installer: nsis-ubuntu
    79  endif
    80  
    81  ifeq (,$(wildcard /usr/share/nsis/Plugins/x86-unicode/EnVar.dll))
    82  nsis-ubuntu: nsis-ubuntu-deps nsis-ubuntu-build
    83  else
    84  nsis-ubuntu: check_version nsis-ubuntu-build
    85  
    86  endif
    87  
    88  nsis-ubuntu-build: build-release
    89  	version_major=$(shell echo $(VERSION) | cut -c 2- | cut -d. -f1)
    90  	version_minor=$(shell echo $(VERSION) | cut -d. -f2)
    91  	version_patch=$(shell echo $(VERSION) | cut -d. -f3)
    92  	echo $(version_patch)
    93  	echo $(version_minor)
    94  	echo $(version_major)
    95  	makensis -DARCH=amd64 -DOUTPUTFILE=sectionctl-$(VERSION)-windows-amd64-installer.exe -DSECTIONCTL_VERSION=$(VERSION) -DMAJORVERSION=$(version_major) -DDMINORVERSION=$(version_minor) -DBUILDVERSION=$(version_patch) packaging/windows/nsis.sectionctl.nsi 
    96  nsis-ubuntu-deps:
    97  	sudo apt update && sudo apt install -y nsis nsis-pluginapi
    98  	wget https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip
    99  	sudo unzip EnVar_plugin.zip -d /usr/share/nsis/
   100  	rm EnVar_plugin.zip
   101  
   102  nsis-windows:
   103  	echo "Not available on Windows yet"