Skip to content

Instantly share code, notes, and snippets.

@abuxton
Last active September 7, 2022 11:13
Show Gist options
  • Save abuxton/da32f8ef4a9e7ecb0067f8db7bc0dfc9 to your computer and use it in GitHub Desktop.
Save abuxton/da32f8ef4a9e7ecb0067f8db7bc0dfc9 to your computer and use it in GitHub Desktop.
makefile helper

Makefile example usage


This just is just a place holder for makefile example usage, taken from https://www.terraform.io/registry/policy-libraries/publishing and https://github.com/hashicorp/policy-library-gcp-networking-terraform/blob/main/Makefile

usage

git clone https://gist.github.com/abuxton/da32f8ef4a9e7ecb0067f8db7bc0dfc9 sentinel-template
cd !$
# list all the available targets in Makefile
grep '^[^#[:space:]].*:' Makefile 
test:
tests:
format:
generate:
.PHONY: format tests

references

test:
sentinel test -verbose $(shell find . -name "$(name)" -type f ! -path "*/testdata/*")
tests:
sentinel test $(shell find . -name "*.sentinel" -type f ! -path "*/testdata/*")
format:
sentinel fmt -write=true $(shell find . -name "*.sentinel" -type f)
generate:
ifeq ($(strip $(name)),)
@echo flag needs an argument: name
@echo Usage: make generate name=deny-old-module-versions
else
@mkdir -p policies/$(name)/test/$(name)
@mkdir -p policies/$(name)/testdata
@cp example/example.sentinel policies/$(name)/$(name).sentinel
@cp example/test/example/*.hcl policies/$(name)/test/$(name)
@cp example/testdata/*.sentinel policies/$(name)/testdata
@echo Policy written to policies/$(name)/$(name).sentinel
@echo Done.
endif
.PHONY: format tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment