-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path.sfreleaser.pre-release.sh
More file actions
executable file
·111 lines (93 loc) · 2.9 KB
/
.sfreleaser.pre-release.sh
File metadata and controls
executable file
·111 lines (93 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
force=false
repository="github.com/streamingfast/substreams-sink-database-changes"
main() {
pushd "$ROOT" &> /dev/null
while getopts "hf" opt; do
case $opt in
h) usage && exit 0;;
f) force=true;;
\?) usage_error "Invalid option: -$OPTARG";;
esac
done
shift $((OPTIND-1))
version="$1"; shift
if [[ $version == "" ]]; then
usage_error "parameter <version> is required"
fi
version="${version#v}" # Remove leading 'v' if present
check_sd
check_git_clean
sd '^version = ".*?"$' "version = \"${version}\"" Cargo.toml
sd 'version = ".*?",' "version = \"${version}\"," Cargo.toml
sd 'version: v.*' "version: v${version}" substreams.yaml
sd '## Unreleased' "## [${version}](https://${repository}/releases/tag/v${version})" CHANGELOG.md
# Important so that the Cargo.lock file is updated with the new version
cargo test --target "$(infer_target)"
if [[ -n $(git status --porcelain) ]]; then
git add -A .
git commit -m "Preparing release of ${version}"
fi
}
check_sd() {
if ! command -v sd &> /dev/null; then
echo "ERROR: 'sd' is required but was not found on your system."
echo "Install it with:"
echo " brew install sd # macOS (Homebrew)"
echo " cargo install sd # Rust/cargo users"
echo " # Or see https://github.com/chmln/sd for more options."
exit 1
fi
}
check_git_clean() {
if [[ "$force" == true ]]; then
return
fi
if [[ -n $(git status --porcelain) ]]; then
echo "ERROR: Your git working directory is not clean. Please commit or stash your changes before running this script."
exit 1
fi
}
infer_target() {
case "$(uname -s)" in
Darwin)
if [[ "$(uname -m)" == "arm64" ]]; then
echo "aarch64-apple-darwin"
else
echo "x86_64-apple-darwin"
fi;;
Linux)
echo "$(uname -m)-unknown-linux-gnu";;
MINGW*|MSYS*|CYGWIN*)
echo "x86_64-pc-windows-msvc";;
*)
echo "$(uname -m)-unknown-linux-gnu";;
esac
}
usage_error() {
message="$1"
exit_code="$2"
echo "ERROR: $message"
echo ""
usage
exit ${exit_code:-1}
}
usage() {
echo "usage: .sfreleaser.pre-release.sh <version>"
echo ""
echo "Run the necessary pre-release tasks for updating the version of"
echo "the project in various files:"
echo ""
echo "This script will update the following files with the new version:"
echo " - Cargo.toml: Updates the 'version' field to <version>"
echo " - substreams.yaml: Updates the 'version' field to v<version>"
echo " - CHANGELOG.md: Replaces '## Unreleased' with '## <version>'"
echo ""
echo "It will also run 'cargo test' to update Cargo.lock and validate the build."
echo ""
echo "Options"
echo " -f Force the script to run even if the git working directory is not clean"
echo " -h Display help about this script"
}
main "$@"