Skip to content

Commit 5610096

Browse files
authored
Merge pull request cds-hooks#425 from buildpacks/polish/407
Polish cds-hooks#407
2 parents a71e557 + 68ff102 commit 5610096

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[*]
22
indent_style = space
3-
indent_size = 2
3+
indent_size = 2
4+
5+
[Makefile]
6+
indent_style = tab
7+
indent_size = 4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ content/docs/tools/pack/cli/pack*
2222
# Tools
2323
/bin
2424
/tmp
25+
26+
/tools/bin

Makefile

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,63 @@ BASE_URL=$(shell echo "$(GITPOD_WORKSPACE_URL)" | sed -r 's;^([^/]*)//(.*);\1//$
1111
endif
1212
endif
1313

14-
ifndef PACK_VERSION
14+
GITHUB_API_OPTS:=
1515
ifdef GITHUB_TOKEN
16-
PACK_VERSION:=$(shell curl -s -H "Authorization: token $(GITHUB_TOKEN)" https://api.github.com/repos/buildpacks/pack/releases/latest | jq -r '.tag_name' | sed -e 's/^v//')
17-
else
18-
PACK_VERSION:=$(shell curl -s https://api.github.com/repos/buildpacks/pack/releases/latest | jq -r '.tag_name' | sed -e 's/^v//')
16+
GITHUB_API_OPTS+=-H "Authorization: token $(GITHUB_TOKEN)"
1917
endif
18+
19+
ifndef PACK_VERSION
20+
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//')
2021
endif
2122

2223
.PHONY: default
2324
default: serve
2425

2526
.PHONY: clean
2627
clean:
27-
rm -rf ./public ./resources
28+
rm -rf ./public ./resources $(TOOLS_BIN)
29+
30+
TOOLS_BIN:=tools/bin
31+
$(TOOLS_BIN):
32+
mkdir $(TOOLS_BIN)
33+
34+
# adapted from https://stackoverflow.com/a/12099167/552902
35+
HUGO_OS:=Linux
36+
HUGO_ARCH:=32bit
37+
HUGO_EXT:=tar.gz
38+
ifeq ($(OS),Windows_NT)
39+
HUGO_OS:=Windows
40+
HUGO_EXT:=zip
41+
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
42+
HUGO_ARCH:=64bit
43+
endif
44+
else
45+
ifeq ($(shell uname -s),Darwin)
46+
HUGO_OS:=macOS
47+
endif
48+
UNAME_P:=$(shell uname -p)
49+
ifneq ($(filter %64,$(UNAME_P)),)
50+
HUGO_ARCH:=64bit
51+
endif
52+
ifneq ($(filter arm%,$(UNAME_P)),)
53+
HUGO_ARCH:=ARM64
54+
endif
55+
endif
2856

29-
.PHONY: install-hugo
30-
install-hugo:
31-
@echo "> Installing hugo..."
32-
cd tools; go install -mod=mod --tags extended github.com/gohugoio/hugo
57+
HUGO_RELEASES_CACHE:=tools/bin/hugo-releases
58+
$(HUGO_RELEASES_CACHE): | $(TOOLS_BIN)
59+
curl -sSL $(GITHUB_API_OPTS) https://api.github.com/repos/gohugoio/hugo/releases/latest > $(HUGO_RELEASES_CACHE)
60+
61+
HUGO_BIN:=tools/bin/hugo
62+
$(HUGO_BIN): $(HUGO_RELEASES_CACHE)
63+
$(HUGO_BIN):
64+
@echo "> Installing hugo for $(HUGO_OS) ($(HUGO_ARCH))..."
65+
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')
66+
ifeq ($(HUGO_EXT), zip)
67+
unzip $(HUGO_BIN).$(HUGO_EXT) -d $(TOOLS_BIN)
68+
else
69+
tar mxfz $(HUGO_BIN).$(HUGO_EXT) -C $(TOOLS_BIN) hugo
70+
endif
3371

3472
.PHONY: upgrade-pack
3573
upgrade-pack: pack-version
@@ -53,9 +91,9 @@ install-ugo:
5391
.PHONY: pack-docs-update
5492
pack-docs-update: upgrade-pack
5593
@echo "> Updating Pack CLI Documentation"
56-
@echo "> SHA of contents (before update):" `find ./content/docs/tools/pack -type f -print0 | xargs -0 sha1sum | sha1sum | cut -d' ' -f1`
94+
@echo "> SHA of contents (before update):" `find ./content/docs/tools/pack -type f -print0 | xargs -0 sha1sum | sha1sum | cut -d' ' -f1`
5795
cd tools; go run -mod=mod get_pack_commands.go
58-
@echo "> SHA of contents (after update):" `find ./content/docs/tools/pack -type f -print0 | xargs -0 sha1sum | sha1sum | cut -d' ' -f1`
96+
@echo "> SHA of contents (after update):" `find ./content/docs/tools/pack -type f -print0 | xargs -0 sha1sum | sha1sum | cut -d' ' -f1`
5997

6098
.PHONY: pack-version
6199
pack-version: export PACK_VERSION:=$(PACK_VERSION)
@@ -67,19 +105,19 @@ pack-version:
67105

68106
.PHONY: serve
69107
serve: export PACK_VERSION:=$(PACK_VERSION)
70-
serve: install-hugo pack-version pack-docs-update
108+
serve: $(HUGO_BIN) pack-version pack-docs-update
71109
@echo "> Serving..."
72110
ifeq ($(BASE_URL),)
73-
hugo server --disableFastRender --port=$(SERVE_PORT)
111+
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT)
74112
else
75-
hugo server --disableFastRender --port=$(SERVE_PORT) --baseURL=$(BASE_URL) --appendPort=false
113+
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT) --baseURL=$(BASE_URL) --appendPort=false
76114
endif
77115

78116
.PHONY: build
79117
build: export PACK_VERSION:=$(PACK_VERSION)
80-
build: install-hugo pack-version pack-docs-update
118+
build: $(HUGO_BIN) pack-version pack-docs-update
81119
@echo "> Building..."
82-
hugo
120+
$(HUGO_BIN)
83121

84122
.PHONY: test
85123
test: install-pack-cli install-ugo

0 commit comments

Comments
 (0)