From 5f2579d987eb4a7939f9cd7365ddfd8553a5af0e Mon Sep 17 00:00:00 2001 From: Jubilee <46493976+workingjubilee@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:51:36 -0700 Subject: [PATCH] Fixing release scripts 0.5.0 beta.1 (#712) * Prerelease fixes to version scripts * update-versions.sh uses cargo-edit to update main project files * Remove dead code from update-versions.sh * Apply correctness fixes to update-versions.sh * Let the shell do the work in update-versions.sh Co-authored-by: Brady Bonnette --- publish.sh | 4 +- update-versions.sh | 117 +++++++++++++++++++++++++++------------------ 2 files changed, 72 insertions(+), 49 deletions(-) diff --git a/publish.sh b/publish.sh index b86afeb71..99a948b53 100755 --- a/publish.sh +++ b/publish.sh @@ -11,10 +11,10 @@ DIR=`pwd` set -x +cd $DIR/pgx-pg-config && cargo publish && sleep 30 cd $DIR/pgx-utils && cargo publish && sleep 30 cd $DIR/pgx-macros && cargo publish && sleep 30 cd $DIR/pgx-pg-sys && cargo publish --no-verify && sleep 30 cd $DIR/pgx && cargo publish --no-verify && sleep 30 cd $DIR/pgx-tests && cargo publish --no-verify && sleep 30 -cd $DIR/cargo-pgx && cargo publish - +cd $DIR/cargo-pgx && cargo publish # cargo-pgx last so the templates are correct diff --git a/update-versions.sh b/update-versions.sh index 4f9fe45dd..01da7b255 100755 --- a/update-versions.sh +++ b/update-versions.sh @@ -10,63 +10,86 @@ # requires: # * ripgrep +# * Cargo extension 'cargo-edit' -if [ "x$1" == "x" ]; then - echo "usage: ./update-verions.sh " +if [ "$1" == "" ]; then + echo "usage: ./update-versions.sh " exit 1 fi set -ex -HEAD=$(git rev-parse HEAD) +if ! which rg &> /dev/null; then + echo "Command \`rg\` (ripgrep) was not found. Please install it and try again." + exit 1 +fi + +if ! cargo set-version --help &> /dev/null; then + echo "Cargo extension \`cargo-edit\` is not installed. Please install it by running: cargo install cargo-edit" + exit 1 +fi + VERSION=$1 -CARGO_TOMLS_TO_BUMP=( - ./Cargo.toml - ./pgx/Cargo.toml - ./pgx-utils/Cargo.toml - ./pgx-macros/Cargo.toml - ./pgx-tests/Cargo.toml - ./cargo-pgx/Cargo.toml - ./pgx-pg-sys/Cargo.toml -) - -CARGO_TOMLS_TO_SED=( - ./cargo-pgx/src/templates/cargo_toml - ./nix/templates/default/Cargo.toml - ./pgx/Cargo.toml - ./pgx-utils/Cargo.toml - ./pgx-macros/Cargo.toml - ./pgx-tests/Cargo.toml - ./cargo-pgx/Cargo.toml - ./pgx-pg-sys/Cargo.toml - ./pgx-examples/*/Cargo.toml - ./Cargo.toml -) - -DEPENDENCIES_TO_UPDATE=( - "pgx" - "pgx-tests" - "pgx-macros" - "pgx-pg-config" - "pgx-pgx-sys" - "pgx-utils" - "cargo-pgx" -) - -SEMVER_REGEX="(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?" - -for cargo_toml in ${CARGO_TOMLS_TO_SED[@]}; do - for dependency in ${DEPENDENCIES_TO_UPDATE[@]}; do - rg --passthru -N "(?P^${dependency}.*\")(?P=?)${SEMVER_REGEX}(?P\".*$)" -r "\${prefix}=${VERSION}\${postfix}" ${cargo_toml} > ${cargo_toml}.tmp || true - mv ${cargo_toml}.tmp ${cargo_toml} +# Use `cargo set-version` to update all main project files +function update_main_files() { + local version=$1 + + EXCLUDE_PACKAGES=() + + # Add additional packages to ignore by using the following syntax: + # EXCLUDE_PACKAGES+=('foo' 'bar' 'baz') + + # Ignore all packages in pgx-examples/ + for file in ./pgx-examples/**/Cargo.toml; do + EXCLUDE_PACKAGES+=("$(rg --multiline '\[package\](.*\n)(?:[^\[]*\n)*name\s?=\s?"(?P[-_a-z]*)"(.*\n)*' -r "\${name}" "$file")") done -done -for cargo_toml in ${CARGO_TOMLS_TO_BUMP[@]}; do - rg --passthru -N "(?P^version = \")${SEMVER_REGEX}(?P\"$)" -r "\${prefix}${VERSION}\${postfix}" ${cargo_toml} > ${cargo_toml}.tmp || true - mv ${cargo_toml}.tmp ${cargo_toml} -done + echo "Excluding the following packages:" + echo "${EXCLUDE_PACKAGES[@]}" + + # shellcheck disable=2068 # allow the shell to split --exclude from each EXCLUDE_PACKAGES value + cargo set-version ${EXCLUDE_PACKAGES[@]/#/--exclude } --workspace "$version" +} + +# This is a legacy holdover for updating extra toml files throughout various crates +function update_extras() { + local version=$1 + + # ordered in a topological fashion starting from the workspace root Cargo.toml + # this isn't always necessary, but it's nice to use a mostly-consistent ordering + CARGO_TOMLS_TO_SED=( + ./Cargo.toml + ./cargo-pgx/src/templates/cargo_toml + ./nix/templates/default/Cargo.toml + ) + + DEPENDENCIES_TO_UPDATE=( + "pgx-pg-config" + "pgx-utils" + "cargo-pgx" + "pgx-macros" + "pgx-pgx-sys" + "pgx" + "pgx-tests" + ) + + SEMVER_REGEX="(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?" + + for cargo_toml in ${CARGO_TOMLS_TO_SED[@]}; do + for dependency in ${DEPENDENCIES_TO_UPDATE[@]}; do + rg --passthru --no-line-number \ + "(?P^${dependency}.*\")(?P=?)${SEMVER_REGEX}(?P\".*$)" \ + -r "\${prefix}=${version}\${postfix}" \ + ${cargo_toml} > ${cargo_toml}.tmp || true + mv ${cargo_toml}.tmp ${cargo_toml} + done + done + +} + +update_main_files $VERSION +update_extras $VERSION cargo generate-lockfile