|
1 | 1 | #!/bin/bash |
2 | | -set -e |
| 2 | +set -Eeuo pipefail # Stricter error handling |
| 3 | +IFS=$'\n\t' |
3 | 4 |
|
4 | | -INSTALL_FILE='install.sh' |
| 5 | +INSTALL_FILE_BASENAME='install.sh' |
| 6 | +REPORT_NAME='integration-report.md' |
| 7 | +REPORT_PATH="$GITHUB_WORKSPACE/$REPORT_NAME" # Create report directly in workspace |
5 | 8 |
|
6 | | -echo "Testing installation process..." |
| 9 | +TEST_DIR="" |
7 | 10 |
|
8 | | -chmod +x $INSTALL_FILE |
| 11 | +cleanup() { |
| 12 | + echo "Running cleanup..." |
| 13 | + if [ -n "$TEST_DIR" ] && [ -d "$TEST_DIR" ]; then |
| 14 | + echo "Removing temporary directory: $TEST_DIR" |
| 15 | + rm -rf "$TEST_DIR" |
| 16 | + fi |
| 17 | +} |
| 18 | +trap cleanup EXIT SIGINT SIGTERM |
| 19 | + |
| 20 | +echo "Integration Test Script Started. Report will be at: $REPORT_PATH" |
| 21 | + |
| 22 | +# Initialize report early |
| 23 | +echo "# Integration Test Results (In Progress)" > "$REPORT_PATH" |
| 24 | + |
| 25 | +if [ ! -f "$GITHUB_WORKSPACE/$INSTALL_FILE_BASENAME" ]; then |
| 26 | + echo "ERROR: Install script $GITHUB_WORKSPACE/$INSTALL_FILE_BASENAME not found!" >> "$REPORT_PATH" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | +# The CI workflow step should make install.sh executable. This is a fallback. |
| 30 | +# chmod +x "$GITHUB_WORKSPACE/$INSTALL_FILE_BASENAME" || { echo "ERROR: Failed to chmod +x $INSTALL_FILE_BASENAME" >> "$REPORT_PATH"; exit 1; } |
9 | 31 |
|
10 | 32 | TEST_DIR=$(mktemp -d) |
11 | | -cd $TEST_DIR |
| 33 | +if [ -z "$TEST_DIR" ] || [ ! -d "$TEST_DIR" ]; then |
| 34 | + echo "ERROR: Failed to create temporary directory with mktemp." >> "$REPORT_PATH" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | +echo "Temporary directory created: $TEST_DIR" >> "$REPORT_PATH" |
| 38 | + |
| 39 | +cp "$GITHUB_WORKSPACE/$INSTALL_FILE_BASENAME" "$TEST_DIR/test-install.sh" || { echo "ERROR: Failed to copy install script to $TEST_DIR" >> "$REPORT_PATH"; exit 1; } |
| 40 | + |
| 41 | +pushd "$TEST_DIR" > /dev/null || { echo "ERROR: Failed to cd into $TEST_DIR" >> "$REPORT_PATH"; exit 1; } |
| 42 | + |
| 43 | +echo "Modifying ./test-install.sh (changing install path to ./local-bin, removing sudo)" >> "$REPORT_PATH" |
| 44 | +sed -i 's|/usr/local/bin|./local-bin|g' ./test-install.sh || { echo "ERROR: sed for install path failed" >> "$REPORT_PATH"; popd > /dev/null; exit 1; } |
| 45 | +sed -i 's|sudo ||g' ./test-install.sh || { echo "ERROR: sed for sudo removal failed" >> "$REPORT_PATH"; popd > /dev/null; exit 1; } |
| 46 | + |
| 47 | +mkdir -p ./local-bin || { echo "ERROR: Failed to create ./local-bin directory" >> "$REPORT_PATH"; popd > /dev/null; exit 1; } |
| 48 | + |
| 49 | +echo "Running modified ./test-install.sh..." # This goes to stdout, not report yet |
| 50 | +INSTALL_OUTPUT_FILE="install_output.txt" |
| 51 | +INSTALL_ERROR_FILE="install_error.txt" |
| 52 | + |
| 53 | +bash ./test-install.sh > "$INSTALL_OUTPUT_FILE" 2> "$INSTALL_ERROR_FILE" |
| 54 | +INSTALL_EXIT_CODE=$? |
| 55 | + |
| 56 | +popd > /dev/null # Return from TEST_DIR |
| 57 | + |
| 58 | +# Finalize Report Content (overwrite initial progress message) |
| 59 | +echo "# Integration Test Results" > "$REPORT_PATH" |
| 60 | +echo "" >> "$REPORT_PATH" |
| 61 | +echo "- Test environment: Ubuntu Latest (GitHub Actions Runner)" >> "$REPORT_PATH" |
| 62 | +echo "- Temporary test directory used: $TEST_DIR (now cleaned up)" >> "$REPORT_PATH" |
| 63 | +echo "- Installation script ($INSTALL_FILE_BASENAME) execution exit code: $INSTALL_EXIT_CODE" >> "$REPORT_PATH" |
| 64 | +echo "" >> "$REPORT_PATH" |
| 65 | + |
| 66 | +echo "## Installation Script Output (stdout from $TEST_DIR/$INSTALL_OUTPUT_FILE):" >> "$REPORT_PATH" |
| 67 | +cat "$TEST_DIR/$INSTALL_OUTPUT_FILE" >> "$REPORT_PATH" |
| 68 | +echo "" >> "$REPORT_PATH" |
12 | 69 |
|
13 | | -cp $GITHUB_WORKSPACE/$INSTALL_FILE ./test-install.sh |
| 70 | +if [ -s "$TEST_DIR/$INSTALL_ERROR_FILE" ]; then |
| 71 | + echo "## Installation Script Errors (stderr from $TEST_DIR/$INSTALL_ERROR_FILE):" >> "$REPORT_PATH" |
| 72 | + cat "$TEST_DIR/$INSTALL_ERROR_FILE" >> "$REPORT_PATH" |
| 73 | + echo "" >> "$REPORT_PATH" |
| 74 | +fi |
14 | 75 |
|
15 | | -sed -i 's|/usr/local/bin|./bin|g' ./test-install.sh |
16 | | -sed -i 's|sudo ||g' ./test-install.sh |
| 76 | +# System info - make robust |
| 77 | +DOCKER_VERSION=$(docker --version 2>/dev/null || echo "Docker not found or error during version check") |
| 78 | +GIT_VERSION=$(git --version 2>/dev/null || echo "Git not found or error during version check") |
| 79 | +CURL_VERSION=$(curl --version 2>/dev/null | head -1 || echo "Curl not found or error during version check") |
| 80 | +BASH_VERSION=$(bash --version 2>/dev/null | head -1 || echo "Bash not found or error during version check") |
17 | 81 |
|
18 | | -mkdir -p ./bin |
| 82 | +echo "## System Information from Runner" >> "$REPORT_PATH" |
| 83 | +echo "- Docker available: $DOCKER_VERSION" >> "$REPORT_PATH" |
| 84 | +echo "- Git available: $GIT_VERSION" >> "$REPORT_PATH" |
| 85 | +echo "- Curl available: $CURL_VERSION" >> "$REPORT_PATH" |
| 86 | +echo "- Bash available: $BASH_VERSION" >> "$REPORT_PATH" |
19 | 87 |
|
20 | | -bash ./test-install.sh || echo "Install test completed (errors expected in CI)" |
| 88 | +echo "Integration test script finished. Report generated at $REPORT_PATH" |
21 | 89 |
|
22 | | -echo "# Integration Test Results" > integration-report.md |
23 | | -echo "" >> integration-report.md |
24 | | -echo "- Test environment: Ubuntu Latest" >> integration-report.md |
25 | | -echo "- Docker available: $(docker --version)" >> integration-report.md |
26 | | -echo "- Git available: $(git --version)" >> integration-report.md |
27 | | -echo "- Curl available: $(curl --version | head -1)" >> integration-report.md |
| 90 | +exit $INSTALL_EXIT_CODE |
0 commit comments