-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.jenkins
174 lines (148 loc) · 6.2 KB
/
Makefile.jenkins
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# This Makefile is a support file to automatize the kiali release process. It is
# used in a Jenkins Pipeline.
# It can also be used to run the release process without Jenkins. Read the
# RELEASING.adoc file for more information.
RELEASE_TYPE ?= 'minor'
UI_GITHUB_URI ?= [email protected]:kiali/kiali-ui.git
UI_PULL_URI ?= https://api.github.com/repos/kiali/kiali-ui/pulls
UI_MAIN_BRANCH ?= master
KIALI_BOT_USER ?= kiali-bot
UI_FORK_URI ?= $(shell git config --get remote.origin.url)
UI_VERSION = $(shell jq -r '.version' package.json)
UI_VERSION_BRANCH ?= $(shell jq -r '.version' package.json | sed 's/\.[[:digit:]]\+$$//')
# BUILD_TAG is an environment variable from Jenkins
BUILD_TAG ?= prepare-next-version
BUMP_BRANCH_ID ?= $(BUILD_TAG)
NPM_DRY_RUN ?= n
# For minors and majors, the version currently stored in package.json
# is the version to publish. All other kind of releases require
# to modify the version string before building and publishing.
ifneq ($(findstring $(RELEASE_TYPE),major minor),$(RELEASE_TYPE))
UPDATE_VERSION_BEFORE_BUILD = y
endif
# Block edge releases on github
ifneq ($(RELEASE_TYPE),edge)
PUSH_GITHUB_TAG = y
endif
# Block edge releases on npm
ifneq ($(RELEASE_TYPE),edge)
PUSH_TO_NPM = y
endif
# For "minor" releases, the "master" branch must be
# updated to be prepared for the next minor release.
ifeq ($(RELEASE_TYPE),minor)
UPDATE_VERSION_POST_BUILD = y
endif
# For "minor" releases, a vX.Y branch must be
# created, in prevention of a possible patch release. For
# "patch" releases, the (assumed) already existent version
# branch should be updated in preparation/prevention for
# the next patch release. Other release types should not
# create/update the version branch.
ifneq ($(findstring $(RELEASE_TYPE),minor patch),$(RELEASE_TYPE))
OMIT_VERSION_BRANCH ?= y
endif
# Determine if an end-of-week snapshot is being released and
# set the "bumped version" accordingly.
ifeq ($(findstring snapshot, $(RELEASE_TYPE)),snapshot)
UI_BUMPED_VERSION ?= $(UI_VERSION)-$(RELEASE_TYPE)
else ifeq ($(findstring $(RELEASE_TYPE),edge),$(RELEASE_TYPE))
UI_BUMPED_VERSION ?= $(UI_VERSION)-$(RELEASE_TYPE)
else
UI_BUMPED_VERSION ?= $(shell semver bump $(RELEASE_TYPE) $(UI_VERSION))
endif
# Start definition of the recipes
.PHONY: all ui-build ui-test ui-npm-publish
.PHONY: ui-push-version-tag ui-prepare-next-version release
.PHONY: ui-fix-version ui-check-clean-workspace
.PHONY: ui-prepare-next-patch-version ui-prepare-master-next-version
all:
$(error You must explicitly specify a target)
ui-check-clean-workspace:
@output=$$(git status --porcelain) && [ -z "$$output" ] || \
(echo 'Your working path must be clean. Please, commit your changes or reset your working path.' && exit 1)
ui-fix-version:
ifeq ($(UPDATE_VERSION_BEFORE_BUILD),y)
jq -r '.version |= "$(UI_BUMPED_VERSION)"' package.json > package.json.typed
mv package.json.typed package.json
@echo "Version string updated before building (from -> to): $(UI_VERSION) -> $(UI_BUMPED_VERSION)"
else
@echo "Version string NOT updated. The version to publish will be: $(UI_VERSION)"
endif
ui-build:
rm -fr build/*
CI=true yarn --frozen-lockfile --non-interactive
CI=true yarn build:dev
echo '$(UI_VERSION)' > build/version.txt
ui-test:
CI=true yarn test --maxWorkers=4
ui-npm-publish:
ifeq ($(PUSH_TO_NPM), y)
ifdef NPM_TOKEN
@echo '//registry.npmjs.org/:_authToken=$(NPM_TOKEN)' > .npmrc
endif
ifeq ($(NPM_DRY_RUN), y)
npm publish --dry-run
else
npm publish
endif
ifdef NPM_TOKEN
rm .npmrc
endif
endif
ui-push-version-tag:
ifeq ($(PUSH_GITHUB_TAG),y)
ifeq ($(UPDATE_VERSION_BEFORE_BUILD),y)
# If the version string was updated before publishing, the updated
# version string must be present in the git tag.
git add package.json
git commit --no-verify -m "Release $(UI_VERSION)"
endif
git push $(UI_GITHUB_URI) $$(git rev-parse HEAD):refs/tags/v$(UI_VERSION)
endif
ui-prepare-next-patch-version:
ifndef OMIT_VERSION_BRANCH
# First, try to push directly to the vX.Y branch
git push $(UI_GITHUB_URI) $$(git rev-parse HEAD):refs/heads/v$(UI_VERSION_BRANCH) || touch pr_needed.txt
# If push to vX.Y branch fails, create a PR
[ ! -f pr_needed.txt ] || git push $(UI_FORK_URI) $$(git rev-parse HEAD):refs/heads/$(BUMP_BRANCH_ID)
ifdef GH_TOKEN
@[ ! -f pr_needed.txt ] || echo "Creating PR to prepare for next version..."
@[ ! -f pr_needed.txt ] || curl -s -H "Authorization: token $(GH_TOKEN)" \
-H "Content-Type: application/json" \
-d '{"title": "Prepare for next version", "body": "I could not update v$(UI_VERSION_BRANCH) branch. Please, merge.", "head": "$(KIALI_BOT_USER):$(BUMP_BRANCH_ID)", "base": "v$(UI_VERSION_BRANCH)"}' \
-X POST $(UI_PULL_URI)
endif
# Clean-up
rm -f pr_needed.txt
else
@echo "Creation or update of the version branch $(UI_VERSION_BRANCH) is omitted."
endif
ui-prepare-master-next-version:
ifeq ($(UPDATE_VERSION_POST_BUILD),y)
# Update version string
jq -r '.version |= "$(UI_BUMPED_VERSION)"' package.json > package.json.bumped
mv package.json.bumped package.json
@echo "Post-build version string update (from -> to): $(UI_VERSION) -> $(UI_BUMPED_VERSION)"
# Commit changes to git
git add package.json
git commit --no-verify -m "Prepare for next version: $(UI_BUMPED_VERSION)"
# First, try to push directly to master
git push $(UI_GITHUB_URI) $$(git rev-parse HEAD):refs/heads/$(UI_MAIN_BRANCH) || touch pr_needed.txt
# If push to master fails, create a PR
[ ! -f pr_needed.txt ] || git push $(UI_FORK_URI) $$(git rev-parse HEAD):refs/heads/$(BUMP_BRANCH_ID)
ifdef GH_TOKEN
@[ ! -f pr_needed.txt ] || echo "Creating PR to prepare for next version..."
@[ ! -f pr_needed.txt ] || curl -s -H "Authorization: token $(GH_TOKEN)" \
-H "Content-Type: application/json" \
-d '{"title": "Prepare for next version", "body": "I could not update $(UI_MAIN_BRANCH) branch. Please, merge.", "head": "$(KIALI_BOT_USER):$(BUMP_BRANCH_ID)", "base": "$(UI_MAIN_BRANCH)"}' \
-X POST $(UI_PULL_URI)
endif
# Clean-up
rm -f pr_needed.txt
else # if UPDATE_VERSION_POST_BUILD
@echo "Skipping preparing repository for next version..."
endif
ui-prepare-next-version: ui-prepare-next-patch-version ui-prepare-master-next-version
release: ui-check-clean-workspace ui-fix-version ui-build ui-test
release: ui-npm-publish ui-push-version-tag ui-prepare-next-version