forked from bufbuild/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
55 lines (45 loc) · 1.98 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
.DEFAULT_GOAL := all
SHELL := /usr/bin/env bash -o pipefail
DOCKER ?= docker
DOCKER_ORG ?= bufbuild
DOCKER_BUILD_EXTRA_ARGS ?=
GO_TEST_FLAGS ?= -race -count=1
BUF ?= buf
BUF_PLUGIN_PUSH_ARGS ?= --visibility=public
# Specify a space separated list of plugin name (and optional version) to just build/test individual plugins.
# For example:
# $ make PLUGINS="connect-go connect-web" # builds all versions of connect-go and connect-web plugins
# $ make PLUGINS="connect-go:v0.4.0" # builds connect-go v0.4.0 plugin
# $ make PLUGINS="bufbuild/connect-go" # can use optional prefix of the org
export PLUGINS ?=
PLUGIN_YAML_FILES := $(shell PLUGINS="$(PLUGINS)" go run ./internal/cmd/dependency-order -relative . 2>/dev/null)
.PHONY: all
all: build
@if [[ -z "${PLUGINS}" ]]; then \
echo "No plugins specified to build with PLUGINS env var."; \
echo "See Makefile for example PLUGINS env var usage."; \
echo "To build all plugins (will take a long time), build with 'make PLUGINS=all'."; \
fi
.PHONY: build
build:
@go run ./internal/cmd/dockerbuild -org "$(DOCKER_ORG)" -- $(DOCKER_BUILD_EXTRA_ARGS)
.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