Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·150 lines (131 loc) · 5.42 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·150 lines (131 loc) · 5.42 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
set -o errexit -o pipefail
source ./scripts/ci/common.sh
echo "Building CSS and JS assets....."
make build-assets
printf "Compiling theme JavaScript and CSS...\n\n"
export ASSET_BUNDLE_ID="$(build_identifier)"
# Paths to the CSS and JS bundles we'll generate below. Note that environment variables
# are read by some templates during the Hugo build process.
export CSS_BUNDLE="static/css/styles.${ASSET_BUNDLE_ID}.css"
export JS_BUNDLE="static/js/bundle.min.${ASSET_BUNDLE_ID}.js"
# Relative paths to those same files, read by Hugo templates.
export REL_CSS_BUNDLE="/css/styles.${ASSET_BUNDLE_ID}.css"
export REL_JS_BUNDLE="/js/bundle.min.${ASSET_BUNDLE_ID}.js"
export REPO_THEME_PATH="themes/default/"
REGISTRY_COMMIT="$(git_sha_short)"
printf "Generating API docs from registry commit %s...\n\n" "${REGISTRY_COMMIT}"
# Restore cached API docs output so resourcedocsgen can skip unchanged packages.
# The .generated sentinel files inside each api-docs/ directory record the cache key;
# if the key matches, the Go tool skips schema fetching and doc generation entirely.
API_DOCS_CACHE=".cache/api-docs"
CONTENT_DIR="themes/default/content/registry/packages"
NAVS_DIR="themes/default/static/registry/packages/navs"
SCHEMAS_DIR="themes/default/static/registry/packages"
LLM_DOCS_DIR="llm-docs-out/registry/packages"
if [[ -d "$API_DOCS_CACHE/content" ]]; then
log "Restoring cached API docs..."
mkdir -p "$CONTENT_DIR" "$NAVS_DIR"
count=0
for pkg_dir in "$API_DOCS_CACHE/content"/*/; do
[[ -d "$pkg_dir/api-docs" ]] || continue
pkg=$(basename "$pkg_dir")
if [[ ! -d "$CONTENT_DIR/$pkg/api-docs" ]]; then
mkdir -p "$CONTENT_DIR/$pkg"
cp -a "$pkg_dir/api-docs" "$CONTENT_DIR/$pkg/api-docs"
((count++)) || true
fi
done
for nav in "$API_DOCS_CACHE/navs"/*.json; do
[[ -f "$nav" ]] || continue
name=$(basename "$nav")
[[ -f "$NAVS_DIR/$name" ]] || cp -a "$nav" "$NAVS_DIR/$name"
done
for schema_dir in "$API_DOCS_CACHE/schemas"/*/; do
[[ -d "$schema_dir" ]] || continue
pkg=$(basename "$schema_dir")
[[ -d "$SCHEMAS_DIR/$pkg" ]] || cp -a "$schema_dir" "$SCHEMAS_DIR/$pkg"
done
if [[ -d "$API_DOCS_CACHE/llm-docs" ]]; then
mkdir -p "$LLM_DOCS_DIR"
for pkg_dir in "$API_DOCS_CACHE/llm-docs"/*/; do
[[ -d "$pkg_dir/api-docs" ]] || continue
pkg=$(basename "$pkg_dir")
if [[ ! -d "$LLM_DOCS_DIR/$pkg/api-docs" ]]; then
mkdir -p "$LLM_DOCS_DIR/$pkg"
cp -a "$pkg_dir/api-docs" "$LLM_DOCS_DIR/$pkg/api-docs"
fi
done
fi
log "Restored $count cached package doc sets"
fi
make api-docs
# Save API docs output to cache for next run.
log "Saving API docs to cache..."
rm -rf "$API_DOCS_CACHE"
mkdir -p "$API_DOCS_CACHE/content" "$API_DOCS_CACHE/navs" "$API_DOCS_CACHE/schemas" "$API_DOCS_CACHE/llm-docs"
for pkg_dir in "$CONTENT_DIR"/*/; do
[[ -d "$pkg_dir/api-docs" ]] || continue
pkg=$(basename "$pkg_dir")
[[ "$pkg" == *@* ]] && continue # versioned packages have their own cache
mkdir -p "$API_DOCS_CACHE/content/$pkg"
cp -a "$pkg_dir/api-docs" "$API_DOCS_CACHE/content/$pkg/api-docs"
done
for nav in "$NAVS_DIR"/*.json; do
[[ -f "$nav" ]] || continue
name=$(basename "$nav")
[[ "$name" == *@* ]] && continue
cp -a "$nav" "$API_DOCS_CACHE/navs/"
done
for schema_dir in "$SCHEMAS_DIR"/*/; do
[[ -d "$schema_dir" && -f "$schema_dir/schema.json" ]] || continue
pkg=$(basename "$schema_dir")
[[ "$pkg" == *@* ]] && continue
# Only cache schema.json, not the entire directory tree (which may contain
# stale LLM doc files from older builds).
mkdir -p "$API_DOCS_CACHE/schemas/$pkg"
cp -a "$schema_dir/schema.json" "$API_DOCS_CACHE/schemas/$pkg/schema.json"
done
for pkg_dir in "$LLM_DOCS_DIR"/*/; do
[[ -d "$pkg_dir/api-docs" ]] || continue
pkg=$(basename "$pkg_dir")
[[ "$pkg" == *@* ]] && continue
mkdir -p "$API_DOCS_CACHE/llm-docs/$pkg"
cp -a "$pkg_dir/api-docs" "$API_DOCS_CACHE/llm-docs/$pkg/api-docs"
done
log "API docs cache saved"
# Apply fixes. See script for details.
node ./scripts/apply-fixes.js
log "Running Hugo..."
echo
echo
case ${1} in
preview)
export HUGO_BASEURL="http://$(origin_bucket_prefix)-$(build_identifier).s3-website.$(aws_region).amazonaws.com"
hugo --minify --buildFuture --templateMetrics -e preview
;;
update)
# testing-deploy.yml builds www.pulumi-test.io with the production Hugo
# environment, which uses the production OneTrust domain script. Swap
# in the "-test" id here, from the deploy's DEPLOYMENT_ENVIRONMENT. The
# "-test" id must never reach production.
if [[ "${DEPLOYMENT_ENVIRONMENT}" == "testing" ]]; then
export HUGO_PARAMS_ONETRUSTDOMAINSCRIPT="01a090cf-8fe9-7448-94a1-4b90a7c501d4-test"
fi
hugo --minify --buildFuture --templateMetrics -e production
;;
*)
echo "Unknown mode, '${1}' must be one of 'preview' or 'update'"
exit 1
;;
esac
# Split the sitemap into multiple files if it exceeds the per-file URL limit.
yarn run split-sitemap
# Purge unused CSS and write commit-hash-named bundles that match the <link>
# hrefs emitted by assets.html, avoiding stale CloudFront caches (#10466).
yarn run minify-css
# Inline critical CSS for key pages.
node scripts/inline-critical-css.js
log "Done!"
echo
echo