Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
199 lines (169 loc) · 6.18 KB
/
Copy pathMakefile
File metadata and controls
199 lines (169 loc) · 6.18 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# 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)
HUGO_OS:=Linux
HUGO_ARCH:=64bit
HUGO_EXT:=tar.gz
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("^hugo_[0-9.]+_$(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
# Hugo compiles the site's SCSS with Dart Sass, which it runs as `sass` from the PATH
SASS_OS:=linux
SASS_ARCH:=x64
ifeq ($(shell uname -s),Darwin)
SASS_OS:=macos
endif
ifneq ($(filter arm64 aarch64,$(shell uname -m)),)
SASS_ARCH:=arm64
endif
SASS_RELEASES_CACHE:=tools/bin/dart-sass-releases
$(SASS_RELEASES_CACHE): | $(TOOLS_BIN)
curl -sSL $(GITHUB_API_OPTS) https://api.github.com/repos/sass/dart-sass/releases/latest > $(SASS_RELEASES_CACHE)
SASS_DIR:=tools/bin/dart-sass
SASS_BIN:=$(SASS_DIR)/sass
$(SASS_BIN): $(SASS_RELEASES_CACHE)
@echo "> Installing Dart Sass for $(SASS_OS) ($(SASS_ARCH))..."
curl -sSL -o $(SASS_DIR).tar.gz $(shell cat $(SASS_RELEASES_CACHE) | jq -r '[.assets[] | select (.name | test("-$(SASS_OS)-$(SASS_ARCH)[.]tar[.]gz$$"))][0] | .browser_download_url')
tar mxfz $(SASS_DIR).tar.gz -C $(TOOLS_BIN)
.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; \
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/ugo@latest
.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..."
@if [ -z '${PACK_VERSION}' ] || [ '${PACK_VERSION}' = 'null' ]; then \
echo "ERROR: could not determine the latest pack version from the GitHub API."; \
echo " The request may have been rate limited. Set GITHUB_TOKEN, or set PACK_VERSION to skip the lookup."; \
exit 1; \
fi
@echo "PACK_VERSION="${PACK_VERSION}""
.PHONY: serve
serve: export PACK_VERSION:=$(PACK_VERSION)
serve: export PATH:=$(CURDIR)/$(SASS_DIR):$(PATH)
serve: $(HUGO_BIN) $(SASS_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: export PATH:=$(CURDIR)/$(SASS_DIR):$(PATH)
build: $(HUGO_BIN) $(SASS_BIN) pack-version pack-docs-update
@echo "> Building..."
$(HUGO_BIN)
# Github Workflows ensures `node` is installed.
npx pagefind --site ./public
.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 "========"