Streamline the version bump process

This commit is contained in:
Fabing Li 2025-03-20 10:56:21 +00:00 committed by Tate, Hongliang Tian
parent 77f70831aa
commit e3e37006b0
4 changed files with 153 additions and 64 deletions

View File

@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
paths:
- VERSION
- DOCKER_IMAGE_VERSION
branches:
- main
@ -26,7 +26,7 @@ jobs:
- name: Fetch versions in the repo
id: fetch-versions
run: |
ASTER_VERSION=$(cat VERSION)
ASTER_VERSION=$(cat DOCKER_IMAGE_VERSION)
RUST_VERSION=$(grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' rust-toolchain.toml)
echo "aster_version=$ASTER_VERSION" >> "$GITHUB_OUTPUT"
echo "rust_version=$RUST_VERSION" >> "$GITHUB_OUTPUT"

View File

@ -17,7 +17,7 @@ jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10
container: asterinas/asterinas:0.14.0
container: asterinas/asterinas:$(cat asterinas/DOCKER_IMAGE_VERSION)
steps:
- uses: actions/checkout@v4

1
DOCKER_IMAGE_VERSION Normal file
View File

@ -0,0 +1 @@
0.14.0-20250320

View File

@ -38,11 +38,16 @@ update_image_versions() {
# Print the help message
print_help() {
echo "Usage: $0 bump_type"
echo "Usage: $0 <command> [options]"
echo ""
echo "The bump_type argument must be either \"patch\", \"minor\", or \"major\","
echo "which instructs the script to increment the patch, minor, and major part"
echo "of the semantic version number of Asterinas, respectively."
echo "Commands:"
echo " --docker_version_file [major|minor|patch|date] Bump the Docker image version in the DOCKER_IMAGE_VERSION file under the project root"
echo " --docker_version_refs Update all references to the Docker image version throughout the codebase"
echo " --version_file Bump the project version to match the Docker image version"
echo " --help, -h Show this help message"
echo ""
echo "The [major|minor|patch|date] options for --docker_version_file specify which part of the"
echo "Docker image version to increment. The 'date' option updates the date part of the version."
}
# Add the number $1 by 1
@ -94,6 +99,129 @@ validate_bump_type() {
esac
}
# Update Docker image version in DOCKER_IMAGE_VERSION file
update_docker_image_version() {
local IFS="-"
local docker_version_parts=($(cat ${DOCKER_IMAGE_VERSION_PATH}))
local version_part=$1
if [[ -z "$version_part" ]]; then
echo "Error: A version part (major, minor, patch, or date) must be specified."
print_help
exit 1
fi
case "$version_part" in
"major" | "minor" | "patch")
local IFS="."
local semantic_version_parts=(${docker_version_parts[0]})
if [ "$version_part" == "major" ]; then
semantic_version_parts[0]=$(add_one "${semantic_version_parts[0]}")
semantic_version_parts[1]=0
semantic_version_parts[2]=0
elif [ "$version_part" == "minor" ]; then
semantic_version_parts[1]=$(add_one "${semantic_version_parts[1]}")
semantic_version_parts[2]=0
else # patch
semantic_version_parts[2]=$(add_one "${semantic_version_parts[2]}")
fi
docker_version_parts[0]="${semantic_version_parts[*]}"
;;
"date")
docker_version_parts[1]=$(date +%Y%m%d)
;;
*)
echo "Error: Invalid version part. Allowed values are: major, minor, patch, or date."
print_help
exit 1
;;
esac
local IFS="+"
new_docker_version="${docker_version_parts[0]}-${docker_version_parts[1]}"
echo -n "${new_docker_version}" > ${DOCKER_IMAGE_VERSION_PATH}
echo "Bumped Docker image version to $new_docker_version"
}
# Update all Docker version references (except VERSION)
update_all_docker_version_refs() {
new_version=$(cat ${DOCKER_IMAGE_VERSION_PATH})
# Update Docker image versions in README files
update_image_versions ${ASTER_SRC_DIR}/README.md
update_image_versions ${ASTER_SRC_DIR}/README_CN.md
update_image_versions ${ASTER_SRC_DIR}/README_JP.md
update_image_versions ${SCRIPT_DIR}/docker/README.md
update_image_versions ${DOCS_DIR}/src/kernel/intel_tdx.md
# Update Docker image versions in workflows
WORKFLOWS=$(find "${ASTER_SRC_DIR}/.github/workflows/" -type f -name "*.yml")
for workflow in $WORKFLOWS; do
update_image_versions $workflow
done
# Update Docker image versions in the documentation
GET_STARTED_PATH=${ASTER_SRC_DIR}/docs/src/kernel/README.md
update_image_versions $GET_STARTED_PATH
}
# Update project dependencies (Cargo.toml and Cargo.lock)
update_project_dependencies() {
# Update the versions in Cargo.toml
update_package_version ${OSTD_TEST_CARGO_TOML_PATH}
update_package_version ${OSTD_MACROS_CARGO_TOML_PATH}
update_package_version ${OSTD_CARGO_TOML_PATH}
update_package_version ${LINUX_BOOT_PARAMS_CARGO_TOML_PATH}
update_package_version ${LINUX_BZIMAGE_BUILDER_CARGO_TOML_PATH}
update_package_version ${LINUX_BZIMAGE_SETUP_CARGO_TOML_PATH}
update_package_version ${OSDK_CARGO_TOML_PATH}
update_package_version ${OSDK_TEST_RUNNER_CARGO_TOML_PATH}
update_package_version ${OSDK_FRAME_ALLOCATOR_CARGO_TOML_PATH}
update_package_version ${OSDK_HEAP_ALLOCATOR_CARGO_TOML_PATH}
update_dep_version ${OSDK_TEST_RUNNER_CARGO_TOML_PATH} ostd
update_dep_version ${OSDK_FRAME_ALLOCATOR_CARGO_TOML_PATH} ostd
update_dep_version ${OSDK_HEAP_ALLOCATOR_CARGO_TOML_PATH} ostd
update_dep_version ${OSTD_CARGO_TOML_PATH} ostd-test
update_dep_version ${OSTD_CARGO_TOML_PATH} linux-boot-params
update_dep_version ${OSTD_CARGO_TOML_PATH} ostd-macros
update_dep_version ${LINUX_BZIMAGE_SETUP_CARGO_TOML_PATH} linux-boot-params
update_dep_version ${OSDK_CARGO_TOML_PATH} linux-bzimage-builder
# Automatically bump Cargo.lock files
cargo update -p aster-nix --precise $new_version # For Cargo.lock
cd osdk && cargo update -p cargo-osdk --precise $new_version # For osdk/Cargo.lock
}
# Synchronize project version to Docker version (update VERSION)
sync_project_version() {
new_version=$(cat ${DOCKER_IMAGE_VERSION_PATH} | cut -d'-' -f1)
current_version=$(cat ${VERSION_PATH})
if [ -z "$new_version" ] || [ -z "$current_version" ]; then
echo "Error: Version string is empty."
exit 1
fi
# Check if versions are equal
if [ "$new_version" = "$current_version" ]; then
echo "Versions are equal. No action needed."
exit 0
fi
# Compare semantic versions
lower_version=$(printf '%s\n' "$new_version" "$current_version" | sort -V | head -n1)
if [ "$lower_version" = "$new_version" ]; then
echo "Error: New version ($new_version) must be greater than current version ($current_version)."
exit 1
fi
update_project_dependencies
echo -n "${new_version}" > ${VERSION_PATH}
echo "Bumped Asterinas OSTD & OSDK version to $new_version"
}
# Update tag version (`v{version}`) in file $1
update_tag_version() {
echo "Updating file $1"
@ -114,66 +242,26 @@ OSDK_TEST_RUNNER_CARGO_TOML_PATH=${ASTER_SRC_DIR}/osdk/deps/test-kernel/Cargo.to
OSDK_FRAME_ALLOCATOR_CARGO_TOML_PATH=${ASTER_SRC_DIR}/osdk/deps/frame-allocator/Cargo.toml
OSDK_HEAP_ALLOCATOR_CARGO_TOML_PATH=${ASTER_SRC_DIR}/osdk/deps/heap-allocator/Cargo.toml
VERSION_PATH=${ASTER_SRC_DIR}/VERSION
DOCKER_IMAGE_VERSION_PATH=${ASTER_SRC_DIR}/DOCKER_IMAGE_VERSION
current_version=$(cat ${VERSION_PATH})
bump_type=$1
command=$1
if [[ "$bump_type" == "--help" || "$bump_type" == "-h" ]]; then
if [[ "$command" == "--help" || "$command" == "-h" ]]; then
print_help
exit 0
fi
validate_bump_type
new_version=$(bump_version ${current_version})
# Update the versions in Cargo.toml
update_package_version ${OSTD_TEST_CARGO_TOML_PATH}
update_package_version ${OSTD_MACROS_CARGO_TOML_PATH}
update_package_version ${OSTD_CARGO_TOML_PATH}
update_package_version ${LINUX_BOOT_PARAMS_CARGO_TOML_PATH}
update_package_version ${LINUX_BZIMAGE_BUILDER_CARGO_TOML_PATH}
update_package_version ${LINUX_BZIMAGE_SETUP_CARGO_TOML_PATH}
update_package_version ${OSDK_CARGO_TOML_PATH}
update_package_version ${OSDK_TEST_RUNNER_CARGO_TOML_PATH}
update_package_version ${OSDK_FRAME_ALLOCATOR_CARGO_TOML_PATH}
update_package_version ${OSDK_HEAP_ALLOCATOR_CARGO_TOML_PATH}
update_dep_version ${OSDK_TEST_RUNNER_CARGO_TOML_PATH} ostd
update_dep_version ${OSDK_FRAME_ALLOCATOR_CARGO_TOML_PATH} ostd
update_dep_version ${OSDK_HEAP_ALLOCATOR_CARGO_TOML_PATH} ostd
update_dep_version ${OSTD_CARGO_TOML_PATH} ostd-test
update_dep_version ${OSTD_CARGO_TOML_PATH} linux-boot-params
update_dep_version ${OSTD_CARGO_TOML_PATH} ostd-macros
update_dep_version ${LINUX_BZIMAGE_SETUP_CARGO_TOML_PATH} linux-boot-params
update_dep_version ${OSDK_CARGO_TOML_PATH} linux-bzimage-builder
# Automatically bump Cargo.lock files
cargo update -p aster-nix --precise $new_version # For Cargo.lock
cd osdk && cargo update -p cargo-osdk --precise $new_version # For osdk/Cargo.lock
# Update Docker image versions in README files
update_image_versions ${ASTER_SRC_DIR}/README.md
update_image_versions ${ASTER_SRC_DIR}/README_CN.md
update_image_versions ${ASTER_SRC_DIR}/README_JP.md
update_image_versions ${SCRIPT_DIR}/docker/README.md
update_image_versions ${DOCS_DIR}/src/kernel/intel_tdx.md
# Update Docker image versions in workflows
WORKFLOWS=$(find "${ASTER_SRC_DIR}/.github/workflows/" -type f -name "*.yml")
for workflow in $WORKFLOWS; do
update_image_versions $workflow
done
# Update tag version in release_tag workflow
RELEASE_TAG_WORKFLOW=${ASTER_SRC_DIR}/.github/workflows/push_git_tag.yml
update_tag_version $RELEASE_TAG_WORKFLOW
# Update Docker image versions in the documentation
GET_STARTED_PATH=${ASTER_SRC_DIR}/docs/src/kernel/README.md
update_image_versions $GET_STARTED_PATH
# Create or update VERSION
# `-n` is used to avoid adding a '\n' in the VERSION file.
echo -n "${new_version}" > ${VERSION_PATH}
echo "Bumped Asterinas OSTD & OSDK version to $new_version"
case "$command" in
"--docker_version_file")
update_docker_image_version "$2"
;;
"--docker_version_refs")
update_all_docker_version_refs
;;
"--version_file")
sync_project_version
;;
*)
echo "Warning: Using --docker_version_file, --docker_version_refs, or --version_file instead."
;;
esac