|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) godot-rust; Bromeon and contributors. |
| 3 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | +# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 6 | + |
| 7 | +# Small utility to run update crate versions, used by godot-rust developers. |
| 8 | + |
| 9 | +# No args specified: do everything. |
| 10 | +if [ "$#" -eq 0 ]; then |
| 11 | + echo "Usage: update-version.sh <newVersion>" |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +# --help menu |
| 16 | +args=("$@") |
| 17 | +for arg in "${args[@]}"; do |
| 18 | + if [ "$arg" == "--help" ]; then |
| 19 | + echo "Usage: update-version.sh <newVersion>" |
| 20 | + echo "" |
| 21 | + echo "Replaces currently published version with <newVersion>". |
| 22 | + echo "Does not git commit." |
| 23 | + exit 0 |
| 24 | + fi |
| 25 | +done |
| 26 | + |
| 27 | +# Uncommitted changes, see https://stackoverflow.com/a/3879077. |
| 28 | +#if git diff --quiet --exit-code; then |
| 29 | +git diff-index --quiet HEAD -- || { |
| 30 | + echo "Repo contains uncommitted changes; make sure working tree is clean." |
| 31 | + exit 1 |
| 32 | +} |
| 33 | + |
| 34 | +# https://stackoverflow.com/a/11114547 |
| 35 | +scriptFile=$(realpath "$0") |
| 36 | +scriptPath=$(dirname "$scriptFile") |
| 37 | +mainCargoToml="$scriptPath/../../godot/Cargo.toml" |
| 38 | + |
| 39 | +newVersion="${args[0]}" |
| 40 | +oldVersion=$(grep -Po '^version = "\K[^"]*' "$mainCargoToml") |
| 41 | + |
| 42 | +publishedCrates=( |
| 43 | + "godot-bindings" |
| 44 | + "godot-codegen" |
| 45 | + "godot-ffi" |
| 46 | + "godot-cell" |
| 47 | + "godot-core" |
| 48 | + "godot-macros" |
| 49 | + "godot" |
| 50 | +) |
| 51 | + |
| 52 | +for crate in "${publishedCrates[@]}"; do |
| 53 | + # Don't just replace version string itself -- the following only replaces the crate's own version |
| 54 | + # (with 'version = "1.2.3"') and dependencies with "=1.2.3", which makes false positives unlikely |
| 55 | + sed -i "s!version = \"${oldVersion}\"!version = \"${newVersion}\"!g" "$scriptPath/../../$crate/Cargo.toml" || exit 2 |
| 56 | + sed -i "s!\"=${oldVersion}\"!\"=${newVersion}\"!g" "$scriptPath/../../$crate/Cargo.toml" || exit 2 |
| 57 | +done |
| 58 | + |
| 59 | +# For `godot` itself, update the `documentation` metadata. |
| 60 | +sed -i "s!documentation = \"https://docs.rs/godot/$oldVersion\"!documentation = \"https://docs.rs/godot/$newVersion\"!g" "$mainCargoToml" || exit 2 |
| 61 | + |
| 62 | +git commit -am "Update crate version: $oldVersion -> $newVersion" || exit 2 |
| 63 | +git tag "$newVersion" || exit 2 |
| 64 | + |
| 65 | +echo "SUCCESS: Updated version $oldVersion -> $newVersion" |
0 commit comments