1
1
#! /bin/bash
2
2
3
+ set -euo pipefail
4
+
3
5
REPO_ROOT=$( git rev-parse --show-toplevel)
4
- cd $REPO_ROOT
6
+ cd " $REPO_ROOT "
5
7
6
8
IMPORT_DIR=" ./imports"
7
9
DOCS_DIR=" ./docs"
@@ -20,39 +22,108 @@ if [ ! -d "$STATIC_DIR" ]; then
20
22
exit 1
21
23
fi
22
24
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)
25
+ # Check if jq is installed
26
+ if ! command -v jq > /dev/null 2>&1 ; then
27
+ echo " Error: 'jq' is required but not installed. Please install jq and try again."
28
+ exit 1
29
+ fi
30
+
31
+ VERSION=$( echo " ${1:- } " | tr -cd ' [:alnum:].-' )
32
+
33
+ # Handle tag name parameter - default to "latest" if not provided
34
+ if [ -z " $VERSION " ] || [ " $VERSION " = " latest" ]; then
35
+ API_ENDPOINT=" https://api.github.com/repos/stacklok/toolhive/releases/latest"
36
+ echo " No tag specified or 'latest' specified, using latest release"
37
+ else
38
+ TAG_NAME=" $VERSION "
39
+ API_ENDPOINT=" https://api.github.com/repos/stacklok/toolhive/releases/tags/$TAG_NAME "
40
+ echo " Using specified tag: $TAG_NAME "
41
+ fi
42
+
43
+ # Fetch release information
44
+ RELEASE_JSON=$( curl -sf " $API_ENDPOINT " || {
45
+ echo " Failed to fetch release information from GitHub API"
46
+ exit 1
47
+ })
48
+ RELEASE_TARBALL=$( echo " $RELEASE_JSON " | jq -r ' .tarball_url // empty' )
49
+ RELEASE_VERSION=$( echo " $RELEASE_JSON " | jq -r ' .tag_name // empty' )
26
50
27
- if [ -z " $LATEST_RELEASE_TARBALL " ]; then
28
- echo " Failed to get the latest release tarball URL for ${LATEST_RELEASE_VERSION} "
51
+ if [ -z " $RELEASE_TARBALL " ]; then
52
+ echo " Failed to get release tarball URL for release: ${RELEASE_VERSION} "
53
+ echo " Please check if the tag exists in the repository"
29
54
exit 1
30
55
fi
31
56
32
- # Output the latest release version for use in CI workflows
33
- if [ ! -z " $GITHUB_OUTPUT " ]; then
34
- echo " version=$LATEST_RELEASE_VERSION " >> " $GITHUB_OUTPUT "
57
+ # Output the release version for use in CI workflows (if running in GitHub Actions)
58
+ if [ -n " ${ GITHUB_OUTPUT:- } " ]; then
59
+ echo " version=$RELEASE_VERSION " >> " $GITHUB_OUTPUT "
35
60
fi
36
61
62
+ # Clean up and prepare import directory
37
63
rm -rf ${IMPORT_DIR} /toolhive
38
64
mkdir -p ${IMPORT_DIR} /toolhive
39
65
40
- echo " Fetching the latest ToolHive release (${LATEST_RELEASE_VERSION } ) from: $LATEST_RELEASE_TARBALL "
66
+ echo " Fetching ToolHive release (${RELEASE_VERSION } ) from: $RELEASE_TARBALL "
41
67
echo " Importing to: $IMPORT_DIR "
42
68
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"
69
+ # Download and extract the release tarball
70
+ curl -sfL " $RELEASE_TARBALL " | tar xz --strip-components=1 -C ./imports/toolhive
71
+
72
+ # Determine release type and process accordingly
73
+ if [[ " $RELEASE_VERSION " =~ ^v.* ]]; then
74
+ echo " Processing main CLI release: $RELEASE_VERSION "
75
+
76
+ # # CLI reference
77
+ echo " Updating ToolHive CLI reference documentation in ${DOCS_DIR} /toolhive/reference/cli"
78
+
79
+ # Remove existing CLI reference documentation files in case we remove any commands
80
+ rm -f ${DOCS_DIR} /toolhive/reference/cli/thv_* .md
81
+
82
+ # Copy CLI documentation
83
+ if [ -d " ${IMPORT_DIR} /toolhive/docs/cli" ]; then
84
+ cp -r ${IMPORT_DIR} /toolhive/docs/cli/* ${DOCS_DIR} /toolhive/reference/cli
85
+ echo " CLI reference documentation updated successfully"
86
+ else
87
+ echo " Warning: CLI documentation not found in ${IMPORT_DIR} /toolhive/docs/cli"
88
+ fi
89
+
90
+ # # API reference
91
+ echo " Updating ToolHive API reference in ${STATIC_DIR} /api-specs"
92
+
93
+ # Copy API specification
94
+ if [ -f " ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml" ]; then
95
+ cp ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml ${STATIC_DIR} /api-specs/toolhive-api.yaml
96
+ echo " API reference updated successfully"
97
+ else
98
+ echo " Warning: API specification not found in ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml"
99
+ fi
100
+
101
+ elif [[ " $RELEASE_VERSION " =~ ^toolhive-operator-crds-.* ]]; then
102
+ echo " Processing operator CRD release: $RELEASE_VERSION "
103
+
104
+ # # CRD API reference
105
+ echo " Updating ToolHive CRD API reference in ${STATIC_DIR} /api-specs"
106
+
107
+ # Copy CRD API documentation
108
+ if [ -f " ${IMPORT_DIR} /toolhive/docs/operator/crd-api.md" ]; then
109
+ # Remove h1 title from the CRD API documentation, Docusaurus will use the title from the front matter
110
+ sed ' 1{/^# /d;}' ${IMPORT_DIR} /toolhive/docs/operator/crd-api.md > ${STATIC_DIR} /api-specs/crd-api.md
111
+ echo " CRD API reference updated successfully"
112
+ else
113
+ echo " Warning: CRD API documentation not found in ${IMPORT_DIR} /toolhive/docs/operator/crd-api.md"
114
+ fi
115
+
116
+ elif [[ " $RELEASE_VERSION " =~ ^toolhive-operator- ]]; then
117
+ echo " Processing main operator release: $RELEASE_VERSION "
118
+ echo " Placeholder: No specific processing implemented for this release type yet"
119
+
120
+ else
121
+ echo " Unknown release type for tag: $RELEASE_VERSION "
122
+ echo " Supported release types:"
123
+ echo " - v* (main CLI releases)"
124
+ echo " - toolhive-operator-crds-* (CRD releases)"
125
+ echo " - toolhive-operator-* (other operator releases)"
126
+ exit 1
127
+ fi
57
128
58
- cp -r ${IMPORT_DIR} /toolhive/docs/server/swagger.yaml ${STATIC_DIR} /api-specs/toolhive-api.yaml
129
+ echo " Release processing completed for: $RELEASE_VERSION "
0 commit comments