Skip to content

Commit

Permalink
feat: pin Hugo version
Browse files Browse the repository at this point in the history
- 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 <chmouel@redhat.com>
  • Loading branch information
chmouel committed Oct 17, 2024
1 parent 7e019bc commit 1f3575e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 15 deletions.
15 changes: 10 additions & 5 deletions .tekton/doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TARGET_NAMESPACE=pipelines-as-code
HUGO_VERSION=0.96.0
GOLANGCI_LINT=golangci-lint
GOFUMPT=gofumpt
TKN_BINARY_NAME := tkn
Expand All @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down
17 changes: 11 additions & 6 deletions docs/content/dev/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,33 @@ 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:

<https://localhost:1313>

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 <https://pipelinesascode.com> only contains the "stable"
documentation. If you want to preview the dev documentation as from `main` you
need to go to this URL:

<https://main.pipelines-as-code.pages.dev>

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" >}})
Expand Down
56 changes: 56 additions & 0 deletions hack/download-hugo.sh
Original file line number Diff line number Diff line change
@@ -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 <chmouel@chmouel.com>
set -eufo pipefail
set -x

TARGET_VERSION=${1:-}
TARGETDIR=${2:-}

[[ -z ${TARGET_VERSION} || -z ${TARGETDIR} ]] && { echo "Usage: $0 <version> [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"

0 comments on commit 1f3575e

Please sign in to comment.