@@ -20,39 +20,97 @@ if [ ! -d "$STATIC_DIR" ]; then
2020 exit 1
2121fi
2222
23- RELEASE_JSON=$( curl -s https://api.github.com/repos/stacklok/toolhive/releases/latest)
24- LATEST_RELEASE_TARBALL=$( echo " $RELEASE_JSON " | grep " tarball_url" | cut -d ' "' -f 4)
25- LATEST_RELEASE_VERSION=$( echo " $RELEASE_JSON " | grep ' "tag_name"' | cut -d ' "' -f 4)
23+ # Handle tag name parameter - default to "latest" if not provided
24+ if [ -z " $1 " ]; then
25+ API_ENDPOINT=" https://api.github.com/repos/stacklok/toolhive/releases/latest"
26+ echo " No tag specified, using latest release"
27+ else
28+ TAG_NAME=" $1 "
29+ API_ENDPOINT=" https://api.github.com/repos/stacklok/toolhive/releases/tags/$TAG_NAME "
30+ echo " Using specified tag: $TAG_NAME "
31+ fi
32+
33+ # Fetch release information
34+ RELEASE_JSON=$( curl -s " $API_ENDPOINT " )
35+ RELEASE_TARBALL=$( echo " $RELEASE_JSON " | grep " tarball_url" | cut -d ' "' -f 4)
36+ RELEASE_VERSION=$( echo " $RELEASE_JSON " | grep ' "tag_name"' | cut -d ' "' -f 4)
2637
27- if [ -z " $LATEST_RELEASE_TARBALL " ]; then
28- echo " Failed to get the latest release tarball URL for ${LATEST_RELEASE_VERSION} "
38+ if [ -z " $RELEASE_TARBALL " ]; then
39+ echo " Failed to get release tarball URL for release: ${RELEASE_VERSION} "
40+ echo " Please check if the tag exists in the repository"
2941 exit 1
3042fi
3143
32- # Output the latest release version for use in CI workflows
44+ # Output the release version for use in CI workflows
3345if [ ! -z " $GITHUB_OUTPUT " ]; then
34- echo " version=$LATEST_RELEASE_VERSION " >> " $GITHUB_OUTPUT "
46+ echo " version=$RELEASE_VERSION " >> " $GITHUB_OUTPUT "
3547fi
3648
49+ # Clean up and prepare import directory
3750rm -rf ${IMPORT_DIR} /toolhive
3851mkdir -p ${IMPORT_DIR} /toolhive
3952
40- echo " Fetching the latest ToolHive release (${LATEST_RELEASE_VERSION } ) from: $LATEST_RELEASE_TARBALL "
53+ echo " Fetching ToolHive release (${RELEASE_VERSION } ) from: $RELEASE_TARBALL "
4154echo " Importing to: $IMPORT_DIR "
4255
43- curl -sL " $LATEST_RELEASE_TARBALL " | tar xz --strip-components=1 -C ./imports/toolhive
44-
45- # # CLI reference
46-
47- echo " Updating ToolHive CLI reference documentation in ${DOCS_DIR} /toolhive/reference/cli"
48-
49- # Remove existing CLI reference documentation files in case we remove any commands
50- rm -f ${DOCS_DIR} /toolhive/reference/cli/thv_* .md
51-
52- cp -r ${IMPORT_DIR} /toolhive/docs/cli/* ${DOCS_DIR} /toolhive/reference/cli
53-
54- # # API reference
55-
56- echo " Updating ToolHive API reference in ${STATIC_DIR} /api-specs"
56+ # Download and extract the release tarball
57+ curl -sL " $RELEASE_TARBALL " | tar xz --strip-components=1 -C ./imports/toolhive
58+
59+ # Determine release type and process accordingly
60+ if [[ " $RELEASE_VERSION " =~ ^v.* ]]; then
61+ echo " Processing main CLI release: $RELEASE_VERSION "
62+
63+ # # CLI reference
64+ echo " Updating ToolHive CLI reference documentation in ${DOCS_DIR} /toolhive/reference/cli"
65+
66+ # Remove existing CLI reference documentation files in case we remove any commands
67+ rm -f ${DOCS_DIR} /toolhive/reference/cli/thv_* .md
68+
69+ # Copy CLI documentation
70+ if [ -d " ${IMPORT_DIR} /toolhive/docs/cli" ]; then
71+ cp -r ${IMPORT_DIR} /toolhive/docs/cli/* ${DOCS_DIR} /toolhive/reference/cli
72+ echo " CLI reference documentation updated successfully"
73+ else
74+ echo " Warning: CLI documentation not found in ${IMPORT_DIR} /toolhive/docs/cli"
75+ fi
76+
77+ # # API reference
78+ echo " Updating ToolHive API reference in ${STATIC_DIR} /api-specs"
79+
80+ # Copy API specification
81+ if [ -f " ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml" ]; then
82+ cp ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml ${STATIC_DIR} /api-specs/toolhive-api.yaml
83+ echo " API reference updated successfully"
84+ else
85+ echo " Warning: API specification not found in ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml"
86+ fi
87+
88+ elif [[ " $RELEASE_VERSION " =~ ^toolhive-operator-crds-.* ]]; then
89+ echo " Processing operator CRD release: $RELEASE_VERSION "
90+
91+ # # CRD API reference
92+ echo " Updating ToolHive CRD API reference in ${STATIC_DIR} /api-specs"
93+
94+ # Copy CRD API documentation
95+ if [ -f " ${IMPORT_DIR} /toolhive/docs/operator/crd-api.md" ]; then
96+ # Remove h1 title from the CRD API documentation, Docusaurus will use the title from the front matter
97+ sed ' 1{/^# /d;}' ${IMPORT_DIR} /toolhive/docs/operator/crd-api.md > ${STATIC_DIR} /api-specs/crd-api.md
98+ echo " CRD API reference updated successfully"
99+ else
100+ echo " Warning: CRD API documentation not found in ${IMPORT_DIR} /toolhive/docs/operator/crd-api.md"
101+ fi
102+
103+ elif [[ " $RELEASE_VERSION " =~ ^toolhive-operator- ]]; then
104+ echo " Processing main operator release: $RELEASE_VERSION "
105+ echo " Placeholder: No specific processing implemented for this release type yet"
106+
107+ else
108+ echo " Unknown release type for tag: $RELEASE_VERSION "
109+ echo " Supported release types:"
110+ echo " - v* (main CLI releases)"
111+ echo " - toolhive-operator-crds-* (CRD releases)"
112+ echo " - toolhive-operator-* (other operator releases)"
113+ exit 1
114+ fi
57115
58- cp -r ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml ${STATIC_DIR} /api-specs/toolhive-api.yaml
116+ echo " Release processing completed for: $RELEASE_VERSION "
0 commit comments