Skip to content

Commit 7a47a9e

Browse files
committed
Polish PR #407
Signed-off-by: Javier Romero <[email protected]>
1 parent 5e4972c commit 7a47a9e

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

.editorconfig

+5-1
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

Makefile

+46-30
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,70 @@ GITHUB_TOKEN?=
44
PACK_BIN?=$(shell which pack)
55
SERVE_PORT=1313
66
BASE_URL?=
7-
HUGO_BIN=./tools/bin/hugo
8-
9-
#retreive latest hugo version
10-
_latestver:=$(shell curl --silent "https://api.github.com/repos/gohugoio/hugo/tags" | jq -r '.[0].name' | tr -d v)
117

128
ifndef BASE_URL
139
ifdef GITPOD_WORKSPACE_URL
1410
BASE_URL=$(shell echo "$(GITPOD_WORKSPACE_URL)" | sed -r 's;^([^/]*)//(.*);\1//$(SERVE_PORT)-\2;')
1511
endif
1612
endif
1713

18-
ifndef PACK_VERSION
14+
GITHUB_API_OPTS:=
1915
ifdef GITHUB_TOKEN
20-
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//')
21-
else
22-
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)"
2317
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//')
2421
endif
2522

2623
.PHONY: default
2724
default: serve
2825

2926
.PHONY: clean
3027
clean:
31-
rm -rf ./public ./resources
32-
33-
.PHONY: install-hugo
34-
install-hugo:
28+
rm -rf ./public ./resources $(TOOLS_BIN)
3529

36-
@echo "> Installing hugo..."
37-
@echo "This may take a while depending on your connection."
30+
TOOLS_BIN:=tools/bin
31+
$(TOOLS_BIN):
32+
mkdir $(TOOLS_BIN)
3833

34+
# adapted from https://stackoverflow.com/a/12099167/552902
35+
HUGO_OS:=Linux
36+
HUGO_ARCH:=32bit
37+
HUGO_EXT:=tar.gz
3938
ifeq ($(OS),Windows_NT)
40-
@echo $(shell uname -s) ;
41-
cd tools; mkdir bin; cd bin; curl -s -L -O $(shell curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.assets[30].browser_download_url')
39+
HUGO_OS:=Windows
40+
HUGO_EXT:=zip
41+
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
42+
HUGO_ARCH:=64bit
4243
endif
43-
44-
ifeq ($(shell uname -s),Darwin)
45-
@echo $(shell uname -s)
46-
cd tools; mkdir bin; cd bin; curl -s -L -O $(shell curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.assets[28].browser_download_url'); tar xvfz hugo_extended_${_latestver}_macOS-64bit.tar.gz
4744
else
48-
@echo $(shell uname -s)
49-
cd tools; mkdir bin; cd bin; curl -s -L -O $(shell curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.assets[27].browser_download_url'); tar xvfz hugo_extended_${_latestver}_Linux-64bit.tar.gz
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
5055
endif
5156

52-
53-
54-
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
5571

5672
.PHONY: upgrade-pack
5773
upgrade-pack: pack-version
@@ -75,9 +91,9 @@ install-ugo:
7591
.PHONY: pack-docs-update
7692
pack-docs-update: upgrade-pack
7793
@echo "> Updating Pack CLI Documentation"
78-
@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`
7995
cd tools; go run -mod=mod get_pack_commands.go
80-
@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`
8197

8298
.PHONY: pack-version
8399
pack-version: export PACK_VERSION:=$(PACK_VERSION)
@@ -89,17 +105,17 @@ pack-version:
89105

90106
.PHONY: serve
91107
serve: export PACK_VERSION:=$(PACK_VERSION)
92-
serve: install-hugo pack-version pack-docs-update
108+
serve: $(HUGO_BIN) pack-version pack-docs-update
93109
@echo "> Serving..."
94110
ifeq ($(BASE_URL),)
95111
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT)
96112
else
97-
hugo server --disableFastRender --port=$(SERVE_PORT) --baseURL=$(BASE_URL) --appendPort=false
113+
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT) --baseURL=$(BASE_URL) --appendPort=false
98114
endif
99115

100116
.PHONY: build
101117
build: export PACK_VERSION:=$(PACK_VERSION)
102-
build: install-hugo pack-version pack-docs-update
118+
build: $(HUGO_BIN) pack-version pack-docs-update
103119
@echo "> Building..."
104120
$(HUGO_BIN)
105121

0 commit comments

Comments
 (0)