-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
64 lines (53 loc) · 2.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
.DEFAULT_GOAL := all
SHELL := /usr/bin/env bash -o pipefail
TMP := .tmp
DOCKER ?= docker
DOCKER_ORG ?= bufbuild
DOCKER_BUILD_EXTRA_ARGS ?=
DOCKER_BUILDER := bufbuild-plugins
DOCKER_CACHE_DIR ?= $(TMP)/dockercache
GO_TEST_FLAGS ?= -race -count=1
BUF ?= buf
BUF_PLUGIN_PUSH_ARGS ?= --visibility=public
# Specify a space or comma separated list of plugin name (and optional version) to build/test individual plugins.
# For example:
# $ make PLUGINS="connectrpc/go connectrpc/es" # builds all versions of connect-go and connect-es plugins
# $ make PLUGINS="connectrpc/go:v1.12.0" # builds connect-go v1.12.0 plugin
export PLUGINS ?=
PLUGIN_YAML_FILES := $(shell PLUGINS="$(PLUGINS)" go run ./internal/cmd/dependency-order -relative . 2>/dev/null)
.PHONY: all
all: build
.PHONY: build
build:
ifeq ($(PLUGINS),)
@echo "No plugins specified to build with PLUGINS env var."
@echo "See Makefile for example PLUGINS env var usage."
else
docker buildx inspect "$(DOCKER_BUILDER)" 2> /dev/null || docker buildx create --use --bootstrap --name="$(DOCKER_BUILDER)" > /dev/null
go run ./internal/cmd/dockerbuild -cache-dir "$(DOCKER_CACHE_DIR)" -org "$(DOCKER_ORG)" -- $(DOCKER_BUILD_EXTRA_ARGS) || \
(docker buildx rm "$(DOCKER_BUILDER)"; exit 1)
docker buildx rm "$(DOCKER_BUILDER)" > /dev/null
endif
.PHONY: dockerpush
dockerpush:
@go run ./internal/cmd/dockerpush -org "$(DOCKER_ORG)"
.PHONY: test
test: build
go test $(GO_TEST_FLAGS) ./...
.PHONY: push
push: build
for plugin in $(PLUGIN_YAML_FILES); do \
plugin_dir=`dirname $${plugin}`; \
PLUGIN_FULL_NAME=`yq '.name' $${plugin_dir}/buf.plugin.yaml`; \
PLUGIN_OWNER=`echo "$${PLUGIN_FULL_NAME}" | cut -d '/' -f 2`; \
PLUGIN_NAME=`echo "$${PLUGIN_FULL_NAME}" | cut -d '/' -f 3-`; \
PLUGIN_VERSION=`yq '.plugin_version' $${plugin_dir}/buf.plugin.yaml`; \
echo "Pushing plugin: $${plugin}"; \
if [[ "$(DOCKER_ORG)" = "ghcr.io/bufbuild" ]]; then \
$(DOCKER) pull $(DOCKER_ORG)/plugins-$${PLUGIN_OWNER}-$${PLUGIN_NAME}:$${PLUGIN_VERSION} || exit 1; \
fi; \
$(BUF) beta registry plugin push $${plugin_dir} $(BUF_PLUGIN_PUSH_ARGS) --image $(DOCKER_ORG)/plugins-$${PLUGIN_OWNER}-$${PLUGIN_NAME}:$${PLUGIN_VERSION} || exit 1; \
done
.PHONY: clean
clean:
rm -rf $(TMP)