|
| 1 | +name: Quality Assurance |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, development, 'fix/**', 'feature/**'] |
| 6 | + pull_request: |
| 7 | + branches: [main, development] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Linting and formatting checks |
| 12 | + lint: |
| 13 | + name: 'Lint & Format Check' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout Repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Install ShellCheck |
| 20 | + run: | |
| 21 | + sudo apt-get update |
| 22 | + sudo apt-get install -y shellcheck |
| 23 | +
|
| 24 | + - name: Install shfmt |
| 25 | + run: | |
| 26 | + wget -O shfmt https://github.com/mvdan/sh/releases/latest/download/shfmt_v3.8.0_linux_amd64 |
| 27 | + chmod +x shfmt |
| 28 | + sudo mv shfmt /usr/local/bin/ |
| 29 | +
|
| 30 | + - name: Run ShellCheck |
| 31 | + run: | |
| 32 | + echo "Running ShellCheck..." |
| 33 | + shellcheck phpvm.sh install.sh || exit 1 |
| 34 | +
|
| 35 | + - name: Check Code Formatting |
| 36 | + run: | |
| 37 | + echo "Checking code formatting..." |
| 38 | + shfmt -d -i 4 -sr phpvm.sh install.sh || { |
| 39 | + echo "Code formatting issues detected!" |
| 40 | + echo "Run 'make format' locally to fix." |
| 41 | + exit 1 |
| 42 | + } |
| 43 | +
|
| 44 | + - name: Check for Common Issues |
| 45 | + run: | |
| 46 | + echo "Checking for common issues..." |
| 47 | +
|
| 48 | + # Check for trailing whitespace |
| 49 | + if grep -n '[[:space:]]$' phpvm.sh install.sh; then |
| 50 | + echo "Trailing whitespace found (see above)" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + # Check for tabs (should use spaces) |
| 55 | + if grep -P '\t' phpvm.sh install.sh; then |
| 56 | + echo "Tabs found - please use spaces for indentation" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "No common issues found!" |
| 61 | +
|
| 62 | + # BATS test suite |
| 63 | + bats-tests: |
| 64 | + name: 'BATS Tests (${{ matrix.os }})' |
| 65 | + runs-on: ${{ matrix.os }} |
| 66 | + needs: lint |
| 67 | + strategy: |
| 68 | + fail-fast: false |
| 69 | + matrix: |
| 70 | + os: [ubuntu-latest, macos-latest] |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Checkout Repository |
| 74 | + uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Install BATS |
| 77 | + run: | |
| 78 | + if [ "${{ matrix.os }}" = "macos-latest" ]; then |
| 79 | + brew install bats-core |
| 80 | + else |
| 81 | + sudo apt-get update |
| 82 | + sudo apt-get install -y bats |
| 83 | + fi |
| 84 | +
|
| 85 | + - name: Run BATS Test Suite |
| 86 | + run: | |
| 87 | + echo "Running BATS tests..." |
| 88 | + bats tests/ -t |
| 89 | +
|
| 90 | + - name: Upload Test Results |
| 91 | + if: always() |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: bats-results-${{ matrix.os }} |
| 95 | + path: test-results/ |
| 96 | + retention-days: 30 |
| 97 | + |
| 98 | + # Built-in phpvm tests |
| 99 | + builtin-tests: |
| 100 | + name: 'Built-in Tests (${{ matrix.os }})' |
| 101 | + runs-on: ${{ matrix.os }} |
| 102 | + needs: lint |
| 103 | + strategy: |
| 104 | + fail-fast: false |
| 105 | + matrix: |
| 106 | + os: [ubuntu-latest, macos-latest] |
| 107 | + |
| 108 | + steps: |
| 109 | + - name: Checkout Repository |
| 110 | + uses: actions/checkout@v4 |
| 111 | + |
| 112 | + - name: Run phpvm Built-in Tests |
| 113 | + run: | |
| 114 | + echo "Running built-in tests..." |
| 115 | + bash phpvm.sh test |
| 116 | +
|
| 117 | + # Integration tests - Test with actual PHP installations |
| 118 | + integration-tests: |
| 119 | + name: 'Integration Tests (${{ matrix.os }})' |
| 120 | + runs-on: ${{ matrix.os }} |
| 121 | + needs: [lint, bats-tests, builtin-tests] |
| 122 | + strategy: |
| 123 | + fail-fast: false |
| 124 | + matrix: |
| 125 | + os: [ubuntu-latest, macos-latest] |
| 126 | + |
| 127 | + steps: |
| 128 | + - name: Checkout Repository |
| 129 | + uses: actions/checkout@v4 |
| 130 | + |
| 131 | + - name: Setup Test Environment |
| 132 | + run: | |
| 133 | + export PHPVM_DIR="$HOME/.phpvm-test" |
| 134 | + mkdir -p "$PHPVM_DIR" |
| 135 | + ./install.sh |
| 136 | +
|
| 137 | + - name: Test PHP Installation (macOS) |
| 138 | + if: matrix.os == 'macos-latest' |
| 139 | + run: | |
| 140 | + source "$HOME/.phpvm-test/phpvm.sh" |
| 141 | +
|
| 142 | + # Test install |
| 143 | + phpvm install 8.2 || echo "PHP 8.2 already installed" |
| 144 | +
|
| 145 | + # Test use |
| 146 | + phpvm use 8.2 |
| 147 | +
|
| 148 | + # Verify PHP version |
| 149 | + php -v |
| 150 | +
|
| 151 | + # Test current |
| 152 | + phpvm current |
| 153 | +
|
| 154 | + - name: Test PHP Installation (Ubuntu) |
| 155 | + if: matrix.os == 'ubuntu-latest' |
| 156 | + run: | |
| 157 | + source "$HOME/.phpvm-test/phpvm.sh" |
| 158 | +
|
| 159 | + # Add repository |
| 160 | + sudo add-apt-repository -y ppa:ondrej/php |
| 161 | + sudo apt-get update |
| 162 | +
|
| 163 | + # Test install |
| 164 | + phpvm install 8.2 || echo "PHP 8.2 installation attempted" |
| 165 | +
|
| 166 | + # Test current |
| 167 | + phpvm current || echo "No active version yet" |
| 168 | +
|
| 169 | + - name: Cleanup |
| 170 | + if: always() |
| 171 | + run: | |
| 172 | + rm -rf "$HOME/.phpvm-test" |
| 173 | +
|
| 174 | + # Quality gate - All checks must pass |
| 175 | + quality-gate: |
| 176 | + name: 'Quality Gate' |
| 177 | + runs-on: ubuntu-latest |
| 178 | + needs: [lint, bats-tests, builtin-tests] |
| 179 | + if: always() |
| 180 | + steps: |
| 181 | + - name: Check All Jobs |
| 182 | + run: | |
| 183 | + if [ "${{ needs.lint.result }}" != "success" ]; then |
| 184 | + echo "Linting failed!" |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | + if [ "${{ needs.bats-tests.result }}" != "success" ]; then |
| 188 | + echo "BATS tests failed!" |
| 189 | + exit 1 |
| 190 | + fi |
| 191 | + if [ "${{ needs.builtin-tests.result }}" != "success" ]; then |
| 192 | + echo "Built-in tests failed!" |
| 193 | + exit 1 |
| 194 | + fi |
| 195 | + echo "All quality checks passed! ✅" |
0 commit comments