@@ -4,54 +4,70 @@ GITHUB_TOKEN?=
4
4
PACK_BIN? =$(shell which pack)
5
5
SERVE_PORT =1313
6
6
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)
11
7
12
8
ifndef BASE_URL
13
9
ifdef GITPOD_WORKSPACE_URL
14
10
BASE_URL =$(shell echo "$(GITPOD_WORKSPACE_URL ) " | sed -r 's;^([^/]* ) //(.*);\1//$(SERVE_PORT ) -\2;')
15
11
endif
16
12
endif
17
13
18
- ifndef PACK_VERSION
14
+ GITHUB_API_OPTS: =
19
15
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 ) "
23
17
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//')
24
21
endif
25
22
26
23
.PHONY : default
27
24
default : serve
28
25
29
26
.PHONY : clean
30
27
clean :
31
- rm -rf ./public ./resources
32
-
33
- .PHONY : install-hugo
34
- install-hugo :
28
+ rm -rf ./public ./resources $(TOOLS_BIN )
35
29
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 )
38
33
34
+ # adapted from https://stackoverflow.com/a/12099167/552902
35
+ HUGO_OS: =Linux
36
+ HUGO_ARCH: =32bit
37
+ HUGO_EXT: =tar.gz
39
38
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
42
43
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
47
44
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
50
55
endif
51
56
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
55
71
56
72
.PHONY : upgrade-pack
57
73
upgrade-pack : pack-version
@@ -75,9 +91,9 @@ install-ugo:
75
91
.PHONY : pack-docs-update
76
92
pack-docs-update : upgrade-pack
77
93
@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`
79
95
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`
81
97
82
98
.PHONY : pack-version
83
99
pack-version : export PACK_VERSION:=$(PACK_VERSION )
@@ -89,17 +105,17 @@ pack-version:
89
105
90
106
.PHONY : serve
91
107
serve : export PACK_VERSION:=$(PACK_VERSION )
92
- serve : install-hugo pack-version pack-docs-update
108
+ serve : $( HUGO_BIN ) pack-version pack-docs-update
93
109
@echo " > Serving..."
94
110
ifeq ($(BASE_URL ) ,)
95
111
$(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT)
96
112
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
98
114
endif
99
115
100
116
.PHONY : build
101
117
build : export PACK_VERSION:=$(PACK_VERSION )
102
- build : install-hugo pack-version pack-docs-update
118
+ build : $( HUGO_BIN ) pack-version pack-docs-update
103
119
@echo " > Building..."
104
120
$(HUGO_BIN )
105
121
0 commit comments