@@ -11,25 +11,63 @@ BASE_URL=$(shell echo "$(GITPOD_WORKSPACE_URL)" | sed -r 's;^([^/]*)//(.*);\1//$
11
11
endif
12
12
endif
13
13
14
- ifndef PACK_VERSION
14
+ GITHUB_API_OPTS: =
15
15
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 ) "
19
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//')
20
21
endif
21
22
22
23
.PHONY : default
23
24
default : serve
24
25
25
26
.PHONY : clean
26
27
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
28
56
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
33
71
34
72
.PHONY : upgrade-pack
35
73
upgrade-pack : pack-version
@@ -53,9 +91,9 @@ install-ugo:
53
91
.PHONY : pack-docs-update
54
92
pack-docs-update : upgrade-pack
55
93
@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`
57
95
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`
59
97
60
98
.PHONY : pack-version
61
99
pack-version : export PACK_VERSION:=$(PACK_VERSION )
@@ -67,19 +105,19 @@ pack-version:
67
105
68
106
.PHONY : serve
69
107
serve : export PACK_VERSION:=$(PACK_VERSION )
70
- serve : install-hugo pack-version pack-docs-update
108
+ serve : $( HUGO_BIN ) pack-version pack-docs-update
71
109
@echo " > Serving..."
72
110
ifeq ($(BASE_URL ) ,)
73
- hugo server --disableFastRender --port=$(SERVE_PORT)
111
+ $(HUGO_BIN) server --disableFastRender --port=$(SERVE_PORT)
74
112
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
76
114
endif
77
115
78
116
.PHONY : build
79
117
build : export PACK_VERSION:=$(PACK_VERSION )
80
- build : install-hugo pack-version pack-docs-update
118
+ build : $( HUGO_BIN ) pack-version pack-docs-update
81
119
@echo " > Building..."
82
- hugo
120
+ $( HUGO_BIN )
83
121
84
122
.PHONY : test
85
123
test : install-pack-cli install-ugo
0 commit comments