Skip to content

Commit

Permalink
Fixing release scripts 0.5.0 beta.1 (#712)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
workingjubilee and BradyBonnette authored Sep 27, 2022
1 parent ba28e5e commit 5f2579d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 49 deletions.
4 changes: 2 additions & 2 deletions publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
117 changes: 70 additions & 47 deletions update-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,86 @@

# requires:
# * ripgrep
# * Cargo extension 'cargo-edit'

if [ "x$1" == "x" ]; then
echo "usage: ./update-verions.sh <VERSION>"
if [ "$1" == "" ]; then
echo "usage: ./update-versions.sh <VERSION>"
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="(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?: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<buildmetadata>[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<prefix>^${dependency}.*\")(?P<pin>=?)${SEMVER_REGEX}(?P<postfix>\".*$)" -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<name>[-_a-z]*)"(.*\n)*' -r "\${name}" "$file")")
done
done

for cargo_toml in ${CARGO_TOMLS_TO_BUMP[@]}; do
rg --passthru -N "(?P<prefix>^version = \")${SEMVER_REGEX}(?P<postfix>\"$)" -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="(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?: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<buildmetadata>[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<prefix>^${dependency}.*\")(?P<pin>=?)${SEMVER_REGEX}(?P<postfix>\".*$)" \
-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

Expand Down

0 comments on commit 5f2579d

Please sign in to comment.