Skip to content

Commit

Permalink
Update scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Nov 10, 2020
1 parent 86bd7c1 commit 08bf1c5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 66 deletions.
49 changes: 25 additions & 24 deletions scripts/bump_version.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
#! /usr/bin/env bash

#
# Bumps the version number from <current> to <next> on all libraries.
# Bumps the version number to ${1}.
#

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${SCRIPT_DIR}/config.sh"

if [ -z "${1}" ] || [ -z "${2}" ]; then
echo "Usage: $0 <current> <next>"
echo "Example: $0 0.1.1 0.1.2"
if [ -z "${1}" ] ; then
echo "Usage: $0 <new-version>"
echo "Example: $0 0.6.1"
exit 1
fi

if ! git grep -c "${1}" > /dev/null; then
echo "The version '${1}' doesn't appear to be correct."
echo "Exiting."
exit 1
fi

function major() {
echo "${1}" | cut -d'.' -f1-2
function do_replace_docs() {
sd "${1}" "${2}" $(fd -t f -e toml -E '/news/*' . "${PROJECT_ROOT}")
sd "${1}" "${2}" $(fd -t f -e md -E '/news/*' . "${SITE_ROOT}")
}

function do_replace() {
find "${PROJECT_ROOT}" -name "*.rs" | xargs sed -i.bak "s/${1}/${2}/g"
find "${PROJECT_ROOT}" -name "*.toml" | xargs sed -i.bak "s/${1}/${2}/g"
find "${SITE_ROOT}" -name "*.md" | xargs sed -i.bak "s/${1}/${2}/g"
sed -i.bak "s/${1}/${2}/g" "${SCRIPT_DIR}/config.sh"
sed -i.bak "s/${1}/${2}/g" "${PROJECT_ROOT}/README.md"
function do_replace_all() {
sd "${1}" "${2}" $(fd -t f -e rs . "${PROJECT_ROOT}")
do_replace_docs "${1}" "${2}"
}

do_replace "v$(major ${1})" "v$(major ${2})"
do_replace "${1}" "${2}"

today=$(date "+%b %d, %Y")
sed -i.bak "s/^date.*/date = \"$today\"/" "${SITE_ROOT}/index.toml"
NEW_VERSION="${1}"
TODAY=$(date "+%b %d, %Y")

if $PRE_RELEASE; then
do_replace_all "/${PHYSICAL_CODENAME}" "/${CODENAME}"
do_replace_docs "${PHYSICAL_CODENAME}" "${CODENAME}"
else
NEW_CODENAME="v$(echo "${NEW_VERSION}" | cut -d'.' -f1-2)"
do_replace_all "/${VIRTUAL_CODENAME}" "/${CODENAME}"
do_replace_all "/${CODENAME}" "/${NEW_CODENAME}"
do_replace_docs "${VIRTUAL_CODENAME}" "${CODENAME}"
do_replace_docs "${CODENAME}" "${NEW_CODENAME}"
fi

find ${PROJECT_ROOT} -name "*.bak" | xargs rm
do_replace_all "${VERSION}" "${NEW_VERSION}"
sd "^date.*" "date = \"${TODAY}\"" "${SITE_ROOT}/index.toml"
78 changes: 44 additions & 34 deletions scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ function future_date() {
fi
}

# Versioning information. These are toggled as versions change.
CURRENT_RELEASE=true
PRE_RELEASE=false

# A generated codename for this version. Use the git branch for pre-releases.
case $PRE_RELEASE in
true)
VERSION_CODENAME="$(git branch --show-current)"
ROCKET_VERSION="${VERSION_CODENAME}-$(future_date)"
;;
false)
ROCKET_VERSION="0.4.5"
VERSION_CODENAME="$(echo "v${ROCKET_VERSION}" | cut -d'.' -f1-2)"
;;
esac

# Root of workspace-like directories.
PROJECT_ROOT=$(relative "") || exit $?
CORE_ROOT=$(relative "core") || exit $?
Expand All @@ -68,6 +52,26 @@ CONTRIB_CODEGEN_ROOT=$(relative "contrib/codegen") || exit $?
EXAMPLES_DIR=$(relative "examples") || exit $?
DOC_DIR=$(relative "target/doc") || exit $?

# Versioning information. These are changed as versions change.
VERSION=$(git grep -h "^version" "${CORE_LIB_ROOT}" | head -n 1 | cut -d '"' -f2)
MAJOR_VERSION=$(echo "${VERSION}" | cut -d'.' -f1-2)
VIRTUAL_CODENAME="$(git branch --show-current)"
PHYSICAL_CODENAME="v${MAJOR_VERSION}"
CURRENT_RELEASE=true
PRE_RELEASE=false

# A generated codename for this version. Use the git branch for pre-releases.
case $PRE_RELEASE in
true)
CODENAME="${VIRTUAL_CODENAME}"
DOC_VERSION="${CODENAME}-$(future_date)"
;;
false)
CODENAME="${PHYSICAL_CODENAME}"
DOC_VERSION="${VERSION}"
;;
esac

ALL_PROJECT_DIRS=(
"${CORE_HTTP_ROOT}"
"${CORE_CODEGEN_ROOT}"
Expand All @@ -76,23 +80,29 @@ ALL_PROJECT_DIRS=(
"${CONTRIB_LIB_ROOT}"
)

function print_environment() {
echo " VERSION: ${VERSION}"
echo " MAJOR_VERSION: ${MAJOR_VERSION}"
echo " CODENAME: ${CODENAME}"
echo " DOC_VERSION: ${DOC_VERSION}"
echo " CURRENT_RELEASE: ${CURRENT_RELEASE}"
echo " PRE_RELEASE: ${PRE_RELEASE}"
echo " SCRIPT_DIR: ${SCRIPT_DIR}"
echo " PROJECT_ROOT: ${PROJECT_ROOT}"
echo " CORE_ROOT: ${CORE_ROOT}"
echo " CONTRIB_ROOT: ${CONTRIB_ROOT}"
echo " SITE_ROOT: ${SITE_ROOT}"
echo " CORE_LIB_ROOT: ${CORE_LIB_ROOT}"
echo " CORE_CODEGEN_ROOT: ${CORE_CODEGEN_ROOT}"
echo " CORE_HTTP_ROOT: ${CORE_HTTP_ROOT}"
echo " CONTRIB_LIB_ROOT: ${CONTRIB_LIB_ROOT}"
echo " CONTRIB_CODEGEN_ROOT: ${CONTRIB_CODEGEN_ROOT}"
echo " EXAMPLES_DIR: ${EXAMPLES_DIR}"
echo " DOC_DIR: ${DOC_DIR}"
echo " ALL_PROJECT_DIRS: ${ALL_PROJECT_DIRS[*]}"
echo " date(): $(future_date)"
}

if [ "${1}" = "-p" ]; then
echo "ROCKET_VERSION: ${ROCKET_VERSION}"
echo "CURRENT_RELEASE: ${CURRENT_RELEASE}"
echo "PRE_RELEASE: ${PRE_RELEASE}"
echo "VERSION_CODENAME: ${VERSION_CODENAME}"
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
echo "PROJECT_ROOT: ${PROJECT_ROOT}"
echo "CORE_ROOT: ${CORE_ROOT}"
echo "CONTRIB_ROOT: ${CONTRIB_ROOT}"
echo "SITE_ROOT: ${SITE_ROOT}"
echo "CORE_LIB_ROOT: ${CORE_LIB_ROOT}"
echo "CORE_CODEGEN_ROOT: ${CORE_CODEGEN_ROOT}"
echo "CORE_HTTP_ROOT: ${CORE_HTTP_ROOT}"
echo "CONTRIB_LIB_ROOT: ${CONTRIB_LIB_ROOT}"
echo "CONTRIB_CODEGEN_ROOT: ${CONTRIB_CODEGEN_ROOT}"
echo "EXAMPLES_DIR: ${EXAMPLES_DIR}"
echo "DOC_DIR: ${DOC_DIR}"
echo "ALL_PROJECT_DIRS: ${ALL_PROJECT_DIRS[*]}"
echo "date(): $(future_date)"
print_environment
fi
2 changes: 1 addition & 1 deletion scripts/mk-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi
# Generate the rustdocs for all of the crates.
echo ":::: Generating the docs..."
pushd "${PROJECT_ROOT}" > /dev/null 2>&1
RUSTDOCFLAGS="-Z unstable-options --crate-version ${ROCKET_VERSION}" \
RUSTDOCFLAGS="-Z unstable-options --crate-version ${DOC_VERSION}" \
cargo doc -p rocket -p rocket_contrib --no-deps --all-features
popd > /dev/null 2>&1

Expand Down
2 changes: 1 addition & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function restore_dev_dependencies() {
}

if ! [ -z "$(git status --porcelain)" ]; then
echo "There are uncommited changes! Aborting."
echo "There are uncommitted changes! Aborting."
exit 1
fi

Expand Down
25 changes: 19 additions & 6 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source "${SCRIPT_DIR}/config.sh"

# Add Cargo to PATH.
export PATH=${HOME}/.cargo/bin:${PATH}
export CARGO_INCREMENTAL=0
CARGO="cargo"

# Checks that the versions for Cargo projects $@ all match
function check_versions_match() {
Expand Down Expand Up @@ -49,6 +51,15 @@ function ensure_trailing_whitespace_free() {
fi
}

if [[ $1 == +* ]]; then
CARGO="$CARGO $1"
shift
fi

echo ":: Preparing. Environment is..."
print_environment
echo " CARGO: $CARGO"

echo ":: Ensuring all crate versions match..."
check_versions_match "${ALL_PROJECT_DIRS[@]}"

Expand All @@ -59,7 +70,9 @@ echo ":: Checking for trailing whitespace..."
ensure_trailing_whitespace_free

echo ":: Updating dependencies..."
cargo update
if ! $CARGO update ; then
echo " WARNING: Update failed! Proceeding with possibly outdated deps..."
fi

if [ "$1" = "--contrib" ]; then
FEATURES=(
Expand All @@ -84,11 +97,11 @@ if [ "$1" = "--contrib" ]; then
pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1

echo ":: Building and testing contrib [default]..."
CARGO_INCREMENTAL=0 cargo test
$CARGO test

for feature in "${FEATURES[@]}"; do
echo ":: Building and testing contrib [${feature}]..."
CARGO_INCREMENTAL=0 cargo test --no-default-features --features "${feature}"
$CARGO test --no-default-features --features "${feature}"
done

popd > /dev/null 2>&1
Expand All @@ -101,15 +114,15 @@ elif [ "$1" = "--core" ]; then
pushd "${CORE_LIB_ROOT}" > /dev/null 2>&1

echo ":: Building and testing core [no features]..."
CARGO_INCREMENTAL=0 cargo test --no-default-features
$CARGO test --no-default-features

for feature in "${FEATURES[@]}"; do
echo ":: Building and testing core [${feature}]..."
CARGO_INCREMENTAL=0 cargo test --no-default-features --features "${feature}"
$CARGO test --no-default-features --features "${feature}"
done

popd > /dev/null 2>&1
else
echo ":: Building and testing libraries..."
CARGO_INCREMENTAL=0 cargo test --all-features --all $@
$CARGO test --all-features --all $@
fi

0 comments on commit 08bf1c5

Please sign in to comment.