Skip to content

Commit b8a8f48

Browse files
author
developerworks
committed
强化发布脚本非交互执行
1 parent d6319c7 commit b8a8f48

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

scripts/release.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/usr/bin/env bash
2+
3+
if [ -z "${BASH_VERSION:-}" ]; then
4+
echo "release.sh must be run with bash; use scripts/release.sh or bash scripts/release.sh" >&2
5+
exit 2
6+
fi
7+
28
set -euo pipefail
39

410
# Runs the same local gates used before publishing, then optionally commits,
@@ -10,6 +16,19 @@ DRY_RUN=1
1016
WAIT_PAGES=1
1117
COMMIT_MESSAGE=""
1218

19+
export GIT_EDITOR=true
20+
export GIT_SEQUENCE_EDITOR=true
21+
export GIT_MERGE_AUTOEDIT=no
22+
export GH_PROMPT_DISABLED=1
23+
24+
# Runs Git without opening an editor or interactive prompts.
25+
git_cmd() {
26+
git \
27+
-c core.editor=true \
28+
-c sequence.editor=true \
29+
"$@"
30+
}
31+
1332
# Prints release script usage.
1433
usage() {
1534
cat <<'EOF'
@@ -64,7 +83,7 @@ done
6483
cd "${ROOT_DIR}"
6584

6685
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
67-
BRANCH="$(git branch --show-current)"
86+
BRANCH="$(git_cmd branch --show-current)"
6887

6988
if [[ -z "${COMMIT_MESSAGE}" ]]; then
7089
COMMIT_MESSAGE="Release ${VERSION}"
@@ -80,7 +99,7 @@ scripts/publish-crate.sh --prepare-only --allow-dirty
8099
cargo fmt --check
81100
cargo clippy --all-targets --all-features -- -D warnings
82101
cargo test
83-
git diff --check
102+
git_cmd diff --check
84103

85104
if ((DRY_RUN)); then
86105
scripts/publish-crate.sh --dry-run --allow-dirty --no-bump
@@ -89,14 +108,14 @@ if ((DRY_RUN)); then
89108
exit 0
90109
fi
91110

92-
if [[ -n "$(git status --porcelain)" ]]; then
93-
git add -A
94-
git -c core.editor=true commit -m "${COMMIT_MESSAGE}"
111+
if [[ -n "$(git_cmd status --porcelain)" ]]; then
112+
git_cmd add -A
113+
git_cmd commit --no-edit -m "${COMMIT_MESSAGE}"
95114
else
96115
echo "working tree is clean; no commit created"
97116
fi
98117

99-
git push
118+
git_cmd push
100119

101120
if ((WAIT_PAGES)); then
102121
if command -v gh >/dev/null 2>&1; then

0 commit comments

Comments
 (0)