forked from openshift-pipelines/task-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (103 loc) · 4.21 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
128
129
130
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)
CATALOGCD_VERSION = v0.1.0
# 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
INTEGRATION_TESTS ?= ./test/integration/*.bats
E2E_TESTS ?= ./test/e2e/*.bats
# 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:
# uses helm to render the resource templates to the stdout
define render-template
@helm template $(ARGS) $(CHART_NAME) .
endef
$(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.3.0/catalog-cd_0.3.0_linux_x86_64.tar.gz | tar xzf - -C $(BIN) catalog-cd
# renders the task resource file printing it out on the standard output
helm-template:
$(call render-template)
# renders and installs the resources (task)
install:
$(call render-template) |kubectl $(ARGS) apply -f -
# renders and remove the resources (task)
remove:
$(call render-template) |kubectl $(ARGS) delete -f -
# pepare a release
.PHONY: prepare-release
prepare-release:
mkdir -p $(RELEASE_DIR) || true
hack/release.sh $(RELEASE_DIR)
.PHONY: release
release: ${CATALOGCD} prepare-release
pushd ${RELEASE_DIR} && \
$(CATALOGCD) release \
--output release \
--version $(CHART_VERSION) \
tasks/* \
stepactions/* \
; \
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
# github-release
.PHONY: github-release
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
# packages the helm-chart as a single tarball, using it's name and version to compose the file
helm-package: clean
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 the integration tests, does not require a kubernetes instance
test-integration:
$(BATS_CORE) $(BATS_FLAGS) $(ARGS) $(INTEGRATION_TESTS)
# 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)
.PHONY: test-e2e-git-clone
test-e2e-git-clone: E2E_TESTS=./test/e2e/*clone.bats
test-e2e-git-clone: test-e2e
.PHONY: test-e2e-git-cli
test-e2e-git-cli: E2E_TESTS=./test/e2e/*cli.bats
test-e2e-git-cli: test-e2e
.PHONY: test-e2e-git-clone-stepaction
test-e2e-git-clone-stepaction: E2E_TESTS=./test/e2e/e2e-stepaction*.bats
test-e2e-git-clone-stepaction: test-e2e
# 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
# 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)