From 1f3575ebf6fb0f6771d910e2d5d5a7a6d13af3fd Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Thu, 17 Oct 2024 10:12:16 +0200 Subject: [PATCH] feat: pin Hugo version - Added a new target `download-hugo` in the Makefile to download Hugo. - Updated the `dev-docs` target to use the downloaded Hugo binary. - Created a new script `hack/download-hugo.sh` to handle the download. - Modified the documentation to reflect the changes in the development process. Signed-off-by: Chmouel Boudjnah --- .tekton/doc.yaml | 15 ++++++---- Makefile | 16 ++++++++--- docs/content/dev/_index.md | 17 ++++++++---- hack/download-hugo.sh | 56 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 15 deletions(-) create mode 100755 hack/download-hugo.sh diff --git a/.tekton/doc.yaml b/.tekton/doc.yaml index 352cbe3f8..8bbcf867f 100644 --- a/.tekton/doc.yaml +++ b/.tekton/doc.yaml @@ -40,7 +40,7 @@ spec: - name: source steps: - name: hugo-gen - image: registry.access.redhat.com/ubi9/python-312 + image: golang:1.22 workingDir: $(workspaces.source.path) env: - name: UPLOADER_PUBLIC_URL @@ -49,13 +49,18 @@ spec: name: "uploader-upload-credentials" key: "public_url" script: | - version=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest|python -c 'import sys, json;dico=json.load(sys.stdin);print(dico["tag_name"])') - curl --fail-early -sL https://github.com/gohugoio/hugo/releases/download/${version}/hugo_extended_${version/v/}_linux-arm64.tar.gz -o-|tar -x -z -v -f- hugo + #!/usr/bin/env bash + set -xeuo pipefail git config --global --add safe.directory $(workspaces.source.path) - cd docs + make download-hugo + hugobin=$(git rev-parse --show-toplevel)/tmp/hugo + [[ -x ${hugobin} ]] || { + echo "Hugo was not downloaded properly" && exit 1 + } + cd $(git rev-parse --show-toplevel)/docs sed -i '1acanonifyURLs = true' config.toml url="${UPLOADER_PUBLIC_URL}/docs/{{ pull_request_number }}" - ../hugo --gc --minify -d {{ pull_request_number }} -b ${url} + ${hugobin} --gc --minify -d {{ pull_request_number }} -b ${url} echo "Preview URL: ${url}" - name: upload-to-static-server # it has curl and we already pulled it diff --git a/Makefile b/Makefile index 71b233f8c..21f000122 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ TARGET_NAMESPACE=pipelines-as-code +HUGO_VERSION=0.96.0 GOLANGCI_LINT=golangci-lint GOFUMPT=gofumpt TKN_BINARY_NAME := tkn @@ -9,13 +10,17 @@ GO = go TIMEOUT_UNIT = 20m TIMEOUT_E2E = 45m GO_TEST_FLAGS += -SHELL := bash +SHELL := bash +TOPDIR := $(shell git rev-parse --show-toplevel) +TMPDIR := $(TOPDIR)/tmp +HUGO_BIN := $(TMPDIR)/hugo PY_FILES := $(shell find . -type f -regex ".*\.py" -print) SH_FILES := $(shell find hack/ -type f -regex ".*\.sh" -print) YAML_FILES := $(shell find . -not -regex '^./vendor/.*' -type f -regex ".*y[a]ml" -print) MD_FILES := $(shell find . -type f -regex ".*md" -not -regex '^./vendor/.*' -not -regex '^./.vale/.*' -not -regex "^./docs/themes/.*" -not -regex "^./.git/.*" -print) + ifeq ($(PAC_VERSION),) PAC_VERSION="$(shell git describe --tags --exact-match 2>/dev/null || echo nightly-`date +'%Y%m%d'`-`git rev-parse --short HEAD`)" endif @@ -166,8 +171,8 @@ dev-redeploy: ## redeploy pac in local setup ./hack/dev/kind/install.sh -p .PHONY: dev-docs -dev-docs: ## preview live your docs with hugo - @hugo server -s docs/ & +dev-docs: download-hugo ## preview live your docs with hugo + @$(HUGO_BIN) server -s docs/ & if type -p xdg-open 2>/dev/null >/dev/null; then \ xdg-open http://localhost:1313; \ elif type -p open 2>/dev/null >/dev/null; then \ @@ -188,7 +193,10 @@ update-golden: ## run unit tests (updating golden files) .PHONY: generated generated: update-golden fumpt ## generate all files that needs to be generated - +.PHONY: download-hugo +download-hugo: + @./hack/download-hugo.sh $(HUGO_VERSION) $(TMPDIR) + .PHONY: clean clean: ## clean build artifacts rm -fR bin diff --git a/docs/content/dev/_index.md b/docs/content/dev/_index.md index 15d668405..3354b9379 100644 --- a/docs/content/dev/_index.md +++ b/docs/content/dev/_index.md @@ -224,21 +224,23 @@ make pre-commit ## Developing the Documentation -Documentation is important to us, most of the time new features or change of -behaviour needs to include documentation part of the Pull Request. +Documentation is important to us. Most of the time, new features or changes in +behavior need to include documentation as part of the Pull Request. -We use hugo, if you want to preview your change, you need to install -[hugo](https://gohugo.io) and do a : +We use [hugo](https://gohugo.io). If you want to preview the changes you made +locally while developing, you can run this command: ```shell make dev-docs ``` -this will start a hugo server with live preview of the docs on : +This will download a version of Hugo that is the same as what we use on +Cloudflare Pages (where [pipelinesascode.com](https://pipelinesascode.com) is +generated) and start the Hugo server with a live preview of the docs on: -When we push the release, the docs get rebuilt by CloudFare. +When we push the release, the docs gets rebuilt automatically by CloudFare pages. By default the website only contains the "stable" documentation. If you want to preview the dev documentation as from `main` you @@ -246,6 +248,9 @@ need to go to this URL: +There is a drop-down at the bottom of the page to let you change the older +major version. + ## Documentation when we are doing the Release Process - See here [release-process]({{< relref "/dev/release-process.md" >}}) diff --git a/hack/download-hugo.sh b/hack/download-hugo.sh new file mode 100755 index 000000000..bea833e34 --- /dev/null +++ b/hack/download-hugo.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# description: Download hugo binary from github directly. +# this let us pin the version the way we want it. +# Author: Chmouel Boudjnah +set -eufo pipefail +set -x + +TARGET_VERSION=${1:-} +TARGETDIR=${2:-} + +[[ -z ${TARGET_VERSION} || -z ${TARGETDIR} ]] && { echo "Usage: $0 [targetdir]" && exit 1; } +[[ -d ${TARGETDIR} ]] || mkdir -p ${TARGETDIR} +[[ -x ${TARGETDIR}/hugo ]] && { + ${TARGETDIR}/hugo version | grep -q "${TARGET_VERSION}.*extended " && { + exit 0 + } + rm -f ${TARGETDIR}/hugo +} + +detect_os_arch() { + local os + local arch + + # Detect OS + case "$(uname -s)" in + Linux*) os=Linux ;; + Darwin*) os=macOS ;; + *) os="UNKNOWN" ;; + esac + + # Detect architecture + case "$(uname -m)" in + x86_64) arch=64bit ;; + arm64) arch=ARM64 ;; + aarch64) arch=ARM64 ;; + *) arch="UNKNOWN" ;; + esac + + [[ ${os} == "UNKNOWN" ]] && echo "Unknown OS" && exit 1 + [[ ${arch} == "UNKNOWN" ]] && echo "Unknown Arch" && exit 1 + + echo "${os}-${arch}" +} + +os_arch=$(detect_os_arch) +download_url=https://github.com/gohugoio/hugo/releases/download/v${TARGET_VERSION}/hugo_extended_${TARGET_VERSION}_${os_arch}.tar.gz + +# If we are on a 64 bit arch we can use the go install method because older hugo don't have a binary for it +[[ ${os_arch} == *64 || ${os_arch} == *64bit ]] && { + export GOBIN=${TARGETDIR} + go install -mod=mod github.com/gohugoio/hugo@v${TARGET_VERSION} + exit 0 +} +echo -n "Downloading ${download_url} to ${TARGETDIR}: " +curl -s -L --fail-early -f -o- ${download_url} | tar -xz -C ${TARGETDIR} hugo +echo "Done"