|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "plugins/**" |
| 8 | + - "scripts/**" |
| 9 | + - ".github/workflows/test.yml" |
| 10 | + |
| 11 | +# Read-only token: this job checks out and EXECUTES PR-supplied plugin code |
| 12 | +# inside the host app, so it must never have write access or secrets. (Mirrors |
| 13 | +# the validate job's trust model — see validate.yml.) |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: test-${{ github.event.pull_request.number }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + test: |
| 23 | + name: Run plugin tests |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + steps: |
| 26 | + - name: Checkout marketplace |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + path: plugins-repo |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + # The host VitoDeploy app provides the classes plugins compile against |
| 33 | + # (App\Plugins\*, App\SiteFeatures\Action, App\Models\*, the SSH facade) |
| 34 | + # and the Tests\TestCase that auto-provisions a server/site. Plugin tests |
| 35 | + # run INSIDE this checkout. |
| 36 | + # |
| 37 | + # Pinned to the host's current development line (4.x). Plugins declare |
| 38 | + # min_vito_version 3.0.0, so the host API they bind to is stable across |
| 39 | + # 3.x/4.x; tracking 4.x surfaces forward-compat breakage early. To also |
| 40 | + # gate on an older line, add a matrix over `ref`. |
| 41 | + - name: Checkout host VitoDeploy app |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + repository: vitodeploy/vito |
| 45 | + ref: 4.x |
| 46 | + path: vito |
| 47 | + |
| 48 | + - name: Setup PHP |
| 49 | + uses: shivammathur/setup-php@v2 |
| 50 | + with: |
| 51 | + php-version: "8.4" |
| 52 | + tools: composer |
| 53 | + |
| 54 | + - name: Setup Node |
| 55 | + uses: actions/setup-node@v4 |
| 56 | + with: |
| 57 | + node-version: "20" |
| 58 | + |
| 59 | + - name: Cache host Composer packages |
| 60 | + id: composer-cache |
| 61 | + uses: actions/cache@v4 |
| 62 | + with: |
| 63 | + path: vito/vendor |
| 64 | + key: vito-host-${{ hashFiles('vito/composer.lock') }} |
| 65 | + restore-keys: | |
| 66 | + vito-host- |
| 67 | +
|
| 68 | + - name: Install host dependencies |
| 69 | + working-directory: vito |
| 70 | + run: composer install --prefer-dist --no-progress |
| 71 | + |
| 72 | + - name: Prepare host test environment |
| 73 | + working-directory: vito |
| 74 | + run: | |
| 75 | + touch storage/database-test.sqlite |
| 76 | + touch .env |
| 77 | + php artisan key:generate |
| 78 | +
|
| 79 | + # Only test plugins changed in this PR (matches validate.yml granularity). |
| 80 | + # If the diff is tooling-only (scripts/**), test every plugin so a runner |
| 81 | + # change can't silently break the suite. |
| 82 | + - name: Determine changed plugins |
| 83 | + id: changed |
| 84 | + working-directory: plugins-repo |
| 85 | + env: |
| 86 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 87 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 88 | + run: | |
| 89 | + set -euo pipefail |
| 90 | + changed_plugins="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- plugins/ \ |
| 91 | + | awk -F/ 'NF>1 && $1=="plugins" {print $2}' | sort -u)" |
| 92 | + tooling="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- scripts/ | head -n1 || true)" |
| 93 | +
|
| 94 | + if [ -n "$tooling" ] || [ -z "$changed_plugins" ]; then |
| 95 | + echo "Tooling changed or no specific plugin diff; testing all plugins." |
| 96 | + echo "slugs=" >> "$GITHUB_OUTPUT" |
| 97 | + else |
| 98 | + echo "Changed plugins:"; printf ' - %s\n' $changed_plugins |
| 99 | + echo "slugs=$(printf '%s ' $changed_plugins)" >> "$GITHUB_OUTPUT" |
| 100 | + fi |
| 101 | +
|
| 102 | + - name: Run plugin tests |
| 103 | + working-directory: plugins-repo |
| 104 | + env: |
| 105 | + VITO_PATH: ${{ github.workspace }}/vito |
| 106 | + run: node scripts/test.mjs ${{ steps.changed.outputs.slugs }} |
0 commit comments