-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
127 lines (99 loc) · 4.33 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
SHELL := /usr/bin/env bash
BIN = $(CURDIR)/.bin
OSP_VERSION ?= latest
# using the chart name and version from chart's metadata
CHART_NAME ?= $(shell awk '/^name:/ { print $$2 }' Chart.yaml)
CHART_VERSION ?= $(shell awk '/^version:/ { print $$2 }' Chart.yaml)
RELEASE_VERSION = v$(CHART_VERSION)
# release directory where the Tekton resources are rendered into.
RELEASE_DIR ?= /tmp/$(CHART_NAME)-$(CHART_VERSION)
# bats entry point and default flags
BATS_CORE = ./test/.bats/bats-core/bin/bats
BATS_FLAGS ?= --print-output-on-failure --show-output-of-passing-tests --verbose-run
# path to the bats test files, overwite the variables below to tweak the test scope
E2E_TESTS ?= ./test/e2e/*.bats
E2E_OPENSHIFT_PARAMS_SCRIPT ?= oc version
E2E_TKN_PARAMS_SCRIPT ?= tkn version
E2E_OPC_PARAMS_SCRIPT ?= opc version
E2E_KN_PARAMS_ARGS ?= help
E2E_KN_APPLY_PARAMS_SERVICE ?= hello
E2E_KN_APPLY_PARAMS_IMAGE ?= gcr.io/knative-samples/helloworld-go:latest
# generic arguments employed on most of the targets
ARGS ?=
# making sure the variables declared in the Makefile are exported to the excutables/scripts invoked
# on all targets
.EXPORT_ALL_VARIABLES:
$(BIN):
@mkdir -p $@
CATALOGCD = $(or ${CATALOGCD_BIN},${CATALOGCD_BIN},$(BIN)/catalog-cd)
$(BIN)/catalog-cd: $(BIN)
curl -fsL https://github.com/openshift-pipelines/catalog-cd/releases/download/v0.1.0/catalog-cd_0.1.0_linux_x86_64.tar.gz | tar xzf - -C $(BIN) catalog-cd
# renders the task resource file printing it out on the standard output, you can redirect the output
# of this target to a `kubectl apply -f -`, for istance
helm-template:
helm template $(ARGS) $(CHART_NAME) .
# renders the task templates and copies documentation into the ${RELEASE_DIR}
prepare-release:
mkdir -p $(RELEASE_DIR) || true
hack/release.sh $(RELEASE_DIR)
# runs "catalog-cd release" to create the release payload based on the Tekton resources
# prepared by the previous step
release: $(CATALOGCD) prepare-release
mkdir -p $(RELEASE_DIR) || true
pushd ${RELEASE_DIR} && \
$(CATALOGCD) release \
--output release \
--version $(CHART_VERSION) \
tasks/* \
; \
popd
# tags the repository with the RELEASE_VERSION and pushes to "origin"
git-tag-release-version:
if ! git rev-list "${RELEASE_VERSION}".. >/dev/null; then \
git tag "$(RELEASE_VERSION)" && \
git push origin --tags; \
fi
# rolls out the current Chart version as the repository release version, uploads the release
# payload prepared to GitHub (using gh)
github-release: git-tag-release-version release
gh release create $(RELEASE_VERSION) --generate-notes && \
gh release upload $(RELEASE_VERSION) $(RELEASE_DIR)/release/catalog.yaml && \
gh release upload $(RELEASE_VERSION) $(RELEASE_DIR)/release/resources.tar.gz
# renders and installs the task in the current namespace
install:
helm template $(CHART_NAME) . |kubectl $(ARGS) apply -f -
# renders and removes the task in the current namespace
remove:
helm template $(CHART_NAME) . |kubectl $(ARGS) delete -f -
# packages the helm-chart as a single tarball, using it's name and version to compose the file
helm-package:
rm -f $(CHART_NAME)-*.tgz || true
helm package $(ARGS) .
tar -ztvpf $(CHART_NAME)-$(CHART_VESION).tgz
# removes the package helm chart, and also the chart-releaser temporary directories
clean:
rm -rf $(CHART_NAME)-*.tgz > /dev/null 2>&1 || true
# run end-to-end tests against the current kuberentes context, it will required a cluster with tekton
# pipelines and other requirements installed, before start testing the target invokes the
# installation of the current project's task (using helm).
test-e2e: install
$(BATS_CORE) $(BATS_FLAGS) $(ARGS) $(E2E_TESTS)
# Run all the end-to-end tests against the current openshift context.
# It is used mainly by the CI and ideally shouldn't differ that much from test-e2e
.PHONY: prepare-e2e-openshift
prepare-e2e-openshift:
./hack/install-osp.sh $(OSP_VERSION)
.PHONY: test-e2e-openshift
test-e2e-openshift: prepare-e2e-openshift
test-e2e-openshift: test-e2e
.PHONY: test-e2e-tkn
test-e2e-tkn: prepare-e2e-openshift
test-e2e-tkn: test-e2e
.PHONY: test-e2e-opc
test-e2e-opc: prepare-e2e-openshift
test-e2e-opc: test-e2e
# act runs the github actions workflows, so by default only running the test workflow (integration
# and end-to-end) to avoid running the release workflow accidently
act: ARGS = --workflows=./.github/workflows/test.yaml
act:
act $(ARGS)