forked from buildpacks/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
177 lines (152 loc) · 5.12 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
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
175
176
177
# Retrieve latest pack version
PACK_VERSION?=
GITHUB_TOKEN?=
SERVE_PORT=1313
BASE_URL?=
ifndef BASE_URL
ifdef GITPOD_WORKSPACE_URL
BASE_URL=$(shell echo "$(GITPOD_WORKSPACE_URL)" | sed -r 's;^([^/]*)//(.*);\1//$(SERVE_PORT)-\2;')
endif
endif
GITHUB_API_OPTS:=
ifdef GITHUB_TOKEN
GITHUB_API_OPTS+=-H "Authorization: token $(GITHUB_TOKEN)"
endif
ifndef PACK_VERSION
PACK_VERSION:=$(shell curl -sSL $(GITHUB_API_OPTS) https://api.github.com/repos/buildpacks/pack/releases/latest | jq -r '.tag_name' | sed -e 's/^v//')
endif
.PHONY: default
default: serve
.PHONY: clean
clean:
rm -rf ./public ./resources $(TOOLS_BIN)
TOOLS_BIN:=tools/bin
$(TOOLS_BIN):
mkdir $(TOOLS_BIN)
# adapted from https://stackoverflow.com/a/12099167/552902
HUGO_OS:=Linux
HUGO_ARCH:=32bit
HUGO_EXT:=tar.gz
ifeq ($(OS),Windows_NT)
HUGO_OS:=Windows
HUGO_EXT:=zip
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
HUGO_ARCH:=64bit
endif
endif
ifeq ($(shell uname -s),Darwin)
HUGO_OS:=darwin
HUGO_ARCH:=universal
endif
ifeq ($(shell uname -s),Linux)
UNAME_M:=$(shell uname -m)
ifneq ($(filter %64,$(UNAME_M)),)
HUGO_ARCH:=64bit
endif
ifneq ($(filter arm%,$(UNAME_M)),)
HUGO_ARCH:=ARM64
endif
endif
HUGO_RELEASES_CACHE:=tools/bin/hugo-releases
$(HUGO_RELEASES_CACHE): | $(TOOLS_BIN)
curl -sSL $(GITHUB_API_OPTS) https://api.github.com/repos/gohugoio/hugo/releases/latest > $(HUGO_RELEASES_CACHE)
HUGO_BIN:=tools/bin/hugo
$(HUGO_BIN): $(HUGO_RELEASES_CACHE)
$(HUGO_BIN):
@echo "> Installing hugo for $(HUGO_OS) ($(HUGO_ARCH))..."
curl -sSL -o $(HUGO_BIN).$(HUGO_EXT) $(shell cat $(HUGO_RELEASES_CACHE) | jq -r '[.assets[] | select (.name | test("extended.*$(HUGO_OS)-$(HUGO_ARCH).*$(HUGO_EXT)"))][0] | .browser_download_url')
ifeq ($(HUGO_EXT), zip)
unzip $(HUGO_BIN).$(HUGO_EXT) -d $(TOOLS_BIN)
else
tar mxfz $(HUGO_BIN).$(HUGO_EXT) -C $(TOOLS_BIN) hugo
endif
.PHONY: upgrade-pack
upgrade-pack: pack-version
@if [ ! $(`which pack` && `pack --version | cut -d '+' -f 1` != "$(PACK_VERSION)") ]; then \
echo "> Upgrading pack library version $(PACK_VERSION)"; \
cd tools; go get github.com/buildpacks/pack@v$(PACK_VERSION); \
fi
.PHONY: install-pack-cli
install-pack-cli: export PACK_BIN:=$(shell which pack)
install-pack-cli: upgrade-pack
@echo "> Installing pack bin..."
@if [ -z "$(PACK_BIN)" ]; then \
cd tools; go install github.com/buildpacks/pack/cmd/pack; \
else \
echo "pack already installed at $(PACK_BIN)"; \
fi
@echo "pack version: " `pack --version`
.PHONY: check-pack-cli-version
check-pack-cli-version:
@echo "> Installed pack version: " `pack --version | cut -d '+' -f 1`
@if [ `pack --version | cut -d '+' -f 1` != "$(PACK_VERSION)" ]; then \
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; \
echo "WARNING: Expected pack version: $(PACK_VERSION)"; \
echo "You may need to upgrade your version of pack! "; \
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; \
fi
.PHONY: install-ugo
install-ugo:
@echo "> Installing ugo..."
cd tools; go install github.com/jromero/ugo/cmd/[email protected]
.PHONY: pack-docs-update
pack-docs-update: upgrade-pack
@echo "> Updating Pack CLI Documentation"
@echo "> SHA of contents (before update):" `find ./content/docs/for-platform-operators/how-to/integrate-ci/pack -type f -print0 | xargs -0 sha1sum | sha1sum | cut -d' ' -f1`
cd tools; go run -mod=mod get_pack_commands.go
@echo "> SHA of contents (after update):" `find ./content/docs/for-platform-operators/how-to/integrate-ci/pack -type f -print0 | xargs -0 sha1sum | sha1sum | cut -d' ' -f1`
.PHONY: pack-version
pack-version: export PACK_VERSION:=$(PACK_VERSION)
pack-version:
@echo "> Ensuring pack version is set..."
@test ! -z '${PACK_VERSION}'
@test '${PACK_VERSION}' != 'null'
@echo "PACK_VERSION="${PACK_VERSION}""
.PHONY: serve
serve: export PACK_VERSION:=$(PACK_VERSION)
serve: $(HUGO_BIN) pack-version pack-docs-update
@echo "> Serving..."
ifeq ($(BASE_URL),)
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT)
else
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT) --baseURL=$(BASE_URL) --appendPort=false
endif
.PHONY: build
build: export PACK_VERSION:=$(PACK_VERSION)
build: $(HUGO_BIN) pack-version pack-docs-update
@echo "> Building..."
$(HUGO_BIN)
.PHONY: test
test: install-pack-cli check-pack-cli-version install-ugo
@echo "> Testing..."
ugo run -v -r -p ./content/docs/
.PHONY: htmltest-install
htmltest-install:
@if ! test -f ./bin/htmltest; then \
echo "> Installing htmltest..."; \
curl https://htmltest.wjdp.uk | bash; \
fi;
.PHONY: htmltest-run
htmltest-run: htmltest-install build
@echo "> Checking links..."
./bin/htmltest ./public -l 3 -s 2>&1 > /dev/null || true
.PHONY: check-links
check-links: htmltest-run
check-links: ERRORS=$(shell cat ./tmp/.htmltest/htmltest.log | grep -i "does not exist")
check-links:
@if [ ! -z "$(ERRORS)" ]; then \
echo "ERROR: found broken links:"; \
cat ./tmp/.htmltest/htmltest.log | grep -i "does not exist"; \
exit 1; \
else \
echo "No broken links found."; \
fi;
.PHONY: tools-tidy
tools-tidy:
cd tools; go mod tidy
.PHONY: prepare-for-pr
prepare-for-pr: check-links test tools-tidy
@echo "========"
@echo "It looks good! :)"
@echo "Make sure to commit all changes!"
@echo "========"