-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_devcontainer_tests.sh
More file actions
executable file
·188 lines (148 loc) · 7.21 KB
/
run_devcontainer_tests.sh
File metadata and controls
executable file
·188 lines (148 loc) · 7.21 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
#!/usr/bin/env bash
# Step 1: Install devcontainer CLI and nvm if not already installed
echo "Step 1: Checking and installing devcontainer CLI and nvm..."
# Check if devcontainer CLI is installed
if ! command -v devcontainer &> /dev/null; then
echo "Installing devcontainer CLI..."
# Install nvm if not already installed
if [ ! -d "/usr/local/share/nvm" ] && [ ! -d "$HOME/.nvm" ]; then
echo "Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
fi
# Set NVM_DIR based on where nvm is actually installed
if [ -d "/usr/local/share/nvm" ]; then
export NVM_DIR="/usr/local/share/nvm"
else
export NVM_DIR="$HOME/.nvm"
fi
echo "nvm is installed at: $NVM_DIR"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Install Node.js using nvm if not already installed
if ! command -v node &> /dev/null; then
echo "Installing Node.js using nvm..."
# Source nvm again to ensure it's available in this context
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install node
nvm use node
# Add node and npm to PATH for this session
export PATH="$NVM_DIR/versions/node/$(nvm version node)/bin:$PATH"
else
echo "Node.js is already installed"
# Ensure nvm is sourced and PATH is set correctly
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
export PATH="$NVM_DIR/versions/node/$(nvm version node)/bin:$PATH"
fi
# Install devcontainer CLI using npm
echo "Installing devcontainer CLI using npm..."
# Ensure npm is available
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
export PATH="$NVM_DIR/versions/node/$(nvm version node)/bin:$PATH"
npm install -g @devcontainers/cli
else
echo "devcontainer CLI is already installed"
fi
# Build the application
echo "Building the application..."
dotnet build --configuration Release --no-restore --self-contained false /p:PublishSingleFile=true /p:PublishTrimmed=true
# Create the zip file
echo "Creating webdev-tool.zip..."
cd ./bin/Release/net9.0 && zip -r ../../../webdev-tool.zip ./* && cd -
echo "Step 1 completed: devcontainer CLI and nvm are ready, and webdev-tool.zip has been created."
# Step 2: Install webdev tool on host and start devcontainer
echo "Step 2: Installing webdev tool on host and starting devcontainer..."
# Check if webdev-tool.zip exists
if [ ! -f "webdev-tool.zip" ]; then
echo "Error: webdev-tool.zip not found. Please ensure the build completed successfully."
exit 1
fi
# Install webdev tool on host first (needed for initializeCommand)
echo "Installing webdev tool on host..."
rm -rf ~/webdev-host
mkdir ~/webdev-host
unzip -o webdev-tool.zip -d ~/webdev-host/
chmod +x ~/webdev-host/webdev.sh
sudo ln -sf ~/webdev-host/webdev.sh /usr/local/bin/webdev
# Navigate to the devcontainer directory
cd devcontainer-testenv
# Reset environment variables
unset WEBDEV_WORKSPACE_FOLDER
# Stop the devcontainer if it is running
echo "Stopping any running devcontainers..."
if [ -n "$(docker ps -q -f name=devcontainer-app)" ]; then
docker stop $(docker ps -q -f name=devcontainer-app)
fi
# Start the devcontainer
echo "Starting devcontainer..."
devcontainer up --workspace-folder . --remove-existing-container
# Wait a moment for the container to be fully ready
sleep 5
# Copy the zip file to the container
echo "Copying webdev-tool.zip to container..."
cp /workspaces/webdev-tool/webdev-tool.zip /workspaces/webdev-tool/devcontainer-testenv/webdev-tool.zip
devcontainer exec --workspace-folder . mkdir -p /home/webdev/webdev
devcontainer exec --workspace-folder . mv webdev-tool.zip /home/webdev/webdev/
# Unzip the file in the container
echo "Unzipping webdev-tool.zip in container..."
devcontainer exec --workspace-folder . bash -c "cd /home/webdev/webdev && unzip -o webdev-tool.zip"
devcontainer exec --workspace-folder . bash -c "chmod +x /home/webdev/webdev/webdev.sh"
devcontainer exec --workspace-folder . bash -c "sudo ln -s /home/webdev/webdev/webdev.sh /usr/local/bin/webdev"
# Set permissions for the devcontainer-testenv folder otherwise tests will fail because the user inside the container is not the same as the user on the host
chmod -R 777 devcontainer-testenv/
echo "Step 2 completed: Devcontainer is running and webdev-tool.zip has been copied and extracted to ~/webdev/"
# Return to the original directory
cd ..
# Delete the zip file
echo "Deleting webdev-tool.zip..."
rm webdev-tool.zip
# Step 3: Build and run tests from WebDevTool.Tests project
echo "Step 3: Building and running tests from WebDevTool.Tests project..."
# Navigate back to the main project directory
cd /workspaces/webdev-tool
# Build the test project
echo "Building WebDevTool.Tests project..."
dotnet build WebDev.Tool.Tests/WebDev.Tool.Tests.csproj --configuration Release --no-restore
# Check if build was successful
if [ $? -eq 0 ]; then
echo "Test project build completed successfully."
# Run the tests in the correct order using collections
echo "Running tests from WebDevTool.Tests project in order..."
# Step 1: Run Basic Tests (version, help, availability)
echo "Step 3.1: Running Basic Tests..."
dotnet test WebDev.Tool.Tests/WebDev.Tool.Tests.csproj --configuration Release --no-build --filter "Category=Basic" --verbosity normal --logger "console;verbosity=detailed"
if [ $? -ne 0 ]; then
echo "Error: Basic tests failed. Stopping execution."
exit 1
fi
# Step 2: Run Workspace Tests (environment setup)
echo "Step 3.2: Running Workspace Tests..."
dotnet test WebDev.Tool.Tests/WebDev.Tool.Tests.csproj --configuration Release --no-build --filter "Category=Workspace" --verbosity normal --logger "console;verbosity=detailed"
if [ $? -ne 0 ]; then
echo "Error: Workspace tests failed. Stopping execution."
exit 1
fi
# Step 3: Run Command Tests (PHP, Node, Database commands)
echo "Step 3.3: Running Command Tests..."
dotnet test WebDev.Tool.Tests/WebDev.Tool.Tests.csproj --configuration Release --no-build --filter "Category=Commands" --verbosity normal --logger "console;verbosity=detailed"
if [ $? -ne 0 ]; then
echo "Error: Command tests failed. Stopping execution."
exit 1
fi
# Step 4: Run Integration Tests (end-to-end workflows)
echo "Step 3.4: Running Integration Tests..."
dotnet test WebDev.Tool.Tests/WebDev.Tool.Tests.csproj --configuration Release --no-build --filter "Category=Integration" --verbosity normal --logger "console;verbosity=detailed"
if [ $? -ne 0 ]; then
echo "Error: Integration tests failed. Stopping execution."
exit 1
fi
# All test collections completed successfully
echo "Step 3 completed: All test collections passed successfully!"
echo "Test execution order:"
echo " ✓ Basic Tests (version, help, availability)"
echo " ✓ Workspace Tests (environment setup)"
echo " ✓ Command Tests (PHP, Node, Database commands)"
echo " ✓ Integration Tests (end-to-end workflows)"
else
echo "Error: Test project build failed. Please check the build output above."
exit 1
fi