Skip to content

Commit 68a5605

Browse files
author
Chris Vermeulen
authored
Merge pull request #5 from compliance-framework/feature-standard-make
Standardise make and actions
2 parents 8d974fc + 9b039cd commit 68a5605

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup OPA
1515
uses: open-policy-agent/setup-opa@v2
1616
with:
17-
version: latest
17+
version: 1.6.0
1818

1919
- name: Run OPA Tests
2020
run: opa test policies

Makefile

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,39 @@
1-
# Makefile for building and pushing OPA policies to a registry
2-
3-
# Variables
4-
REGISTRY_URL := ghcr.io
5-
NAMESPACE := compliance-framework
6-
POLICY_NAME := plugin-github-settings-policies
7-
VERSION := latest
8-
POLICY_DIR := ./policies # Directory containing your .rego files
9-
10-
# Build and Push Commands
11-
.PHONY: all build bundle push clean
12-
13-
# Default action
14-
all: test check build push clean
1+
# The help target prints out all targets with their descriptions organized
2+
# beneath their categories. The categories are represented by '##@' and the
3+
# target descriptions by '##'. The awk commands is responsible for reading the
4+
# entire set of makefiles included in this invocation, looking for lines of the
5+
# file as xyz: ## something, and then pretty-format the target and help. Then,
6+
# if there's a line with ##@ something, that gets pretty-printed as a category.
7+
# More info on the usage of ANSI catalog characters for terminal formatting:
8+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
9+
# More info on the awk command:
10+
# http://linuxcommand.org/lc3_adv_awk.php
1511

1612
# Check if OPA CLI is installed
1713
OPA := $(shell command -v opa 2> /dev/null)
1814
ifeq ($(OPA),)
1915
$(error "opa CLI not found. Please install it: https://www.openpolicyagent.org/docs/latest/cli/")
2016
endif
2117

22-
# Check if Docker CLI is installed
18+
##@ Help
19+
help: ## Display this concise help, ie only the porcelain target
20+
@awk 'BEGIN {FS = ":.*##"; printf "\033[1mUsage\033[0m\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
2321

24-
CONTAINER_CLI := ""
25-
DOCKER := $(shell command -v docker 2> /dev/null)
26-
PODMAN := $(shell command -v podman 2> /dev/null)
27-
ifeq ($(DOCKER),)
28-
PODMAN := := $(shell command -v podman 2> /dev/null)
29-
ifeq ($(PODMAN),)
30-
$(error "either docker or podman CLI is required.")
31-
else
32-
CONTAINER_CLI = PODMAN
33-
endif
34-
else
35-
CONTAINER_CLI = DOCKER
36-
endif
22+
help-all: ## Display all help items, ie including plumbing targets
23+
@awk 'BEGIN {FS = ":.*#"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?#/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^#@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
3724

38-
test:
39-
@echo "Testing policies..."
25+
##@ Policies
26+
test: ## Test policy files
4027
@OPA test policies
4128

42-
# Build the policies
43-
check:
44-
@echo "Checking policies..."
29+
validate: ## Validate policy files
4530
@opa check policies
4631

32+
clean: # Cleanup build artifacts
33+
@rm -f dist/*
34+
4735
# Bundle the policies into a tarball for OCI registry
48-
build: clean
49-
@echo "Bundling policies..."
36+
build: clean ## Build the policy bundle
5037
@mkdir -p dist/
5138
@opa build -b policies -o dist/bundle.tar.gz
5239

53-
# Push the bundled policies to an OCI-compliant registry
54-
push: build
55-
@echo "Pushing bundle to registry..."
56-
@# Log in to the registry if necessary
57-
@$(CONTAINER_CLI) login $(REGISTRY_URL)
58-
@# Push the bundle as an OCI artifact
59-
@$(CONTAINER_CLI) cp dist/bundle.tar.gz $(REGISTRY_URL)/$(NAMESPACE)/$(POLICY_NAME):$(VERSION)
60-
@echo "Bundle pushed successfully to $(REGISTRY_URL)/$(NAMESPACE)/$(POLICY_NAME):$(VERSION)"
61-
62-
# Clean up build artifacts
63-
clean:
64-
@echo "Cleaning up..."
65-
@rm -f dist/bundle.tar.gz

0 commit comments

Comments
 (0)