-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpublish_plugin.sh
More file actions
executable file
Β·132 lines (115 loc) Β· 4.29 KB
/
publish_plugin.sh
File metadata and controls
executable file
Β·132 lines (115 loc) Β· 4.29 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
set -e
PLUGIN_ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$PLUGIN_ROOT"
echo "π Checking pubspec.yaml for version..."
PLUGIN_VERSION=$(grep '^version: ' pubspec.yaml | awk '{print $2}' | tr -d '\r\n')
if [ -z "$PLUGIN_VERSION" ]; then
echo "β Could not find version in pubspec.yaml"
exit 1
fi
echo "β
Version found: $PLUGIN_VERSION"
echo "π Checking if version $PLUGIN_VERSION already exists on pub.dev..."
PLUGIN_NAME=$(grep '^name: ' pubspec.yaml | awk '{print $2}' | tr -d '\r\n')
if curl -s "https://pub.dev/api/packages/$PLUGIN_NAME" | grep -q "\"version\":\"$PLUGIN_VERSION\""; then
echo "β Version $PLUGIN_VERSION is already published on pub.dev"
echo " You cannot republish the same version. Please bump the version in pubspec.yaml"
exit 1
fi
echo "β
Version $PLUGIN_VERSION is not yet published"
echo "π Verifying CHANGELOG.md contains version..."
if ! grep -Eq "##[[:space:]]*(\[?v?$PLUGIN_VERSION\]?)" CHANGELOG.md; then
echo "β CHANGELOG.md does not contain a version entry for $PLUGIN_VERSION"
echo " (Expected something like '## $PLUGIN_VERSION' or '## [v$PLUGIN_VERSION]')"
exit 1
fi
echo "β
CHANGELOG.md has an entry for version $PLUGIN_VERSION"
echo "π Checking publish_to configuration..."
if grep -q "^publish_to:[[:space:]]*['\"]none['\"]" pubspec.yaml; then
echo "β Package is marked as private (publish_to: 'none')"
echo " Remove or comment out the 'publish_to' field to publish to pub.dev"
exit 1
fi
if grep -q "^publish_to:[[:space:]]*none" pubspec.yaml; then
echo "β Package is marked as private (publish_to: none)"
echo " Remove or comment out the 'publish_to' field to publish to pub.dev"
exit 1
fi
echo "β
Package is configured for pub.dev publishing"
echo "π§ͺ Running dry-run publish..."
set +e # Temporarily disable exit on error
flutter pub publish --dry-run
DRY_RUN_EXIT=$?
set -e # Re-enable exit on error
if [ $DRY_RUN_EXIT -eq 65 ]; then
echo "β οΈ Dry-run completed with warnings (usually okay - may be due to modified files or minor issues)"
elif [ $DRY_RUN_EXIT -ne 0 ]; then
echo "β Dry-run failed with exit code $DRY_RUN_EXIT"
exit $DRY_RUN_EXIT
else
echo "β
Dry-run completed successfully"
fi
echo "π¦ Validating example project..."
if [ ! -d "example" ]; then
echo "β No example/ directory found"
exit 1
fi
cd example
flutter clean
flutter pub get
echo "π¦ Installing CocoaPods in example/ios..."
cd ios
export LANG=en_US.UTF-8
set +e # Temporarily disable exit on error
pod install
POD_EXIT=$?
set -e # Re-enable exit on error
if [ $POD_EXIT -ne 0 ]; then
echo "β οΈ CocoaPods install had issues (exit code $POD_EXIT), but continuing..."
fi
cd ..
echo "π Ready to publish version $PLUGIN_VERSION to pub.dev"
printf "Are you sure you want to publish? (y/N): "
read confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
echo "β Publishing cancelled."
exit 1
fi
cd "$PLUGIN_ROOT"
echo "π€ Publishing to pub.dev..."
set +e # Temporarily disable exit on error
flutter pub publish --force
PUBLISH_EXIT=$?
set -e # Re-enable exit on error
if [ $PUBLISH_EXIT -ne 0 ]; then
echo "β Publishing failed with exit code $PUBLISH_EXIT"
if [ $PUBLISH_EXIT -eq 65 ]; then
echo " Common issues:"
echo " - Package marked as private: Check 'publish_to' field in pubspec.yaml"
echo " - Not logged in: Run 'flutter pub login'"
echo " - Package already published: Version may already exist on pub.dev"
else
echo " Make sure you're logged in: flutter pub login"
fi
exit $PUBLISH_EXIT
fi
echo "π Tagging release with v$PLUGIN_VERSION..."
set +e # Temporarily disable exit on error
git tag "v$PLUGIN_VERSION" 2>/dev/null
TAG_EXIT=$?
set -e # Re-enable exit on error
if [ $TAG_EXIT -eq 0 ]; then
echo "β
Created tag v$PLUGIN_VERSION"
git push origin "v$PLUGIN_VERSION" || {
echo "β οΈ Failed to push tag, but you can push it manually: git push origin v$PLUGIN_VERSION"
}
elif git rev-parse "v$PLUGIN_VERSION" >/dev/null 2>&1; then
echo "β οΈ Tag v$PLUGIN_VERSION already exists, skipping tag creation"
git push origin "v$PLUGIN_VERSION" || {
echo "β οΈ Failed to push tag, but tag already exists locally"
}
else
echo "β Failed to create tag v$PLUGIN_VERSION"
exit 1
fi
echo "β
Plugin version $PLUGIN_VERSION successfully published and tagged!"