Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions hugo/internal/hugo_repository.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

HUGO_BUILD_FILE = """
HUGO_BUILD_FILE = """
package(default_visibility = ["//visibility:public"])
exports_files( ["hugo"] )
exports_files(["hugo"])
"""

def _hugo_repository_impl(repository_ctx):
Expand All @@ -11,18 +11,21 @@ def _hugo_repository_impl(repository_ctx):
hugo = "hugo_extended"

os_arch = repository_ctx.attr.os_arch

archive_suffix = "tar.gz"
os_name = repository_ctx.os.name.lower()
if os_name.startswith("mac os"):
os_arch = "macOS-64bit"
elif os_name.find("windows") != -1:
os_arch = "Windows-64bit"
else:
os_arch = "Linux-64bit"

url = "https://github.com/gohugoio/hugo/releases/download/v{version}/{hugo}_{version}_{os_arch}.tar.gz".format(
if os_arch == "":
if os_name.startswith("mac os"):
os_arch = "darwin-universal"
elif os_name.find("windows") != -1:
os_arch = "windows-amd64"
archive_suffix = "zip"
else:
os_arch = "Linux-64bit"

url = "https://github.com/gohugoio/hugo/releases/download/v{version}/{hugo}_{version}_{os_arch}.{archive_suffix}".format(
hugo = hugo,
os_arch = os_arch,
archive_suffix = archive_suffix,
version = repository_ctx.attr.version,
)

Expand All @@ -31,13 +34,19 @@ def _hugo_repository_impl(repository_ctx):
sha256 = repository_ctx.attr.sha256,
)

# On Windows, the Hugo binary is named `hugo.exe`. We must symlink to
# `hugo` so that there is a consistent location for the binary across
# platforms.
if os_name.find("windows") != -1:
repository_ctx.symlink("hugo.exe", "hugo")

repository_ctx.file("BUILD.bazel", HUGO_BUILD_FILE)

hugo_repository = repository_rule(
_hugo_repository_impl,
attrs = {
"version": attr.string(
default = "0.55.5",
default = "0.122.0",
doc = "The hugo version to use",
),
"sha256": attr.string(
Expand Down