-
Notifications
You must be signed in to change notification settings - Fork 873
Expand file tree
/
Copy pathrelease-prep.sh
More file actions
executable file
Β·132 lines (100 loc) Β· 4.68 KB
/
release-prep.sh
File metadata and controls
executable file
Β·132 lines (100 loc) Β· 4.68 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
#!/usr/bin/env bash
#
# Official release preparation script (pre-PR)
#
# Automates steps 1-8 of the official release process:
# 1. Log out of npm
# 2. Checkout main
# 3. Pull latest from upstream
# 4. Create a timestamped release branch
# 5. Build the release CLI
# 6. Run the release dry-run (interactive)
# 7. (User confirms in the interactive CLI)
# 8. Push the branch to origin and open a PR
#
# Usage: yarn release:prep
#
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
RESET='\033[0m'
step() {
echo ""
echo -e "${GREEN}${BOLD}[$1]${RESET} $2"
}
warn() {
echo -e "${YELLOW}Warning:${RESET} $1"
}
error() {
echo -e "${RED}Error:${RESET} $1" >&2
exit 1
}
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || error "Not inside a git repository"
cd "$REPO_ROOT"
# Verify the upstream remote exists
git remote get-url upstream &>/dev/null || error "'upstream' remote not found. Please add it: git remote add upstream [email protected]:elastic/eui.git"
# ββ Step 1: Log out of npm ββββββββββββββββββββββββββββββββββββββββββββββββββ
step "1/8" "Ensuring npm is not authenticated..."
npm logout 2>/dev/null || true
yarn npm logout 2>/dev/null || true
# ββ Step 2: Checkout main βββββββββββββββββββββββββββββββββββββββββββββββββββ
step "2/8" "Checking out main branch..."
git checkout main
# ββ Step 3: Pull latest ββββββββββββββββββββββββββββββββββββββββββββββββββββ
step "3/8" "Pulling latest changes from upstream..."
git pull upstream main
# ββ Step 4: Create release branch βββββββββββββββββββββββββββββββββββββββββββ
BRANCH_NAME="release/$(date +%s)"
step "4/8" "Creating release branch: ${BOLD}${BRANCH_NAME}${RESET}"
git checkout -b "$BRANCH_NAME"
# ββ Step 5: Build release CLI βββββββββββββββββββββββββββββββββββββββββββββββ
step "5/8" "Installing dependencies and building release CLI..."
yarn
yarn workspace @elastic/eui-release-cli run build
# ββ Step 6: Run release (dry-run) βββββββββββββββββββββββββββββββββββββββββββ
step "6/8" "Starting release process (dry-run)..."
echo ""
yarn release run official --dry-run --allow-custom --skip-auth-check --use-auth-token
# ββ Step 7: Push branch ββββββββββββββββββββββββββββββββββββββββββββββββββββ
step "7/8" "Pushing branch to origin..."
git push -u origin "$BRANCH_NAME"
# ββ Step 8: Open PR ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
step "8/8" "Opening release PR..."
# Detect changed packages by comparing versions on this branch vs main
PR_TITLE_PARTS=""
PR_BODY_LINES=""
for pkg_dir in packages/eui packages/eui-theme-common packages/eui-theme-borealis packages/docusaurus-preset packages/docusaurus-theme packages/eslint-plugin; do
pkg_json="${pkg_dir}/package.json"
[[ -f "$pkg_json" ]] || continue
new_version=$(node -p "require('./${pkg_json}').version")
old_version=$(git show "main:${pkg_json}" 2>/dev/null | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version" 2>/dev/null || echo "")
if [[ -n "$old_version" && "$new_version" != "$old_version" ]]; then
pkg_name=$(node -p "require('./${pkg_json}').name")
if [[ -n "$PR_TITLE_PARTS" ]]; then
PR_TITLE_PARTS="${PR_TITLE_PARTS}, ${pkg_name} v${new_version}"
else
PR_TITLE_PARTS="${pkg_name} v${new_version}"
fi
PR_BODY_LINES="${PR_BODY_LINES}\n- \`${pkg_name}\` - v${old_version} β v${new_version}"
fi
done
if [[ -z "$PR_TITLE_PARTS" ]]; then
error "No changed package versions detected. Did the release dry-run update any versions?"
fi
PR_TITLE="Release: ${PR_TITLE_PARTS}"
PR_BODY="$(printf "Packages to release:\n${PR_BODY_LINES}")"
PR_URL=$(gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--label "skip-changelog" \
--label "release" \
--base main)
echo ""
echo -e "${GREEN}${BOLD}Prep complete!${RESET}"
echo ""
echo -e " PR: ${BOLD}${PR_URL}${RESET}"
echo ""
echo -e " ${BOLD}After the PR is merged:${RESET}"
echo -e " yarn release:publish"