11#! /bin/bash
22set -euo pipefail
3+ set +H # Disable history expansion to prevent '!' in content from being expanded
34
45# Optimizely Flutter SDK - Release (Step 2)
56# Publishes to pub.dev and creates GitHub release
@@ -28,22 +29,28 @@ git diff-index --quiet HEAD -- || error "Working tree has uncommitted changes"
2829PUBSPEC_VERSION=$( grep ' ^version:' pubspec.yaml | awk ' {print $2}' )
2930[[ " $PUBSPEC_VERSION " != " $VERSION " ]] && error " Version mismatch! pubspec.yaml: $PUBSPEC_VERSION , requested: $VERSION "
3031
31- # Verify authentication
32+ # Verify authentication (note: gh auth status only checks authentication, not that the
33+ # token has the required 'repo' scope needed to create releases)
3234gh auth status & > /dev/null || error " GitHub CLI not authenticated. Run: gh auth login"
3335
3436success " Pre-flight checks passed"
3537
3638# Create temporary file for dry-run output (prevents symlink attacks)
3739DRY_RUN_LOG=$( mktemp)
38- trap " rm -f ' $ DRY_RUN_LOG' " EXIT
40+ trap " rm -f \" ${ DRY_RUN_LOG} \" " EXIT
3941
4042# Dry run
4143info " Running pub publish dry-run..."
42- if ! flutter packages pub publish --dry-run 2>&1 | tee " $DRY_RUN_LOG " ; then
44+ flutter packages pub publish --dry-run 2>&1 | tee " $DRY_RUN_LOG "
45+ FLUTTER_EXIT=" ${PIPESTATUS[0]} "
46+ if [[ " $FLUTTER_EXIT " != " 0" ]]; then
4347 echo " "
44- read -p " Dry-run found warnings. Continue? (y/N) " -n 1 -r
48+ if [[ ! -t 0 ]]; then
49+ error " Dry-run found warnings. Cannot prompt in non-interactive mode. Fix warnings or run interactively."
50+ fi
51+ read -p " Dry-run found warnings. Continue? (y/N) " -r -n 1
4552 echo
46- [[ ! $REPLY =~ ^[Yy]$ ]] && error " Aborted by user"
53+ [[ ! " $REPLY " =~ ^[Yy]$ ]] && error " Aborted by user"
4754fi
4855
4956# Publish
@@ -52,10 +59,13 @@ flutter packages pub publish || error "Publishing failed"
5259success " Published to pub.dev!"
5360
5461# Extract CHANGELOG
55- # Escape VERSION for use in sed regex (prevent regex metacharacter interpretation)
62+ # Escape VERSION for use in sed regex (prevent regex metacharacter interpretation).
63+ # VERSION is already validated against ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?$ above,
64+ # so it cannot contain '|' (the alternate sed delimiter used below); escaping here
65+ # is an additional safety measure for other metacharacters.
5666ESCAPED_VERSION=$( printf ' %s\n' " $VERSION " | sed ' s/[.[\*^$()+?{|]/\\&/g' )
57- CHANGELOG_CONTENT=$( sed -n " / ^## ${ESCAPED_VERSION} \$ /,/ ^## [0-9]/ p" CHANGELOG.md | sed ' 1d;$d' )
58- [[ -z " $CHANGELOG_CONTENT " ]] && CHANGELOG_CONTENT=" Release $VERSION \n\nSee CHANGELOG.md for details."
67+ CHANGELOG_CONTENT=$( sed -n " \| ^## ${ESCAPED_VERSION} \$ |,\| ^## [0-9]| p" CHANGELOG.md | sed ' 1d;$d' )
68+ [[ -z " $CHANGELOG_CONTENT " ]] && CHANGELOG_CONTENT=$( printf ' Release %s \n\nSee CHANGELOG.md for details.' " $VERSION " )
5969
6070RELEASE_NOTES=" ## $VERSION
6171
0 commit comments