Skip to content

Commit 5bd0dff

Browse files
authored
feat: Upgrade script (#374)
Added a new script to help with upgrading backstage within workspaces.
1 parent 992cfac commit 5bd0dff

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

scripts/upgrade_workspace.sh

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash
2+
3+
# Colors
4+
GREEN='\033[0;32m'
5+
BLUE='\033[0;34m'
6+
YELLOW='\033[1;33m'
7+
RED='\033[0;31m'
8+
NC='\033[0m' # No Color
9+
10+
# Function to display error message and exit
11+
function error_exit {
12+
echo -e "\n${RED}ERROR: $1${NC}" 1>&2
13+
exit 1
14+
}
15+
16+
# Function to display section headers
17+
function section_header {
18+
echo -e "\n${BLUE}=================================================${NC}"
19+
echo -e "${BLUE} $1${NC}"
20+
echo -e "${BLUE}=================================================${NC}\n"
21+
}
22+
23+
# Function to run command with output handling
24+
# Shows output only on error, otherwise hides it
25+
function run_command {
26+
local cmd="$1"
27+
local error_msg="$2"
28+
local temp_output=$(mktemp)
29+
30+
echo -e "$3"
31+
32+
# Run the command and capture output
33+
eval "$cmd" >"$temp_output" 2>&1
34+
local status=$?
35+
36+
if [ $status -ne 0 ]; then
37+
echo -e "\n${RED}❌ Command failed. Output:${NC}\n"
38+
cat "$temp_output"
39+
rm "$temp_output"
40+
error_exit "$error_msg"
41+
else
42+
rm "$temp_output"
43+
echo -e "${GREEN}$4${NC}"
44+
fi
45+
}
46+
47+
# Function to run interactive commands that require user input
48+
function run_interactive_command {
49+
local cmd="$1"
50+
local error_msg="$2"
51+
52+
echo -e "$3"
53+
54+
# Run the command directly without capturing output
55+
eval "$cmd"
56+
local status=$?
57+
58+
if [ $status -ne 0 ]; then
59+
error_exit "$error_msg"
60+
else
61+
echo -e "${GREEN}$4${NC}"
62+
fi
63+
}
64+
65+
section_header "BACKSTAGE WORKSPACE UPGRADE"
66+
echo -e "${GREEN}This script will guide you through upgrading a Backstage workspace.${NC}\n"
67+
68+
# List available workspaces
69+
section_header "WORKSPACE SELECTION"
70+
echo -e "${YELLOW}Please select a workspace to upgrade from the list below:${NC}"
71+
workspaces=(workspaces/*)
72+
select workspace in "${workspaces[@]}"; do
73+
if [ -n "$workspace" ]; then
74+
echo -e "\n${GREEN}✅ Selected workspace: ${YELLOW}$(basename "$workspace")${NC}\n"
75+
break
76+
else
77+
echo -e "\n${RED}❌ Invalid selection. Please try again.${NC}\n"
78+
fi
79+
done
80+
81+
# Change to the selected workspace directory
82+
section_header "PREPARING WORKSPACE"
83+
echo -e "📂 Changing to workspace directory: ${YELLOW}$workspace${NC}"
84+
cd "$workspace" || error_exit "Failed to change directory to $workspace"
85+
echo -e "${GREEN}✅ Successfully changed to workspace directory${NC}"
86+
87+
# Update yarn to the latest stable version
88+
section_header "UPDATING YARN"
89+
run_command "yarn set version stable" "Failed to update yarn to the latest stable version" \
90+
"🧶 Updating yarn to latest stable version..." \
91+
"Successfully updated yarn"
92+
93+
# Install dependencies with new yarn version
94+
section_header "INSTALLING DEPENDENCIES"
95+
run_command "yarn install" "Failed to install dependencies" \
96+
"📦 Installing dependencies with updated yarn version..." \
97+
"Successfully installed dependencies"
98+
99+
# Import the yarn plugin
100+
section_header "IMPORTING YARN PLUGIN"
101+
run_command "yarn plugin import https://versions.backstage.io/v1/tags/main/yarn-plugin" "Failed to import yarn plugin" \
102+
"🔌 Importing Backstage yarn plugin..." \
103+
"Successfully imported yarn plugin"
104+
105+
# Bump backstage versions
106+
section_header "BUMPING BACKSTAGE VERSIONS"
107+
run_command "yarn backstage-cli versions:bump" "Failed to bump backstage versions" \
108+
"⬆️ Bumping Backstage versions to latest..." \
109+
"Successfully bumped versions"
110+
111+
# Deduplicate dependencies
112+
section_header "DEDUPLICATING DEPENDENCIES"
113+
run_command "yarn dedupe" "Failed to deduplicate dependencies" \
114+
"🧹 Deduplicating dependencies..." \
115+
"Successfully deduplicated dependencies"
116+
117+
# TypeScript compilation
118+
section_header "COMPILING TYPESCRIPT"
119+
run_command "yarn tsc" "TypeScript compilation failed" \
120+
"📝 Running TypeScript compilation..." \
121+
"Successfully compiled TypeScript"
122+
123+
# Run tests with coverage
124+
section_header "RUNNING TESTS"
125+
run_command "yarn test --coverage" "Tests failed" \
126+
"🧪 Running tests with coverage..." \
127+
"All tests passed successfully"
128+
129+
# Run changeset - Interactive command
130+
section_header "CREATING CHANGESET"
131+
run_interactive_command "yarn changeset" "Changeset failed" \
132+
"📦 Creating changeset for version tracking...\n${YELLOW}Please provide input for the changeset when prompted:${NC}" \
133+
"Successfully created changeset"
134+
135+
# Run prettier to format code
136+
section_header "FORMATTING CODE"
137+
run_command "yarn prettier --write ." "Prettier formatting failed" \
138+
"✨ Formatting code with prettier..." \
139+
"Successfully formatted code"
140+
141+
section_header "UPGRADE COMPLETE"
142+
echo -e "${GREEN}🎉 Workspace upgrade completed successfully!${NC}"
143+
echo -e "${YELLOW}Workspace ${NC}$(basename "$workspace")${YELLOW} has been upgraded to the latest Backstage version.${NC}\n"

0 commit comments

Comments
 (0)