forked from silexlabs/Silex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·210 lines (182 loc) · 5.97 KB
/
release.sh
File metadata and controls
executable file
·210 lines (182 loc) · 5.97 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
#!/bin/bash
# release.sh
# Sript to release packages in the Silex monorepo based on npm workspaces and git submodules.
# This script automates the process of updating internal dependencies, bumping versions, and pushing changes to the repository.
# Usage:
# ./scripts/release.sh [--release] [--dry-run]
# Options:
# --release: Perform a release (default is prerelease)
# --dry-run: Simulate the release process without making any changes
# --help: Show this help message
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
RELEASE=false
DRY_RUN=false
for arg in "$@"; do
case "$arg" in
--release) RELEASE=true ;;
--dry-run) DRY_RUN=true ;;
--h|--help)
echo "Usage: $0 [--release] [--dry-run]"
echo "Options:"
echo " --release: Perform a release (default is prerelease)"
echo " --dry-run: Simulate the release process without making any changes"
exit 0
;;
*)
echo "Unknown argument: $arg"
echo "Usage: $0 [--release] [--dry-run]"
echo "Options:"
echo " --release: Perform a release (default is prerelease)"
echo " --dry-run: Simulate the release process without making any changes"
exit 1
;;
esac
done
echo "🔍 Mode: $([[ $RELEASE == true ]] && echo "RELEASE" || echo "PRERELEASE")"
echo "🔍 Dry run: $([[ $DRY_RUN == true ]] && echo "YES" || echo "NO")"
echo ""
# Check for dirty packages
echo "🔎 Validating working directory status for all packages..."
DIRTY_PACKAGES=()
for dir in packages/*; do
[ -e "$dir/.git" ] || continue
if [ -n "$(cd "$dir" && git status --porcelain)" ]; then
DIRTY_PACKAGES+=("$dir")
fi
done
if [ ${#DIRTY_PACKAGES[@]} -gt 0 ]; then
echo "❌ Some packages have uncommitted changes:"
for p in "${DIRTY_PACKAGES[@]}"; do
echo " - $p"
done
echo ""
echo "🛑 Please commit or stash these changes before running the release."
exit 1
fi
echo "✅ All packages clean"
echo ""
ERRORS=()
SKIPPED=()
UPDATED=()
INTERNAL_PACKAGE_NAMES=($(find packages -mindepth 1 -maxdepth 1 -type d -exec jq -r .name {}/package.json \;))
PACKAGE_PATHS=($(./scripts/sort-internal-deps.js | grep '^-' | sed 's/^- //' | xargs -n1))
for pkg_dir in "${PACKAGE_PATHS[@]}"; do
dir="packages/$pkg_dir"
[ -f "$dir/package.json" ] || continue
cd "$dir"
echo "📦 Processing $pkg_dir"
CURRENT_VERSION=$(jq -r .version package.json)
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
HAS_NEW_COMMITS=false
if [ -n "$LAST_TAG" ] && [ -n "$(git rev-list "$LAST_TAG"..HEAD)" ]; then
HAS_NEW_COMMITS=true
fi
# Update internal deps
OUTDATED=$(npx -y npm-check-updates --dep prod,dev,peer --target=greatest || true)
INTERNAL_LINES=()
INTERNAL_UPGRADE_LIST=()
while IFS= read -r line; do
dep=$(echo "$line" | awk '{print $1}' | xargs)
if [[ " ${INTERNAL_PACKAGE_NAMES[*]} " =~ " $dep " ]]; then
echo " ✨ $line"
INTERNAL_LINES+=("$line")
INTERNAL_UPGRADE_LIST+=("$dep")
fi
done <<< "$OUTDATED"
UPDATED_INTERNAL_DEPS=false
if [[ ${#INTERNAL_UPGRADE_LIST[@]} -gt 0 ]]; then
UPDATED_INTERNAL_DEPS=true
if $DRY_RUN; then
echo " 🧪 (dry-run) Would update internal deps: ${INTERNAL_UPGRADE_LIST[*]}"
else
echo " 🔧 Updating internal deps..."
npx -y npm-check-updates --dep prod,dev,peer --target=greatest --upgrade "${INTERNAL_UPGRADE_LIST[@]}"
npm install --package-lock-only --workspaces false
git add package.json package-lock.json
git commit -m "chore: update internal dependencies in $pkg_dir"
git push
fi
else
echo " ✅ No internal dependencies to update."
fi
# Re-check for new commits after dependency update
HAS_NEW_COMMITS=false
if [ -n "$LAST_TAG" ] && [ -n "$(git rev-list "$LAST_TAG"..HEAD)" ]; then
HAS_NEW_COMMITS=true
fi
# Determine if version bump needed
SHOULD_BUMP=false
if $RELEASE && [[ "$CURRENT_VERSION" == *-* ]]; then
SHOULD_BUMP=true
elif $HAS_NEW_COMMITS; then
SHOULD_BUMP=true
fi
if ! $SHOULD_BUMP; then
echo " ✅ No version bump needed. Skipping."
SKIPPED+=("$pkg_dir")
cd "$REPO_ROOT"
echo ""
continue
fi
if $RELEASE; then
# Mode release (stable)
if [[ "$CURRENT_VERSION" == *-* ]]; then
# On est sur une prerelease, on veut juste la version stable sans le suffixe
STABLE_VERSION=$(echo "$CURRENT_VERSION" | sed 's/-[0-9]*$//')
CMD="npm version $STABLE_VERSION -m 'chore: release %s'"
else
# On est déjà sur une version stable, incrémenter le minor
CMD="npm version minor -m 'chore: release %s'"
fi
else
# Mode prerelease
if [[ "$CURRENT_VERSION" == *-* ]]; then
# On est déjà sur une prerelease, incrémenter le suffixe
CMD="npm version prerelease --preid=canary -m 'chore: prerelease %s'"
else
# On est sur une version stable, incrémenter le minor + ajouter -0
CMD="npm version preminor --preid=canary -m 'chore: prerelease %s'"
fi
fi
if $DRY_RUN; then
echo " 🧪 (dry-run) Would run: $CMD"
echo " 🧪 (dry-run) Would push + tag"
NEW_VERSION=$(jq -r .version package.json)
else
echo " 🚀 Bumping version..."
eval "$CMD"
NEW_VERSION=$(jq -r .version package.json)
git push
git push --tags
PACKAGE_NAME=$(jq -r .name package.json)
echo ""
echo "🛑 Waiting for $PACKAGE_NAME@$NEW_VERSION to appear on npm"
echo "🔗 https://www.npmjs.com/package/$PACKAGE_NAME/"
read -p "⏸️ Press enter to continue when it's available..."
echo "⏳ Waiting 10s"
sleep 10
npm cache clean --force
fi
UPDATED+=("$pkg_dir|$CURRENT_VERSION → $NEW_VERSION")
cd "$REPO_ROOT"
echo ""
done
# Résumé
echo "✅ Script completed."
echo ""
if [ ${#UPDATED[@]} -gt 0 ]; then
echo "📦 Tagged:"
for entry in "${UPDATED[@]}"; do
echo " - $entry"
done
echo ""
fi
if [ ${#SKIPPED[@]} -gt 0 ]; then
echo "⏭️ Skipped (no changes):"
for d in "${SKIPPED[@]}"; do
echo " - $d"
done
echo ""
fi