github.com/companieshouse/lfp-pay-api@v0.0.0-20230203133422-0ca455cd79f9/Makefile (about)

     1  CHS_ENV_HOME ?= $(HOME)/.chs_env
     2  TESTS        ?= ./...
     3  
     4  bin          := lfp-pay-api
     5  chs_envs     := $(CHS_ENV_HOME)/global_env $(CHS_ENV_HOME)/lfp-pay-api/env
     6  source_env   := for chs_env in $(chs_envs); do test -f $$chs_env && . $$chs_env; done
     7  xunit_output := test.xml
     8  lint_output  := lint.txt
     9  
    10  .EXPORT_ALL_VARIABLES:
    11  GO111MODULE = on
    12  
    13  .PHONY: all
    14  all: build
    15  
    16  .PHONY: fmt
    17  fmt:
    18  	go fmt ./...
    19  
    20  .PHONY: build
    21  build: fmt $(bin)
    22  
    23  $(bin):
    24  	CGO_ENABLED=0 go build -o ./$(bin)
    25  
    26  .PHONY: test
    27  test: test-unit test-integration
    28  
    29  .PHONY: test-unit
    30  test-unit:
    31  	go test $(TESTS) -run 'Unit' -coverprofile=coverage.out
    32  
    33  .PHONY: test-integration
    34  test-integration:
    35  	$(source_env); go test $(TESTS) -run 'Integration'
    36  
    37  .PHONY: clean
    38  clean:
    39  	go mod tidy
    40  	rm -f ./$(bin) ./$(bin)-*.zip $(test_path) build.log
    41  
    42  .PHONY: package
    43  package:
    44  ifndef version
    45  	$(error No version given. Aborting)
    46  endif
    47  	$(info Packaging version: $(version))
    48  	$(eval tmpdir := $(shell mktemp -d build-XXXXXXXXXX))
    49  	cp ./$(bin) $(tmpdir)
    50  	cp ./routes.yaml $(tmpdir)
    51  	cp ./start.sh $(tmpdir)
    52  	cp -r ./assets  $(tmpdir)/assets
    53  	cd $(tmpdir) && zip -r ../$(bin)-$(version).zip $(bin) start.sh routes.yaml assets
    54  	rm -rf $(tmpdir)
    55  
    56  .PHONY: dist
    57  dist: clean build package
    58  
    59  .PHONY: xunit-tests
    60  xunit-tests: GO111MODULE = off
    61  xunit-tests:
    62  	go get github.com/tebeka/go2xunit
    63  	@set -a; go test -v $(TESTS) -run 'Unit' | go2xunit -output $(xunit_output)
    64  
    65  .PHONY: lint
    66  lint: GO111MODULE = off
    67  lint:
    68  	go get -u github.com/alecthomas/gometalinter
    69  	gometalinter --install
    70  	gometalinter ./... > $(lint_output); true