forked from hugo-fixit/FixIt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
111 lines (91 loc) · 2.99 KB
/
Copy pathbuild.sh
File metadata and controls
111 lines (91 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# @file
# Builds a Hugo site hosted on Vercel.
#
# The Vercel build image automatically installs Node.js dependencies.
#
# @example
# chmod a+x build.sh && ./build.sh
#------------------------------------------------------------------------------
# Exit on error, undefined variables, or pipe failures
set -euo pipefail
build_temp_dir=""
# Perform cleanup
cleanup() {
if [[ -n "${build_temp_dir:-}" && -d "${build_temp_dir}" ]]; then
rm -rf "${build_temp_dir}"
fi
}
# Register the cleanup trap
trap cleanup EXIT SIGINT SIGTERM
# Build demo/test with the correct Hugo baseURL on Vercel preview deployments.
# - demo: https://${VERCEL_URL}
# - test: https://${VERCEL_URL}/test
build() {
local target="$1"
if [[ ! "${target}" =~ ^(demo|test)$ ]]; then
echo "Unknown build target: ${target}" >&2
return 2
fi
if [[ "${VERCEL_ENV:-}" != "preview" ]]; then
pnpm "build:${target}"
return
fi
local base_url="https://${VERCEL_URL}"
if [[ "${target}" == "test" ]]; then
base_url+="/test"
fi
pnpm "build:${target}" --buildDrafts --baseURL "${base_url}"
}
main() {
# Define tool versions
# You can also manage these via Environment Variables in the Vercel dashboard.
if [[ -z "${DART_SASS_VERSION:-}" ]]; then
DART_SASS_VERSION=1.99.0
fi
if [[ -z "${GO_VERSION:-}" ]]; then
GO_VERSION=1.26.1
fi
# Set the build timezone
export TZ=Asia/Shanghai
# Create and move into a temporary directory for downloads
build_temp_dir=$(mktemp -d)
pushd "${build_temp_dir}" > /dev/null
# Create the local tools directory
mkdir -p "${HOME}/.local"
# Install Dart Sass
echo "Installing Dart Sass ${DART_SASS_VERSION}..."
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
export PATH="${HOME}/.local/dart-sass:${PATH}"
# Install Go
# echo "Installing Go ${GO_VERSION}..."
# curl -sLJO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
# tar -C "${HOME}/.local" -xf "go${GO_VERSION}.linux-amd64.tar.gz"
# export PATH="${HOME}/.local/go/bin:${PATH}"
# Install Go from the package manager
dnf install -y golang.x86_64
# Return to the project root
popd > /dev/null
# Verify installations
echo "Verifying installations..."
echo Dart Sass: "$(sass --version)"
echo Go: "$(go version)"
echo Hugo: "$(hugo version)"
echo Node.js: "$(node --version)"
# Configure Git
echo "Configuring Git..."
git config core.quotepath false
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
git fetch --unshallow
fi
# Build the site
echo "Building the site..."
build demo & pid_demo=$!
build test & pid_test=$!
wait "${pid_demo}" || { echo "build demo failed"; exit 1; }
wait "${pid_test}" || { echo "build test failed"; exit 1; }
pnpm -F integration start
}
main "$@"