-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·96 lines (79 loc) · 4.05 KB
/
release.sh
File metadata and controls
executable file
·96 lines (79 loc) · 4.05 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
#!/bin/bash
set -euo pipefail
PROJECT="Preview3MF.xcodeproj/project.pbxproj"
SCHEME="Preview3MF"
PRODUCT="Preview3MF"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PBXPROJ="$SCRIPT_DIR/$PROJECT"
# ── Parse arguments ──────────────────────────────────────────────────────────
BUMP="patch" # default
DRY_RUN=false
usage() {
echo "Usage: $0 [--patch | --minor | --major] [--dry-run]"
echo ""
echo " --patch (default) 1.0.0 → 1.0.1"
echo " --minor 1.0.1 → 1.1.0"
echo " --major 1.1.0 → 2.0.0"
echo " --dry-run Show what would happen without making changes"
exit 0
}
for arg in "$@"; do
case "$arg" in
--patch) BUMP="patch" ;;
--minor) BUMP="minor" ;;
--major) BUMP="major" ;;
--dry-run) DRY_RUN=true ;;
--help|-h) usage ;;
*) echo "Unknown option: $arg"; usage ;;
esac
done
# ── Read current version ─────────────────────────────────────────────────────
CURRENT_MARKETING=$(grep -m1 'MARKETING_VERSION' "$PBXPROJ" | sed 's/.*= *//;s/ *;.*//')
CURRENT_BUILD=$(grep -m1 'CURRENT_PROJECT_VERSION' "$PBXPROJ" | sed 's/.*= *//;s/ *;.*//')
# Normalise to 3 components (e.g. "1.0" → "1.0.0")
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_MARKETING"
MAJOR=${MAJOR:-0}
MINOR=${MINOR:-0}
PATCH=${PATCH:-0}
# ── Compute new version ──────────────────────────────────────────────────────
case "$BUMP" in
patch) PATCH=$((PATCH + 1)) ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
NEW_BUILD=$((CURRENT_BUILD + 1))
TAG="v$NEW_VERSION"
echo "──────────────────────────────────────"
echo " Version : $CURRENT_MARKETING → $NEW_VERSION"
echo " Build : $CURRENT_BUILD → $NEW_BUILD"
echo " Tag : $TAG"
echo " Bump : $BUMP"
echo "──────────────────────────────────────"
if $DRY_RUN; then
echo "(dry run — exiting)"
exit 0
fi
# ── Ensure clean working tree (aside from this script itself) ────────────────
if ! git -C "$SCRIPT_DIR" diff --quiet -- . ':!release.sh' || \
! git -C "$SCRIPT_DIR" diff --cached --quiet; then
echo "Error: You have uncommitted changes. Please commit or stash them first."
exit 1
fi
# ── Bump versions in pbxproj ─────────────────────────────────────────────────
sed -i '' "s/MARKETING_VERSION = .*;/MARKETING_VERSION = $NEW_VERSION;/g" "$PBXPROJ"
sed -i '' "s/CURRENT_PROJECT_VERSION = .*;/CURRENT_PROJECT_VERSION = $NEW_BUILD;/g" "$PBXPROJ"
echo "✓ Updated pbxproj"
# ── Commit & tag ─────────────────────────────────────────────────────────────
git -C "$SCRIPT_DIR" add "$PBXPROJ"
git -C "$SCRIPT_DIR" commit -m "Bump version to $NEW_VERSION (build $NEW_BUILD)"
git -C "$SCRIPT_DIR" tag -a "$TAG" -m "Release $TAG"
echo "✓ Committed and tagged $TAG"
# ── Push ─────────────────────────────────────────────────────────────────────
git -C "$SCRIPT_DIR" push origin main
git -C "$SCRIPT_DIR" push origin "$TAG"
REPO_URL=$(git -C "$SCRIPT_DIR" remote get-url origin | sed 's/\.git$//;s|git@github.com:|https://github.com/|')
echo "✓ Pushed to origin"
echo ""
echo "GitHub Actions will build and create the release automatically."
echo " $REPO_URL/actions"