Skip to content

Commit

Permalink
Merge pull request #495 from piyush-jena/toml-copy
Browse files Browse the repository at this point in the history
scripts: Create script to copy contents from previous minor version to current
  • Loading branch information
piyush-jena authored Oct 28, 2024
2 parents 7b896f4 + 4f63370 commit f5f8cf5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/website-boiler-plate-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Script: Copy documentation from previous minor version to current minor version

This script is used to generate the data for `content/[lang]/os/[version]/` and `data/settings/[version]`. You will need to run it on every minor version before running any other script.

## Prerequisites

This script works on Linux or MacOS and is unlikely to work in Windows.

## Running the script

There is one script in this directory:

- `copy_files_from_prev_version.sh`: Copies contents from previous minor version to current minor version and removes unnecessary files. The only argument it accepts is the version (usually the latest) for which we want to copy content.

### Usage

As an example, if we want to copy the contents from 1.25 to 1.26, then, you can run the following:

```bash
./copy_files_from_prev_version.sh 1.26.0
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Path to website repository
BOTTLEROCKET_WEBSITE_REPO_DIR="$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")"

# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <version>"
exit 1
fi

VERSION="${1}"

# Check if the version format is valid (X.Y.Z)
if ! [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Expected: X.Y.Z"
exit 1
fi

MAJOR=$(echo "${VERSION}" | cut -d'.' -f1)
MINOR=$(echo "${VERSION}" | cut -d'.' -f2)
PATCH=$(echo "${VERSION}" | cut -d'.' -f3)

# Check if MINOR is 0, which is an invalid case
if [ "${MINOR}" -eq 0 ]; then
echo "Invalid version format. Minor version cannot be 0."
exit 1
fi

# Check if PATCH is not 0, which is an invalid case
if [ "${PATCH}" -ne 0 ]; then
echo "Invalid version format. Patch version must be 0. This script is only meant to copy contents for new minor version."
exit 1
fi

PREV_MINOR=$((MINOR - 1))
MAJOR_MINOR_X="${MAJOR}.${MINOR}.x"
PREV_MAJOR_MINOR_X="${MAJOR}.${PREV_MINOR}.x"

# Copy previous minor version content to the latest minor version
cp -R "${BOTTLEROCKET_WEBSITE_REPO_DIR}/content/en/os/${PREV_MAJOR_MINOR_X}/" \
"${BOTTLEROCKET_WEBSITE_REPO_DIR}/content/en/os/${MAJOR_MINOR_X}/"
cp -R "${BOTTLEROCKET_WEBSITE_REPO_DIR}/data/settings/${PREV_MAJOR_MINOR_X}/" \
"${BOTTLEROCKET_WEBSITE_REPO_DIR}/data/settings/${MAJOR_MINOR_X}/"

# Remove invalid files and folders
rm -rf "${BOTTLEROCKET_WEBSITE_REPO_DIR}/content/en/os/${MAJOR_MINOR_X}/version-information/packages/${MAJOR}.*"
rm -rf "${BOTTLEROCKET_WEBSITE_REPO_DIR}/content/en/os/${MAJOR_MINOR_X}/version-information/gpu-drivers/${MAJOR}.*"

0 comments on commit f5f8cf5

Please sign in to comment.