2016-08-24 22:37:18 +03:00
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
2023-08-15 00:11:19 +03:00
PROJECT := github.com/getsops/sops/v3
PROJECT_DIR := $( shell dirname $( abspath $( lastword $( MAKEFILE_LIST) ) ) )
2023-08-17 01:13:52 +03:00
BIN_DIR := $( PROJECT_DIR) /bin
2023-08-15 01:00:43 +03:00
2023-08-15 00:11:19 +03:00
GO := GOPROXY = https://proxy.golang.org go
2023-08-15 01:00:43 +03:00
GO_TEST_FLAGS ?= -race -coverprofile= profile.out -covermode= atomic
2016-08-24 22:37:18 +03:00
2023-08-15 00:11:19 +03:00
GITHUB_REPOSITORY ?= github.com/getsops/sops
2023-08-11 01:10:59 +03:00
2023-08-17 01:13:52 +03:00
STATICCHECK := $( BIN_DIR) /staticcheck
2023-08-15 00:11:19 +03:00
STATICCHECK_VERSION := latest
2023-08-17 01:13:52 +03:00
SYFT := $( BIN_DIR) /syft
SYFT_VERSION ?= v0.87.0
GORELEASER := $( BIN_DIR) /goreleaser
2023-08-15 00:11:19 +03:00
GORELEASER_VERSION ?= v1.20.0
2023-08-11 01:10:59 +03:00
2023-09-16 23:38:17 +03:00
RSTCHECK := $( shell command -v rstcheck)
MARKDOWNLINT := $( shell command -v mdl)
2023-08-17 01:13:52 +03:00
export PATH := $( BIN_DIR) :$( PATH)
2023-08-11 01:10:59 +03:00
.PHONY : all
2016-11-14 00:20:13 +03:00
all : test vet generate install functional -tests
2023-08-11 01:10:59 +03:00
.PHONY : origin -build
2019-03-29 20:42:01 +03:00
origin-build : test vet generate install functional -tests -all
2016-08-24 22:37:18 +03:00
2023-08-17 01:27:28 +03:00
.PHONY : install
2016-08-24 22:37:18 +03:00
install :
2023-07-11 22:09:23 +03:00
$( GO) install github.com/getsops/sops/v3/cmd/sops
2016-08-24 22:37:18 +03:00
2023-08-15 00:11:19 +03:00
.PHONY : staticcheck
staticcheck : install -staticcheck
$( STATICCHECK) ./...
2016-08-24 22:37:18 +03:00
2023-08-11 01:10:59 +03:00
.PHONY : vendor
2016-10-26 22:44:11 +03:00
vendor :
2019-07-30 11:55:08 +03:00
$( GO) mod tidy
$( GO) mod vendor
2016-10-26 22:44:11 +03:00
2023-08-17 01:27:28 +03:00
.PHONY : vet
2016-08-24 22:37:18 +03:00
vet :
2023-08-12 02:51:24 +03:00
$( GO) vet ./...
2016-08-24 22:37:18 +03:00
2023-09-16 23:38:17 +03:00
.PHONY : checkdocs
checkdocs : checkrst checkmd
.PHONY : checkrst
RST_FILES = $( shell find . -name '*.rst' | grep -v /vendor/ | sort)
checkrst : $( RST_FILES )
@if [ " $( RSTCHECK) " = = "" ] ; then echo "Need rstcheck to lint RST files. Install rstcheck from your system package repository or from PyPI (https://pypi.org/project/rstcheck/)." ; exit 1; fi
$( RSTCHECK) --report-level warning $^
.PHONY : checkmd
MD_FILES = $( shell find . -name '*.md' | grep -v /vendor/ | sort)
checkmd : $( MD_FILES )
@if [ " $( MARKDOWNLINT) " = = "" ] ; then echo "Need markdownlint to lint RST files. Install markdownlint from your system package repository or from https://github.com/markdownlint/markdownlint." ; exit 1; fi
$( MARKDOWNLINT) $^
2023-08-11 01:10:59 +03:00
.PHONY : test
2019-08-01 00:25:29 +03:00
test : vendor
2016-08-25 22:21:10 +03:00
gpg --import pgp/sops_functional_tests_key.asc 2>& 1 1>/dev/null || exit 0
2024-09-04 04:02:17 +03:00
unset SOPS_AGE_KEY_FILE; LANG = en_US.UTF-8 $( GO) test $( GO_TEST_FLAGS) ./...
2016-08-24 22:37:18 +03:00
2023-08-17 01:27:28 +03:00
.PHONY : showcoverage
2016-08-24 22:37:18 +03:00
showcoverage : test
2023-08-17 01:27:28 +03:00
$( GO) tool cover -html= profile.out
2016-08-24 22:37:18 +03:00
2023-08-11 01:10:59 +03:00
.PHONY : generate
2018-06-17 23:50:30 +03:00
generate : keyservice /keyservice .pb .go
2016-08-24 22:37:18 +03:00
$( GO) generate
2018-06-17 23:50:30 +03:00
%.pb.go : %.proto
protoc --go_out= plugins = grpc:. $<
2023-08-11 01:10:59 +03:00
.PHONY : functional -tests
2016-11-14 00:20:13 +03:00
functional-tests :
2023-07-11 22:09:23 +03:00
$( GO) build -o functional-tests/sops github.com/getsops/sops/v3/cmd/sops
2016-11-14 00:20:13 +03:00
cd functional-tests && cargo test
2023-08-11 01:10:59 +03:00
.PHONY : functional -tests -all
2019-03-29 20:42:01 +03:00
functional-tests-all :
2023-07-11 22:09:23 +03:00
$( GO) build -o functional-tests/sops github.com/getsops/sops/v3/cmd/sops
2023-08-11 01:10:59 +03:00
# Ignored tests are ones that require external services (e.g. AWS KMS)
# TODO: Once `--include-ignored` lands in rust stable, switch to that.
2019-03-29 20:42:01 +03:00
cd functional-tests && cargo test && cargo test -- --ignored
2023-08-11 01:10:59 +03:00
.PHONY : release -snapshot
2023-08-17 01:13:52 +03:00
release-snapshot : install -goreleaser install -syft
2024-06-10 23:03:05 +03:00
GITHUB_REPOSITORY = $( GITHUB_REPOSITORY) $( GORELEASER) release --clean --snapshot --skip= sign
2023-08-11 01:10:59 +03:00
2023-08-17 01:27:28 +03:00
.PHONY : clean
clean :
rm -rf $( BIN_DIR) profile.out functional-tests/sops
2023-08-15 00:11:19 +03:00
.PHONY : install -staticcheck
install-staticcheck :
$( call go-install-tool,$( STATICCHECK) ,honnef.co/go/tools/cmd/staticcheck@$( STATICCHECK_VERSION) ,$( STATICCHECK_VERSION) )
2023-08-11 01:10:59 +03:00
.PHONY : install -goreleaser
install-goreleaser :
$( call go-install-tool,$( GORELEASER) ,github.com/goreleaser/goreleaser@$( GORELEASER_VERSION) ,$( GORELEASER_VERSION) )
2023-08-17 01:13:52 +03:00
.PHONY : install -syft
install-syft :
$( call go-install-tool,$( SYFT) ,github.com/anchore/syft/cmd/syft@$( SYFT_VERSION) ,$( SYFT_VERSION) )
2023-08-11 01:10:59 +03:00
# go-install-tool will 'go install' any package $2 and install it to $1.
d e f i n e g o - i n s t a l l - t o o l
@ [ - f $( 1) - $( 3) ] | | { \
s e t - e ; \
GOBIN = $$ ( dirname $( 1) ) go install $( 2) ; \
t o u c h $( 1) - $( 3) ; \
}
e n d e f