forked from cogwheel0/conduit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·172 lines (142 loc) · 4.84 KB
/
release.sh
File metadata and controls
executable file
·172 lines (142 loc) · 4.84 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
#!/bin/bash
# Conduit Mobile Release Script (CI-driven)
# Usage:
# ./scripts/release.sh [major|minor|patch]
# ./scripts/release.sh rebuild [vX.Y.Z] # Rebuild existing tag, bump build number only, update same release assets
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if we're in the right directory
if [ ! -f "pubspec.yaml" ]; then
print_error "This script must be run from the project root directory"
exit 1
fi
ACTION=${1:-patch}
if [ "$ACTION" = "rebuild" ]; then
# Rebuild path: Update existing release assets without changing the tag/version name
# Optionally accepts a tag argument; defaults to latest tag.
TAG_ARG=$2
if [ -z "$TAG_ARG" ]; then
TAG_VERSION=$(git describe --tags --abbrev=0)
else
TAG_VERSION=$TAG_ARG
fi
if [ -z "$TAG_VERSION" ]; then
print_error "No tag found. Provide an explicit tag: ./scripts/release.sh rebuild vX.Y.Z"
exit 1
fi
print_status "Rebuilding existing release for tag: $TAG_VERSION"
echo
read -p "Proceed to rebuild $TAG_VERSION and update its assets? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_warning "Rebuild cancelled"
exit 0
fi
if command -v gh >/dev/null 2>&1; then
print_status "Dispatching GitHub Actions workflow (Release) via gh CLI..."
gh workflow run "Release" \
--ref main \
-f tag="$TAG_VERSION" \
-f remove_old_assets=true
print_status "Workflow dispatched. Track progress in GitHub Actions."
else
print_warning "GitHub CLI (gh) not found. Trigger the workflow manually:"
echo "- Go to: https://github.com/$(git config --get remote.origin.url | sed -E 's#(git@|https://)([^/:]+)[:/]([^/.]+/[^.]+)(\.git)?#\2/\3#')/actions/workflows/release.yml"
echo "- Click 'Run workflow', set tag to $TAG_VERSION, and run."
fi
exit 0
fi
# Standard release path (major/minor/patch)
# Check if git is clean
if [ -n "$(git status --porcelain)" ]; then
print_error "Working directory is not clean. Please commit or stash your changes first."
exit 1
fi
# Get current version from pubspec.yaml
CURRENT_VERSION=$(grep "^version:" pubspec.yaml | sed 's/version: //')
print_status "Current version: $CURRENT_VERSION"
# Parse version components
IFS='.' read -ra VERSION_PARTS <<< "${CURRENT_VERSION%%+*}"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
# Determine release type
RELEASE_TYPE=$ACTION
case $RELEASE_TYPE in
major)
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
;;
minor)
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
;;
patch)
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
;;
*)
print_error "Invalid command. Use: major | minor | patch | rebuild [vX.Y.Z]"
exit 1
;;
esac
NEW_VERSION="$NEW_MAJOR.$NEW_MINOR.$NEW_PATCH"
TAG_VERSION="v$NEW_VERSION"
print_status "New version: $NEW_VERSION"
print_status "Tag version: $TAG_VERSION"
echo
read -p "Do you want to create release $TAG_VERSION? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_warning "Release cancelled"
exit 0
fi
# Get current build number
CURRENT_BUILD=$(echo "$CURRENT_VERSION" | awk -F'+' '{print $2}')
if [ -z "$CURRENT_BUILD" ]; then
CURRENT_BUILD=1
fi
NEW_BUILD=$((CURRENT_BUILD + 1))
# Update pubspec.yaml with new version and incremented build number
print_status "Updating pubspec.yaml to version: $NEW_VERSION+$NEW_BUILD"
sed -i.bak "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" pubspec.yaml
rm pubspec.yaml.bak
# Generate Fastlane changelogs
print_status "Generating Fastlane changelogs..."
LINK="https://github.com/cogwheel0/conduit/releases/tag/$TAG_VERSION"
# Android changelog (default only)
ANDROID_CHANGELOG_DIR="android/fastlane/metadata/android/en-US/changelogs"
mkdir -p "$ANDROID_CHANGELOG_DIR"
echo "$LINK" > "$ANDROID_CHANGELOG_DIR/default.txt"
# iOS release notes in Deliverfile
IOS_DELIVERFILE="ios/fastlane/Deliverfile"
print_status "Updating iOS Deliverfile with release notes..."
sed -i.bak "/^release_notes(/ s|'default' => \".*\"|'default' => \"$LINK\"|" "$IOS_DELIVERFILE"
rm "${IOS_DELIVERFILE}.bak"
# Commit changes
print_status "Committing changes..."
git add pubspec.yaml "$ANDROID_CHANGELOG_DIR/default.txt" "$IOS_DELIVERFILE"
git commit -m "chore: bump version to $NEW_VERSION"
git push origin main
# Create and push tag
print_status "Creating tag $TAG_VERSION..."
git tag -a "$TAG_VERSION" -m "Release $TAG_VERSION"
git push origin "$TAG_VERSION"
print_status "Release $TAG_VERSION created and pushed! CI will handle the build and GitHub release."