|
| 1 | +name: Packer Script Testing |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'packer/**' |
| 7 | + - '.github/workflows/packer-test.yml' |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - 'packer/**' |
| 13 | + - '.github/workflows/packer-test.yml' |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +jobs: |
| 17 | + test-individual-scripts: |
| 18 | + name: Test Individual Scripts |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + script: |
| 24 | + - cassandra/install/install_cassandra_easy_stress.sh |
| 25 | + - base/install/install_docker.sh |
| 26 | + - base/install/install_python.sh |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v3 |
| 33 | + |
| 34 | + - name: Build test image |
| 35 | + run: | |
| 36 | + cd packer |
| 37 | + docker build -t easy-cass-lab-packer-test . |
| 38 | +
|
| 39 | + - name: Test script - ${{ matrix.script }} |
| 40 | + run: | |
| 41 | + cd packer |
| 42 | + ./test-script.sh ${{ matrix.script }} |
| 43 | +
|
| 44 | + test-changed-scripts: |
| 45 | + name: Test Changed Scripts |
| 46 | + runs-on: ubuntu-latest |
| 47 | + if: github.event_name == 'pull_request' |
| 48 | + steps: |
| 49 | + - name: Checkout code |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + fetch-depth: 0 |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + - name: Build test image |
| 58 | + run: | |
| 59 | + cd packer |
| 60 | + docker build -t easy-cass-lab-packer-test . |
| 61 | +
|
| 62 | + - name: Detect and test changed scripts |
| 63 | + run: | |
| 64 | + cd packer |
| 65 | + echo "Detecting changed shell scripts..." |
| 66 | +
|
| 67 | + # Get list of changed .sh files |
| 68 | + CHANGED_SCRIPTS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^packer/.*\.sh$' | grep -v 'test-script.sh' || true) |
| 69 | +
|
| 70 | + if [ -z "$CHANGED_SCRIPTS" ]; then |
| 71 | + echo "No shell scripts changed in this PR" |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "Changed scripts:" |
| 76 | + echo "$CHANGED_SCRIPTS" |
| 77 | +
|
| 78 | + # Test each changed script |
| 79 | + EXIT_CODE=0 |
| 80 | + for script in $CHANGED_SCRIPTS; do |
| 81 | + # Remove 'packer/' prefix if present |
| 82 | + script_path="${script#packer/}" |
| 83 | +
|
| 84 | + # Skip deleted files |
| 85 | + if [ ! -f "$script" ]; then |
| 86 | + echo "⊘ $script_path was deleted, skipping test" |
| 87 | + continue |
| 88 | + fi |
| 89 | +
|
| 90 | + echo "Testing: $script_path" |
| 91 | +
|
| 92 | + if ./test-script.sh "$script_path"; then |
| 93 | + echo "✓ $script_path passed" |
| 94 | + else |
| 95 | + echo "✗ $script_path failed" |
| 96 | + EXIT_CODE=1 |
| 97 | + fi |
| 98 | + done |
| 99 | +
|
| 100 | + exit $EXIT_CODE |
| 101 | +
|
| 102 | + test-base-provisioning: |
| 103 | + name: Test Base Provisioning Sequence |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - name: Checkout code |
| 107 | + uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Set up Docker Buildx |
| 110 | + uses: docker/setup-buildx-action@v3 |
| 111 | + |
| 112 | + - name: Test base provisioning |
| 113 | + run: | |
| 114 | + cd packer |
| 115 | + docker compose up --exit-code-from test-base test-base |
| 116 | +
|
| 117 | + - name: Show logs on failure |
| 118 | + if: failure() |
| 119 | + run: | |
| 120 | + cd packer |
| 121 | + docker compose logs test-base |
| 122 | +
|
| 123 | + test-cassandra-provisioning: |
| 124 | + name: Test Cassandra Provisioning Sequence |
| 125 | + runs-on: ubuntu-latest |
| 126 | + steps: |
| 127 | + - name: Checkout code |
| 128 | + uses: actions/checkout@v4 |
| 129 | + |
| 130 | + - name: Set up Docker Buildx |
| 131 | + uses: docker/setup-buildx-action@v3 |
| 132 | + |
| 133 | + - name: Test cassandra provisioning |
| 134 | + run: | |
| 135 | + cd packer |
| 136 | + docker compose up --exit-code-from test-cassandra test-cassandra |
| 137 | +
|
| 138 | + - name: Show logs on failure |
| 139 | + if: failure() |
| 140 | + run: | |
| 141 | + cd packer |
| 142 | + docker compose logs test-cassandra |
0 commit comments