-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-static.sh
More file actions
executable file
·48 lines (42 loc) · 1.59 KB
/
build-static.sh
File metadata and controls
executable file
·48 lines (42 loc) · 1.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
#!/usr/bin/env bash
#
# Build static content from the spec repo
set -exo pipefail
BASE_DIR="$( cd "$( dirname "$0" )/.." >/dev/null 2>&1 && pwd )"
STATIC_DIR="${BASE_DIR}/static"
DOCS_DIR="${SPEC_DIR:-$(mktemp -d)}"
# Clone the spec repo to pull the schemas
if [ ! -d ${DOCS_DIR}/.git ]; then
git clone https://github.com/cdevents/spec "${DOCS_DIR}"
fi
# Serve versioned schemas
cd "${DOCS_DIR}"
for tag in $(git tag); do
# Get the version by trimming the "v"
version=$(printf '%s' "${tag}" | sed 's/^v//g')
TARGET_SCHEMA_FOLDER="${STATIC_DIR}/${version}/schema"
# Create the folder if it doesn't exists yet
mkdir -p "${TARGET_SCHEMA_FOLDER}" || true
git checkout "${tag}"
for schema in schemas/*json; do
# Extract the schema name from the schema id itself
TARGET_SCHEMA=$(awk -F'/' '/"\$id"/{ print $6 }' "${schema}" | sed -e 's/",//g')
# Copy the file to static with the new name
cp "${schema}" "${TARGET_SCHEMA_FOLDER}/${TARGET_SCHEMA}"
done
# Starting with v0.4 we serve links schemas too
if [[ -d schemas/links ]]; then
pushd schemas
mkdir "${TARGET_SCHEMA_FOLDER}/links" || true
for schema in links/*json; do
cp -r "${schema}" "${TARGET_SCHEMA_FOLDER}/${schema}"
cp -r "${schema}" "${TARGET_SCHEMA_FOLDER}/${schema%.*}"
done
popd
fi
# Starting with v0.4 we serve the custom events schema
if [[ -f custom/schema.json ]]; then
cp custom/schema.json "${TARGET_SCHEMA_FOLDER}/custom"
cp custom/schema.json "${TARGET_SCHEMA_FOLDER}/custom.json"
fi
done