Skip to content

Commit e707cde

Browse files
author
Nguyễn Tuấn Việt
committed
fix(publish): add --force flag + trap for safe pubspec restore
1 parent c340e96 commit e707cde

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scripts/publish.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ if command -v fvm &>/dev/null; then
3232
fi
3333

3434
DRY_FLAG=""
35+
FORCE_FLAG=""
3536
if [[ "$MODE" == "dry-run" ]]; then
3637
DRY_FLAG="--dry-run"
3738
echo "▶ DRY-RUN mode — no packages will be uploaded"
3839
else
3940
echo "▶ PUBLISH mode — packages will be uploaded to pub.dev"
4041
read -rp " Continue? [y/N] " confirm
4142
[[ "$confirm" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 1; }
43+
FORCE_FLAG="--force" # skip dart pub publish's own y/N prompt
4244
fi
4345

4446
# ── Helpers ──────────────────────────────────────────────────────────────────
@@ -106,13 +108,18 @@ publish_package() {
106108

107109
patch_pubspec "$dir"
108110

111+
# Ensure pubspec is restored even if the publish command fails or the
112+
# script is interrupted (Ctrl-C, set -e abort, etc.)
113+
trap "restore_pubspec '$dir'" EXIT
114+
109115
(
110116
cd "$dir"
111-
echo " Running: dart pub publish $DRY_FLAG"
112-
$FLUTTER pub publish $DRY_FLAG
117+
echo " Running: dart pub publish $DRY_FLAG $FORCE_FLAG"
118+
$FLUTTER pub publish $DRY_FLAG $FORCE_FLAG
113119
)
114120

115121
restore_pubspec "$dir"
122+
trap - EXIT # clear trap after successful restore
116123
}
117124

118125
# ── Static analysis first ─────────────────────────────────────────────────────

0 commit comments

Comments
 (0)