forked from aztec-labs-eng/aztec-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·149 lines (133 loc) · 4.59 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·149 lines (133 loc) · 4.59 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
#!/usr/bin/env bash
source $(git rev-parse --show-toplevel)/ci3/source_bootstrap
repo_root=$(git rev-parse --show-toplevel)
export BB=${BB:-$repo_root/labs-aztec-toolchain/bin/bb}
export NARGO=${NARGO:-$repo_root/labs-aztec-toolchain/bin/nargo}
# We search the docs/*.md files to find included code, and use those as our rebuild dependencies.
# We prefix the results with ^ to make them "not a file", otherwise they'd be interpreted as pattern files.
hash=$(
cache_content_hash \
.rebuild_patterns \
$(find docs docs-developers docs-operate docs-participate developer_versioned_docs network_versioned_docs -type f -name "*.md*" -exec grep '^#include_code' {} \; | \
awk '{ gsub("^/", "", $3); print "^" $3 }' | sort -u)
)
if semver check $REF_NAME; then
# Ensure that released versions don't use cache from non-released versions (they will have incorrect links to master)
hash+=$REF_NAME
export COMMIT_TAG=$REF_NAME
fi
function build_docs {
if [ "${CI:-0}" -eq 1 ] && [ $(arch) == arm64 ]; then
echo "Not building docs for arm64 in CI."
return
fi
echo_header "build docs"
npm_install_deps
if cache_download docs-$hash.tar.gz; then
return
fi
denoise "yarn build"
cache_upload docs-$hash.tar.gz build
}
function check_generated_refs {
if [ "${CI:-0}" -eq 1 ] && [ $(arch) == arm64 ]; then
echo "Not checking generated docs for arm64 in CI."
return
fi
echo_header "check generated aztec.js reference"
./scripts/aztecjs_reference_generation/update_docs.sh --check
}
function test_cmds {
if [ "${CI:-0}" -eq 1 ] && [ $(arch) == arm64 ]; then
# Not running docs tests for arm64 in CI.
return
fi
local test_hash=$hash
echo "$test_hash cd docs && yarn spellcheck"
# Delegate to examples for their test commands
(cd examples && ./bootstrap.sh test_cmds)
}
function test {
echo_header "docs test"
test_cmds | parallelize
}
function check_orphaned_urls {
echo_header "Check orphaned URLs"
# Source the baseline from the base branch, not the working tree, so a PR
# cannot weaken its own gate by deleting URLs from the snapshot in the same
# diff. The committed snapshot only grows the protected set for future PRs;
# the check a PR must satisfy is the base-branch version it cannot edit.
local snapshot=snapshots/published-urls.txt
local base_ref="${GITHUB_BASE_REF:-${MERGE_GROUP_BASE_REF:-main}}"
base_ref="${base_ref#refs/heads/}"
local tmp
tmp=$(mktemp)
# shellcheck disable=SC2064
trap "rm -f '$tmp'" RETURN
# Resolve the base branch first, distinguishing "base unreachable" from "base
# reachable but snapshot absent". Only the latter is a legitimate fallback (it
# happens for the PR that first introduces the snapshot). Treating an
# unreachable base as a fallback would silently reopen the bypass.
local base_obj=""
if git rev-parse --verify -q "refs/remotes/origin/${base_ref}" >/dev/null; then
base_obj="refs/remotes/origin/${base_ref}"
elif git fetch -q --depth=1 origin "refs/heads/${base_ref}:refs/remotes/origin/${base_ref}" 2>/dev/null &&
git rev-parse --verify -q "refs/remotes/origin/${base_ref}" >/dev/null; then
base_obj="refs/remotes/origin/${base_ref}"
fi
local baseline
if [[ -n "$base_obj" ]]; then
if git show "${base_obj}:docs/${snapshot}" >"$tmp" 2>/dev/null; then
echo "Using base-branch baseline (${base_obj})."
baseline="$tmp"
else
echo "Base branch ${base_ref} has no snapshot yet; using working-tree snapshot (introducing PR)."
baseline="$snapshot"
fi
elif [[ "${CI:-0}" -eq 1 ]]; then
# In CI the base must be reachable; downgrading to the PR's own editable
# snapshot would reopen the bypass this gate exists to close.
echo "ERROR: cannot resolve base branch origin/${base_ref} to source the orphan-check baseline." >&2
return 1
else
echo "Base branch origin/${base_ref} unavailable; using working-tree snapshot (local run)."
baseline="$snapshot"
fi
local rc=0
FAIL_ON_ORPHAN=1 ./scripts/check_orphaned_urls.sh "$baseline" || rc=$?
return $rc
}
function check_references {
echo_header "Check doc references"
./scripts/check_doc_references.sh docs
}
function build_examples {
echo_header "Building examples"
(cd examples && ./bootstrap.sh "$@")
}
case "$cmd" in
"ci")
build_examples
build_docs
check_generated_refs
test
check_orphaned_urls
check_references
;;
"")
build_examples
build_docs
check_generated_refs
check_orphaned_urls
check_references
;;
"hash")
echo "$hash"
;;
"compile")
build_examples compile "$@"
;;
*)
default_cmd_handler "$@"
;;
esac