From 34b3aac2e325ffff2929682706bbe24f7e2ee79e Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Sat, 24 Aug 2024 14:21:58 +0800 Subject: [PATCH] Bump and publish `ostd-test` and `ostd-macros` --- .github/workflows/publish_osdk_and_ostd.yml | 52 ++----------- Cargo.lock | 4 +- osdk/Cargo.lock | 2 +- ostd/Cargo.toml | 4 +- ostd/libs/ostd-macros/Cargo.toml | 2 +- ostd/libs/ostd-test/Cargo.toml | 2 +- tools/bump_version.sh | 24 +++--- .../github_workflows/publish_osdk_and_ostd.sh | 78 +++++++++++++++++++ 8 files changed, 106 insertions(+), 62 deletions(-) create mode 100755 tools/github_workflows/publish_osdk_and_ostd.sh diff --git a/.github/workflows/publish_osdk_and_ostd.yml b/.github/workflows/publish_osdk_and_ostd.yml index 32f3c8b46..8a6d28996 100644 --- a/.github/workflows/publish_osdk_and_ostd.yml +++ b/.github/workflows/publish_osdk_and_ostd.yml @@ -13,62 +13,22 @@ on: - VERSION jobs: - osdk-publish: + publish: runs-on: ubuntu-latest timeout-minutes: 10 container: asterinas/asterinas:0.8.0 steps: - uses: actions/checkout@v4 - - name: Check Publish OSDK - # On pull request, set `--dry-run` to check whether OSDK can publish + - name: Publish OSTD and OSDK (dry run) + # On pull request, set `--dry-run` to check whether they can be published if: github.event_name == 'pull_request' run: | - cd osdk - cargo publish --dry-run - - - name: Publish OSDK - # On push, OSDK will be published - if: github.event_name == 'push' - env: - REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run: | - cd osdk - cargo publish --token ${REGISTRY_TOKEN} - - ostd-publish: - runs-on: ubuntu-latest - timeout-minutes: 10 - container: asterinas/asterinas:0.8.0 - strategy: - matrix: - # All supported targets, this array should keep consistent with - # `package.metadata.docs.rs.targets` in `ostd/Cargo.toml` - target: ['x86_64-unknown-none'] - steps: - - uses: actions/checkout@v4 - - - name: Check Publish OSTD and the test runner - # On pull request, set `--dry-run` to check whether OSDK can publish - if: github.event_name == 'pull_request' - run: | - cd ostd - cargo publish --target ${{ matrix.target }} --dry-run - cargo doc --target ${{ matrix.target }} - cd osdk/test-kernel - cargo publish --target ${{ matrix.target }} --dry-run - cargo doc --target ${{ matrix.target }} + ./tools/github_workflows/publish_osdk_and_ostd.sh --dry-run - - name: Publish OSTD and the test runner + - name: Publish OSTD and OSDK if: github.event_name == 'push' env: REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - # Using any target that OSTD supports for publishing is ok. - # Here we use the same target as - # `package.metadata.docs.rs.default-target` in `ostd/Cargo.toml`. run: | - cd ostd - cargo publish --target x86_64-unknown-none --token ${REGISTRY_TOKEN} - cd osdk/test-kernel - cargo publish --target x86_64-unknown-none --token ${REGISTRY_TOKEN} - \ No newline at end of file + ./tools/github_workflows/publish_osdk_and_ostd.sh --token ${REGISTRY_TOKEN} diff --git a/Cargo.lock b/Cargo.lock index 57ad547f9..ccdf7c554 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,7 +1088,7 @@ dependencies = [ [[package]] name = "ostd-macros" -version = "0.1.4" +version = "0.8.0" dependencies = [ "proc-macro2", "quote", @@ -1116,7 +1116,7 @@ dependencies = [ [[package]] name = "ostd-test" -version = "0.1.0" +version = "0.8.0" [[package]] name = "owo-colors" diff --git a/osdk/Cargo.lock b/osdk/Cargo.lock index 6ee3668a0..cdc23e420 100644 --- a/osdk/Cargo.lock +++ b/osdk/Cargo.lock @@ -146,7 +146,7 @@ dependencies = [ [[package]] name = "cargo-osdk" -version = "0.7.0" +version = "0.8.0" dependencies = [ "assert_cmd", "clap", diff --git a/ostd/Cargo.toml b/ostd/Cargo.toml index e232964a9..6fa985a15 100644 --- a/ostd/Cargo.toml +++ b/ostd/Cargo.toml @@ -34,8 +34,8 @@ log = "0.4" num = { version = "0.4", default-features = false } num-derive = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false } -ostd-macros = { path = "libs/ostd-macros", version = "0.1.4" } -ostd-test = { path = "libs/ostd-test", version = "0.1.0" } +ostd-macros = { version = "0.8.0", path = "libs/ostd-macros" } +ostd-test = { version = "0.8.0", path = "libs/ostd-test" } owo-colors = { version = "3", optional = true } ostd-pod = { git = "https://github.com/asterinas/ostd-pod", rev = "c4644be", version = "0.1.1" } spin = "0.9.4" diff --git a/ostd/libs/ostd-macros/Cargo.toml b/ostd/libs/ostd-macros/Cargo.toml index 816b8e058..16a69e931 100644 --- a/ostd/libs/ostd-macros/Cargo.toml +++ b/ostd/libs/ostd-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ostd-macros" -version = "0.1.4" +version = "0.8.0" edition = "2021" description = "OSTD's proc macros" license = "MPL-2.0" diff --git a/ostd/libs/ostd-test/Cargo.toml b/ostd/libs/ostd-test/Cargo.toml index 5b8e6f949..734bfe663 100644 --- a/ostd/libs/ostd-test/Cargo.toml +++ b/ostd/libs/ostd-test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ostd-test" -version = "0.1.0" +version = "0.8.0" edition = "2021" description = "The kernel mode unit testing framework of OSTD" license = "MPL-2.0" diff --git a/tools/bump_version.sh b/tools/bump_version.sh index 410fcb63c..7f0fa9ff8 100755 --- a/tools/bump_version.sh +++ b/tools/bump_version.sh @@ -20,11 +20,11 @@ update_package_version() { sed -i "0,/${pattern}/s/${pattern}/version = \"${new_version}\"/1" $1 } -# Update the version of the `ostd` dependency (`ostd = { version = "", ...`) in file $1 -update_ostd_dep_version() { - echo "Updating file $1" - pattern="^ostd = { version = \"[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\"" - sed -i "0,/${pattern}/s/${pattern}/ostd = { version = \"${new_version}\"/1" $1 +# Update the version of the $2 dependency (`$2 = { version = "", ...`) in file $1 +update_dep_version() { + echo "Updating the version of $2 in file $1" + pattern="^$2 = { version = \"[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\"" + sed -i "0,/${pattern}/s/${pattern}/$2 = { version = \"${new_version}\"/1" $1 } # Update Docker image versions (`asterinas/asterinas:{version}`) in file $1 @@ -104,8 +104,10 @@ SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) ASTER_SRC_DIR=${SCRIPT_DIR}/.. DOCS_DIR=${ASTER_SRC_DIR}/docs OSTD_CARGO_TOML_PATH=${ASTER_SRC_DIR}/ostd/Cargo.toml +OSTD_TEST_CARGO_TOML_PATH=${ASTER_SRC_DIR}/ostd/libs/ostd-test/Cargo.toml +OSTD_MACROS_CARGO_TOML_PATH=${ASTER_SRC_DIR}/ostd/libs/ostd-macros/Cargo.toml OSDK_CARGO_TOML_PATH=${ASTER_SRC_DIR}/osdk/Cargo.toml -OSTD_TEST_RUNNER_CARGO_TOML_PATH=${ASTER_SRC_DIR}/osdk/test-kernel/Cargo.toml +OSDK_TEST_RUNNER_CARGO_TOML_PATH=${ASTER_SRC_DIR}/osdk/test-kernel/Cargo.toml VERSION_PATH=${ASTER_SRC_DIR}/VERSION current_version=$(cat ${VERSION_PATH}) @@ -119,11 +121,15 @@ fi validate_bump_type new_version=$(bump_version ${current_version}) -# Update the package version in Cargo.toml +# 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_dep_version ${OSTD_CARGO_TOML_PATH} ostd-test +update_dep_version ${OSTD_CARGO_TOML_PATH} ostd-macros update_package_version ${OSDK_CARGO_TOML_PATH} -update_package_version ${OSTD_TEST_RUNNER_CARGO_TOML_PATH} -update_ostd_dep_version ${OSTD_TEST_RUNNER_CARGO_TOML_PATH} +update_package_version ${OSDK_TEST_RUNNER_CARGO_TOML_PATH} +update_dep_version ${OSDK_TEST_RUNNER_CARGO_TOML_PATH} ostd # Automatically bump Cargo.lock file cargo update -p aster-nix --precise $new_version diff --git a/tools/github_workflows/publish_osdk_and_ostd.sh b/tools/github_workflows/publish_osdk_and_ostd.sh new file mode 100755 index 000000000..58b622121 --- /dev/null +++ b/tools/github_workflows/publish_osdk_and_ostd.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +# Publish OSDK and OSTD to crates.io +# +# Usage: publish_osdk_and_ostd.sh [--dry-run | --token REGISTRY_TOKEN] + +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +ASTER_SRC_DIR=${SCRIPT_DIR}/../.. + +# Print help message +print_help() { + echo "Usage: $0 [--dry-run | --token REGISTRY_TOKEN]" + echo "" + echo "Options:" + echo " --dry-run: Execute the publish check without actually publishing it." + echo " --token REGISTRY_TOKEN: The token to authenticate with crates.io." +} + +# Parse the parameters +DRY_RUN="" +TOKEN="" +while [ "$#" -gt 0 ]; do + case "$1" in + --dry-run) + DRY_RUN="true" + shift + ;; + --token) + TOKEN="$2" + shift 2 + ;; + *) + echo "Error: Invalid parameter: $1" + print_help + exit 1 + ;; + esac +done + +# Performs the publish check or publish the crate in directory $1, with +# optional target $2. If the target is not specified, cargo will decide +# the target automatically. +do_publish_for() { + pushd $ASTER_SRC_DIR/$1 + TARGET_ARGS="" + if [ -n "$2" ]; then + TARGET_ARGS="--target $2" + fi + if [ -n "$DRY_RUN" ]; then + cargo publish --dry-run $TARGET_ARGS + cargo doc $TARGET_ARGS + else + cargo publish --token $TOKEN $TARGET_ARGS + fi + popd +} + +do_publish_for osdk + +# All supported targets of OSTD, this array should keep consistent with +# `package.metadata.docs.rs.targets` in `ostd/Cargo.toml`. +TARGETS="x86_64-unknown-none" +for TARGET in $TARGETS; do + do_publish_for ostd/libs/ostd-macros $TARGET + do_publish_for ostd/libs/ostd-test $TARGET + do_publish_for ostd $TARGET + do_publish_for osdk/test-kernel $TARGET + + # For actual publishing, we should only publish once. Using any target that + # OSTD supports is OK. Here we use the first target in the list. + if [ -z "$DRY_RUN" ]; then + break + fi +done