-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·381 lines (307 loc) · 12.3 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·381 lines (307 loc) · 12.3 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/bin/bash
# release.sh - Script for easier_drop build/release
# Usage: ./release.sh [--deploy]
set -e # Stop on error
# Output Colors and styles
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Helper for nice headers
print_header() {
echo -e "\n${BOLD}${BLUE}=== $1 ===${NC}"
}
# Configuration
APP_NAME="Easier Drop"
APP_BUNDLE_NAME="Easier Drop.app" # Final Production App Name
DEBUG_APP_NAME="Easier Drop (Debug).app" # Final Debug App Name
BUILD_OUTPUT_DIR="$(pwd)/build/app"
PROJECT_ROOT="$(pwd)"
echo -e "${GREEN}🚀 Starting release process for ${BOLD}${APP_NAME}${NC}"
echo -e "${YELLOW}📍 Project Root: $PROJECT_ROOT${NC}"
# Parse arguments
DEPLOY=false
while [[ $# -gt 0 ]]; do
case $1 in
--deploy)
DEPLOY=true
shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
# 1. READ VERSION FROM pubspec.yaml
print_header "1. Configuration"
echo -e "📖 Reading version from pubspec.yaml..."
VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}' | sed 's/+.*//' | sed 's/^/v/')
if [[ -z "$VERSION" ]]; then
echo -e "${RED}❌ Error: version not found in pubspec.yaml${NC}"
exit 1
fi
echo -e "✅ Detected version: ${BOLD}${GREEN}${VERSION}${NC}"
# 2. CLEAN & SETUP
print_header "2. Environment Setup"
echo -e "🧹 Cleaning project..."
flutter clean > /dev/null
echo -e "📦 Getting dependencies..."
flutter pub get > /dev/null
# Prepare output directory (FLAT STRUCTURE)
rm -rf "$BUILD_OUTPUT_DIR"
mkdir -p "$BUILD_OUTPUT_DIR"
# 2.1 LOAD ENV VARS
echo -e "🔑 Loading environment variables..."
DART_DEFINES=""
if [ -f .env ]; then
while IFS='=' read -r key value; do
# Skip comments and empty lines
if [[ ! $key =~ ^# && -n $key ]]; then
# Trim whitespace
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
DART_DEFINES="$DART_DEFINES --dart-define=$key=$value"
fi
done < .env
echo -e "✅ Environment variables loaded."
else
echo -e "${YELLOW}⚠️ .env file not found. Building without secrets.${NC}"
fi
# 3. BUILD DEBUG
print_header "3. Building DEBUG Version"
echo -e "⚙️ Compiling..."
flutter build macos --debug $DART_DEFINES > /dev/null
DEBUG_SRC="build/macos/Build/Products/Debug/easier_drop.app"
if [[ -d "$DEBUG_SRC" ]]; then
cp -R "$DEBUG_SRC" "$BUILD_OUTPUT_DIR/$DEBUG_APP_NAME"
echo -e "${GREEN}✅ Debug app built.${NC}"
else
echo -e "${RED}❌ Error: Debug build failed (app not found).${NC}"
exit 1
fi
# 4. BUILD RELEASE (Obfuscated & Split Debug Info)
print_header "4. Building RELEASE Version (Universal Build)"
echo -e "📦 Compiling with obfuscation and split debug info..."
echo -e " This may take a minute..."
# Obfuscation and split-debug-info help reduce size
flutter build macos --release --obfuscate --split-debug-info=./build/debug-info --tree-shake-icons $DART_DEFINES
RELEASE_SRC="build/macos/Build/Products/Release/easier_drop.app"
if [[ ! -d "$RELEASE_SRC" ]]; then
echo -e "${RED}❌ Error: Release build failed (app not found).${NC}"
exit 1
fi
# Helper function to package for an arch
package_arch() {
local ARCH=$1
local SUFFIX=$2 # e.g., "arm64" or "x64" or "universal"
echo -e "\n${BOLD}🔨 Processing ${ARCH} (${SUFFIX})...${NC}"
local APP_DEST="${BUILD_OUTPUT_DIR}/${SUFFIX}/Easier Drop.app"
local ZIP_NAME="easier_drop-macos-${SUFFIX}-${VERSION}.zip"
local DMG_NAME="easier_drop-macos-${SUFFIX}-${VERSION}.dmg"
local DMG_PATH="$BUILD_OUTPUT_DIR/$DMG_NAME"
mkdir -p "${BUILD_OUTPUT_DIR}/${SUFFIX}"
cp -R "$RELEASE_SRC" "$APP_DEST"
# If specific arch requested (not universal), thin the binary
if [[ "$ARCH" != "universal" ]]; then
local BINARY="$APP_DEST/Contents/MacOS/easier_drop"
echo " 🔪 Thinning binary to $ARCH..."
lipo -thin "$ARCH" "$BINARY" -output "$BINARY" || {
echo -e "${YELLOW}⚠️ Failed to thin binary for $ARCH. It might already be single-arch.${NC}"
}
fi
# Create ZIP
echo " 🤐 Creating ZIP..."
(cd "${BUILD_OUTPUT_DIR}/${SUFFIX}" && zip -r -y "$BUILD_OUTPUT_DIR/$ZIP_NAME" "Easier Drop.app" -x "*.DS_Store") > /dev/null
# Create DMG
echo " 💿 Creating DMG..."
local DMG_STAGING="${BUILD_OUTPUT_DIR}/${SUFFIX}/dmg_temp"
rm -rf "$DMG_STAGING"
mkdir -p "$DMG_STAGING"
cp -R "$APP_DEST" "$DMG_STAGING/"
ln -s /Applications "$DMG_STAGING/Applications"
hdiutil create -volname "$APP_NAME" \
-srcfolder "$DMG_STAGING" \
-ov -format UDZO "$DMG_PATH" \
-quiet
rm -rf "$DMG_STAGING"
local SIZE=$(du -sh "$DMG_PATH" | awk '{print $1}')
echo -e "${GREEN}✅ Artifacts ready for ${SUFFIX}. DMG Size: ${SIZE}${NC}"
}
# 5. SPLIT AND PACKAGE
print_header "5. Packaging & Splitting"
# Verify if it's a universal binary
BINARY_PATH="$RELEASE_SRC/Contents/MacOS/easier_drop"
ARCHS=$(lipo -info "$BINARY_PATH")
echo -e "ℹ️ Source Architectures: ${ARCHS}"
# Always package Universal
echo -e "${YELLOW}✨ Packaging Universal Binary...${NC}"
package_arch "universal" "universal"
if [[ "$ARCHS" == *"x86_64"* && "$ARCHS" == *"arm64"* ]]; then
echo -e "${YELLOW}✨ Universal binary detected. Creating split packages...${NC}"
package_arch "arm64" "arm64"
package_arch "x86_64" "x64"
else
echo -e "${YELLOW}⚠️ Not a universal binary. Skipping splitting.${NC}"
fi
# 6. DEPLOY (Optional)
if [[ "$DEPLOY" == true ]]; then
print_header "6. Deployment (GitHub Releases)"
if ! command -v gh &> /dev/null; then
echo -e "${RED}❌ GitHub CLI (gh) not found. Install with: brew install gh${NC}"
exit 1
fi
# Check if we are in a git repo
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo -e "${RED}❌ Not a git repository.${NC}"
exit 1
fi
echo -e "📤 Committing changes..."
git add .
git commit -m "Release ${VERSION}" || echo " Nothing to commit"
git push origin main
echo -e "🏷️ Checking Tags..."
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo " ⚠️ Tag $VERSION already exists. Skipping tag creation."
else
echo " ✨ Creating tag ${VERSION}..."
git tag "$VERSION"
git push origin "$VERSION"
fi
# Extract Changelog for this version
RAW_VERSION=${VERSION#v}
echo -e "📄 Extracting changelog notes for version ${BOLD}${RAW_VERSION}${NC}..."
CHANGELOG_NOTES=$(awk "/^## \[${RAW_VERSION}\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md)
if [[ -z "$CHANGELOG_NOTES" ]]; then
echo -e "${YELLOW}⚠️ No specific notes found in CHANGELOG.md for this version. Using default.${NC}"
CHANGELOG_NOTES="Official macOS release."
else
echo -e " ✅ Clean changelog extracted."
fi
echo -e "🚀 Creating GitHub Release..."
# Collect all assets
ASSETS=()
for f in "$BUILD_OUTPUT_DIR"/*.zip "$BUILD_OUTPUT_DIR"/*.dmg; do
if [[ -f "$f" ]]; then
ASSETS+=("$f")
fi
done
gh release create "$VERSION" "${ASSETS[@]}" \
--title "${APP_NAME} ${VERSION}" \
--generate-notes \
--notes "
🚀 **${APP_NAME} ${VERSION}**
${CHANGELOG_NOTES}
## 📦 Downloads
| Architecture | DMG Installer | ZIP Portable |
|:---:|:---:|:---:|
| **Universal (Standard)** | [Download](https://github.com/victorcmarinho/EasierDrop/releases/download/${VERSION}/easier_drop-macos-universal-${VERSION}.dmg) | [ZIP](https://github.com/victorcmarinho/EasierDrop/releases/download/${VERSION}/easier_drop-macos-universal-${VERSION}.zip) |
| **Apple Silicon (M1/M2/M3)** | [Download (arm64)](https://github.com/victorcmarinho/EasierDrop/releases/download/${VERSION}/easier_drop-macos-arm64-${VERSION}.dmg) | [ZIP](https://github.com/victorcmarinho/EasierDrop/releases/download/${VERSION}/easier_drop-macos-arm64-${VERSION}.zip) |
| **Intel** | [Download (x64)](https://github.com/victorcmarinho/EasierDrop/releases/download/${VERSION}/easier_drop-macos-x64-${VERSION}.dmg) | [ZIP](https://github.com/victorcmarinho/EasierDrop/releases/download/${VERSION}/easier_drop-macos-x64-${VERSION}.zip) |
---
*Built with Flutter*
"
echo -e "${GREEN}🎉 Release published successfully!${NC}"
echo -e " 🔗 URL: https://github.com/victorcmarinho/EasierDrop/releases/tag/${VERSION}"
# --- HOMEBREW CASK UPDATE ---
print_header "6.1 Update Homebrew Cask"
UNIV_DMG=$(find "$BUILD_OUTPUT_DIR" -name "*universal*.dmg" | head -n 1)
CASK_FILE="Casks/easier-drop.rb"
if [[ -f "$UNIV_DMG" && -f "$CASK_FILE" ]]; then
echo -e "🍺 Updating Homebrew Cask..."
# Calculate SHA256
SHA256=$(shasum -a 256 "$UNIV_DMG" | awk '{print $1}')
echo -e " 🔑 SHA256: $SHA256"
# Update Cask File
CLEAN_VERSION=${VERSION#v}
sed -i '' "s/version \".*\"/version \"$CLEAN_VERSION\"/" "$CASK_FILE"
sed -i '' "s/sha256 :no_check/sha256 \"$SHA256\"/" "$CASK_FILE" || true
sed -i '' "s/sha256 \".*\"/sha256 \"$SHA256\"/" "$CASK_FILE"
echo -e " ✅ Cask updated to version $CLEAN_VERSION with new SHA256."
# Commit Cask change
git add "$CASK_FILE"
git commit -m "Update Homebrew Cask to $VERSION" || echo " ⚠️ Nothing to commit for Cask."
git push origin main
echo -e " 📤 Cask changes pushed to repository."
else
echo -e "${YELLOW}⚠️ Could not update Cask. Missing DMG or Cask file.${NC}"
fi
# --- DOCS UPDATE ---
print_header "6.2 Update Website Docs"
DOCS_FILE="docs/index.html"
if [[ -f "$DOCS_FILE" ]]; then
echo -e "🌐 Updating Website Version..."
# Replace "Download vX.X.X" with new version
CLEAN_VERSION=${VERSION#v}
sed -i '' "s/Download v[0-9.]*/Download v$CLEAN_VERSION/" "$DOCS_FILE"
echo -e " ✅ website updated to v$CLEAN_VERSION."
git add "$DOCS_FILE"
git commit -m "Update docs version to $VERSION" || echo " ⚠️ Nothing to commit for Docs."
git push origin main
fi
else
print_header "6. Deployment Skipped"
echo -e "${YELLOW}ℹ️ To publish to GitHub, use: ./release.sh --deploy${NC}"
fi
print_header "🏁 Build Summary"
echo -e "${GREEN}✨ Process finished successfully!${NC}"
echo -e "\n${BOLD}Generated Artifacts:${NC}"
printf "%-15s %-40s\n" "SIZE" "FILENAME"
echo "--------------------------------------------------------"
echo -e "\n${BOLD}Generated Artifacts:${NC}"
printf "%-15s %-40s\n" "SIZE" "FILENAME"
echo "--------------------------------------------------------"
# Function to get human readable size with decimals
get_file_size() {
local path="$1"
if [[ -d "$path" ]]; then
# Directory: use du -sk (KB)
local kb=$(du -sk "$path" | awk '{print $1}')
echo "$kb" | awk '{ printf "%.2f MB", $1/1024 }'
elif [[ -f "$path" ]]; then
# File: use wc -c (Bytes)
local bytes=$(wc -c < "$path")
echo "$bytes" | awk '{ printf "%.2f MB", $1/1024/1024 }'
else
echo "N/A"
fi
}
# Helper to print a specific file/dir if it exists
print_artifact() {
local path="$1"
local name="$2"
if [[ -z "$path" ]]; then return; fi
# Check if path exists (directory or file)
if [[ -e "$path" ]]; then
local size=$(get_file_size "$path")
# If no custom name provided, use basename
if [[ -z "$name" ]]; then
name=$(basename "$path")
fi
printf "%-15s %-40s\n" "$size" "$name"
fi
}
# 1. Debug App
print_artifact "$BUILD_OUTPUT_DIR/$DEBUG_APP_NAME"
# 2. App Bundles (Raw)
print_artifact "$BUILD_OUTPUT_DIR/arm64/Easier Drop.app" "Easier Drop (arm64).app"
print_artifact "$BUILD_OUTPUT_DIR/x64/Easier Drop.app" "Easier Drop (x64).app"
print_artifact "$BUILD_OUTPUT_DIR/universal/Easier Drop.app" "Easier Drop (Universal).app"
# 3. DMGs
# Find specific files to handle version changes gracefully
ARM64_DMG=$(find "$BUILD_OUTPUT_DIR" -name "*arm64*.dmg" | head -n 1)
X64_DMG=$(find "$BUILD_OUTPUT_DIR" -name "*x64*.dmg" | head -n 1)
UNIV_DMG=$(find "$BUILD_OUTPUT_DIR" -name "*universal*.dmg" | head -n 1)
print_artifact "$ARM64_DMG"
print_artifact "$X64_DMG"
print_artifact "$UNIV_DMG"
# 4. ZIPs
ARM64_ZIP=$(find "$BUILD_OUTPUT_DIR" -name "*arm64*.zip" | head -n 1)
X64_ZIP=$(find "$BUILD_OUTPUT_DIR" -name "*x64*.zip" | head -n 1)
UNIV_ZIP=$(find "$BUILD_OUTPUT_DIR" -name "*universal*.zip" | head -n 1)
print_artifact "$ARM64_ZIP"
print_artifact "$X64_ZIP"
print_artifact "$UNIV_ZIP"
echo "--------------------------------------------------------"