Skip to content

Commit 9a3b171

Browse files
authored
allow build on mac (#6478)
1 parent 0957edf commit 9a3b171

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

hack/build.sh

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,28 @@ readonly TEMP="$(mktemp -d)"
4040
readonly SITE=$PWD/site
4141
rm -rf site/
4242

43+
if [[ -z "${GITHUB_TOKEN}" ]]; then
44+
echo "❌ Error: GITHUB_TOKEN environment variable is not set." >&2
45+
exit 1
46+
fi
47+
48+
REMOTE_BRANCH=$(git remote | grep -q upstream && echo upstream || echo origin)
49+
4350
# If we're running on Netlify, update git branches
4451
if [ "$CI" == "true" ]; then
45-
git fetch --prune origin
52+
git fetch --prune $REMOTE_BRANCH
53+
fi
54+
55+
if [[ "$OSTYPE" == "darwin"* ]]; then
56+
# Require gnu-sed.
57+
if ! [ -x "$(command -v gsed)" ]; then
58+
echo "Error: 'gsed' is not istalled." >&2
59+
echo "If you are using Homebrew, install with 'brew install gnu-sed'." >&2
60+
exit 1
61+
fi
62+
SED_CMD=gsed
63+
else
64+
SED_CMD=sed
4665
fi
4766

4867

@@ -64,29 +83,29 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
6483
# Remove pre-release documents from search. This has to be applied to each markdown, unfortunately.
6584
# This needs to be done as two commands: the first ensures front-matter in files that don't have it,
6685
# and the seconds inserts commands into the front-matter.
67-
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs sed -i '1s/^\([^-]\)/---\n---\n\1/'
68-
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs sed -i '2isearch:\n exclude: true'
86+
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs ${SED_CMD} -i '1s/^\([^-]\)/---\n---\n\1/'
87+
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs ${SED_CMD} -i '2isearch:\n exclude: true'
6988
echo "- Docs: development" >> "$TEMP/content/docs/.nav.yml"
70-
sed -i 's| versioned/| development/|g' "$TEMP/content/config/redirects.yml"
89+
${SED_CMD} -i 's| versioned/| development/|g' "$TEMP/content/config/redirects.yml"
7190

7291
# Handle current release specially, as we don't include a version slug
7392
# Note that git worktree reuses the same git clone, so we don't need to clone 50+MB each time.
74-
git worktree add --detach "$TEMP/current-release" "origin/${DOCS_BRANCHES[0]}"
93+
git worktree add --detach "$TEMP/current-release" "${REMOTE_BRANCH}/${DOCS_BRANCHES[0]}"
7594
if [ -d "$TEMP/current-release/docs/versioned" ]; then
7695
cp -r "$TEMP/current-release/docs/versioned" "$TEMP/content/docs/docs"
7796
echo -e "\ndoc_base: /docs/versioned/" >> "$TEMP/content/docs/docs/.meta.yml"
7897
# Fix up redirects from old versioned/ path to docs/ and append them to redirects.
7998
# We only do this for development (so we can see effects) and docs (current)
80-
grep '^ ' "$TEMP/current-release/config/redirects.yml" | sed 's| versioned/| docs/|g' >> "$TEMP/content/config/redirects.yml"
99+
grep '^ ' "$TEMP/current-release/config/redirects.yml" | ${SED_CMD} 's| versioned/| docs/|g' >> "$TEMP/content/config/redirects.yml"
81100
else
82101
cp -r "$TEMP/current-release/docs" "$TEMP/content/docs/docs"
83102
echo -e "\ndoc_base: /docs/" >> "$TEMP/content/docs/docs/.meta.yml"
84103
# Older redirects were already for /docs/, but did not have the right destination path.
85-
grep '^ ' "$TEMP/current-release/config/redirects.yml" | sed '/: *http/! s|: |: docs/|' >> "$TEMP/content/config/redirects.yml"
104+
grep '^ ' "$TEMP/current-release/config/redirects.yml" | ${SED_CMD} '/: *http/! s|: |: docs/|' >> "$TEMP/content/config/redirects.yml"
86105
# Copy the nav, but strip out non-versioned content, starting with blog
87106
# This can be retired after we stop supporting v1.19.
88107
if [ ! -f "$TEMP/content/docs/docs/.nav.yml" ]; then
89-
sed '/- Blog:/,$d' "$TEMP/current-release/config/nav.yml" >> "$TEMP/content/docs/docs/.nav.yml"
108+
${SED_CMD} '/- Blog:/,$d' "$TEMP/current-release/config/nav.yml" >> "$TEMP/content/docs/docs/.nav.yml"
90109
fi
91110
# Redirect from old homepage to concepts documentation, if it exists (pre-1.20)
92111
if [ -f "$TEMP/content/docs/docs/concepts/README.md" ]; then
@@ -105,7 +124,7 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
105124
version=${previous[$i]}
106125

107126
echo "Building for previous version $version"
108-
git worktree add --detach "$TEMP/docs-$version" "origin/${DOCS_BRANCHES[i+1]}"
127+
git worktree add --detach "$TEMP/docs-$version" "${REMOTE_BRANCH}/${DOCS_BRANCHES[i+1]}"
109128
if [ -d "$TEMP/docs-$version/docs/versioned" ]; then
110129
cp -r "$TEMP/docs-$version/docs/versioned" "$TEMP/content/docs/v$version-docs"
111130
echo -e "\ndoc_base: /docs/versioned/" >> "$TEMP/content/docs/v$version-docs/.meta.yml"
@@ -115,7 +134,7 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
115134
# Copy the nav, but strip out non-versioned content, starting with blog
116135
# This can be retired after we stop supporting v1.19.
117136
if [ ! -f "$TEMP/content/docs/v$version-docs/.nav.yml" ]; then
118-
sed '/- Blog:/,$d' "$TEMP/docs-$version/config/nav.yml" >> "$TEMP/content/docs/v$version-docs/.nav.yml"
137+
${SED_CMD} '/- Blog:/,$d' "$TEMP/docs-$version/config/nav.yml" >> "$TEMP/content/docs/v$version-docs/.nav.yml"
119138
fi
120139
# Redirect from old homepage to concepts documentation, if it exists (pre-1.20)
121140
if [ -f "$TEMP/content/docs/v${version}-docs/concepts/README.md" ]; then
@@ -134,8 +153,8 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
134153
# Remove older-version documents from search. This has to be applied to each markdown, unfortunately.
135154
# This needs to be done as two commands: the first ensures front-matter in files that don't have it,
136155
# and the seconds inserts commands into the front-matter.
137-
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs sed -i '1s/^\([^-]\)/---\n---\n\1/'
138-
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs sed -i '2isearch:\n exclude: true'
156+
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs ${SED_CMD} -i '1s/^\([^-]\)/---\n---\n\1/'
157+
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs ${SED_CMD} -i '2isearch:\n exclude: true'
139158
done
140159

141160
# Put the development version at the end of the JSON list of documentation,

0 commit comments

Comments
 (0)