Skip to content

Add tooling to bump container-toolkit version #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ Always update the openshift docset when there is a new gpu-operator docset versi
copyright_start = 2020
```

1. Update the version in `<component-name>/versions1.json`:
1. Update the version in `<component-name>/versions.json`:

```diff
diff --git a/container-toolkit/versions1.json b/container-toolkit/versions1.json
diff --git a/container-toolkit/versions.json b/container-toolkit/versions.json
index 95429953..e2738987 100644
--- a/container-toolkit/versions1.json
+++ b/container-toolkit/versions1.json
--- a/container-toolkit/versions.json
+++ b/container-toolkit/versions.json
@@ -1,6 +1,10 @@
[
{
Expand Down
93 changes: 51 additions & 42 deletions container-toolkit/versions.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
{
"latest": "1.17.8",
"versions":
[
{
"version": "1.17.8"
},
{
"version": "1.17.7"
},
{
"version": "1.17.6"
},
{
"version": "1.17.5"
},
{
"version": "1.17.4"
},
{
"version": "1.17.3"
},
{
"version": "1.17.2"
},
{
"version": "1.17.1"
},
{
"version": "1.17.0"
},
{
"version": "1.16.2"
},
{
"version": "1.16.1"
},
{
"version": "1.16.0"
}
]
}
[
{
"preferred": "true",
"url": "../1.17.8",
"version": "1.17.8"
},
{
"url": "../1.17.7",
"version": "1.17.7"
},
{
"url": "../1.17.6",
"version": "1.17.6"
},
{
"url": "../1.17.5",
"version": "1.17.5"
},
{
"url": "../1.17.4",
"version": "1.17.4"
},
{
"url": "../1.17.3",
"version": "1.17.3"
},
{
"url": "../1.17.2",
"version": "1.17.2"
},
{
"url": "../1.17.1",
"version": "1.17.1"
},
{
"url": "../1.17.0",
"version": "1.17.0"
},
{
"url": "../1.16.2",
"version": "1.16.2"
},
{
"url": "../1.16.1",
"version": "1.16.1"
},
{
"url": "../1.16.0",
"version": "1.16.0"
}
]
51 changes: 0 additions & 51 deletions container-toolkit/versions1.json

This file was deleted.

4 changes: 2 additions & 2 deletions repo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ sphinx_conf_py_extra = """

html_domain_indices = False
html_use_index = False
html_extra_path = ["versions1.json"]
html_extra_path = ["versions.json"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were two reasons for using versions1.json:

  • It avoided clobbering the older format that was used before NVIDIA Sphinx Theme. This way, if someone stumbled on an older version of the docs, the version menu would still work.
  • Naming the file versions1.json is a bit of a convention across docs projects at NVIDIA, kinda because we've nearly all migrated to using NVIDIA Sphinx Theme.

IMO, not worth changing and kind of worth it to keep as-is for continuity across projects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Are the docs not built from a specific commit? Meaning that as long as that specific commit has the "correct" version information then using versions.json should be fine?

html_static_path = ["${root}/css"]
html_css_files = ["custom.css"]

html_theme_options = {
"icon_links": [],
"switcher": {
"json_url": "../versions1.json",
"json_url": "../versions.json",
"version_match": release,
},
}
Expand Down
71 changes: 71 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

# Function to print usage
print_usage() {
echo "Usage: $0 <component-name> <new-version>"
echo "Example: $0 container-toolkit 1.17.9"
exit 1
}

# Check if yq is installed
check_yq() {
if ! command -v yq &> /dev/null; then
echo "Error: yq is not installed"
echo "Please install yq first. On macOS, you can use: brew install yq"
exit 1
fi
}

# Validate input parameters
if [[ $# -ne 2 ]]; then
print_usage
fi

COMPONENT="$1"
NEW_VERSION="$2"

# Check if yq is available
check_yq

# Validate component exists both as a directory and in repo.toml
if [[ ! -d "$COMPONENT" ]]; then
echo "Error: Component directory '${COMPONENT}' not found"
exit 1
fi

# Check if the version field exists and get current version
CURRENT_VERSION=$(yq ".repo_docs.projects.${COMPONENT}.version" repo.toml)
if [[ "$CURRENT_VERSION" == "null" ]]; then
echo "Error: Component '${COMPONENT}' version field not found in repo.toml"
exit 1
fi

# Update versions.json if it exists
VERSIONS_JSON="$COMPONENT/versions.json"
if [[ -f "$VERSIONS_JSON" ]]; then
echo "Updating $VERSIONS_JSON..."
yq -p=json -o=json -i '. = [{"preferred": "true", "url": "../'"${NEW_VERSION}"'", "version": "'"${NEW_VERSION}"'"}] + [(.[0] | del(.preferred))] + .[1:]' "$VERSIONS_JSON"
Copy link
Preview

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The complex inline yq command impacts readability and maintainability; consider refactoring parts into intermediate variables or adding inline comments to clarify its intent.

Suggested change
yq -p=json -o=json -i '. = [{"preferred": "true", "url": "../'"${NEW_VERSION}"'", "version": "'"${NEW_VERSION}"'"}] + [(.[0] | del(.preferred))] + .[1:]' "$VERSIONS_JSON"
echo "Preparing new version entry for $VERSIONS_JSON..."
NEW_VERSION_ENTRY='[{"preferred": "true", "url": "../'"${NEW_VERSION}"'", "version": "'"${NEW_VERSION}"'"}]'
REMOVE_PREFERRED='[(.[0] | del(.preferred))]'
REMAINING_ENTRIES='.[1:]'
# Update the versions.json file with the new version entry
yq -p=json -o=json -i ". = ${NEW_VERSION_ENTRY} + ${REMOVE_PREFERRED} + ${REMAINING_ENTRIES}" "$VERSIONS_JSON"

Copilot uses AI. Check for mistakes.

if [[ $? -ne 0 ]]; then
echo "Error: Failed to update $VERSIONS_JSON"
exit 1
fi
fi

# Update version in repo.toml using sed
echo "Updating version in repo.toml..."
# Remove quotes from current version for sed
CURRENT_VERSION=${CURRENT_VERSION//\"/}
if [[ $(uname) == "Darwin" ]]; then
# macOS requires an empty string for -i
sed -i '' "s/version = \"${CURRENT_VERSION}\"/version = \"${NEW_VERSION}\"/" repo.toml
else
# Linux version of sed
sed -i "s/version = \"${CURRENT_VERSION}\"/version = \"${NEW_VERSION}\"/" repo.toml
fi

if [[ $? -ne 0 ]]; then
echo "Error: Failed to update repo.toml"
exit 1
fi

echo "Successfully updated version to ${NEW_VERSION} for ${COMPONENT}"