name: Test Action on: push: branches: [ main ] pull_request: branches: [ main ] # Keep the fixture source in one place. Override these with repository variables # when testing another server repository; no workflow edits are required. env: TEST_SERVER_REPOSITORY: ${{ vars.TEST_SERVER_REPOSITORY || 'Nodarx/server' }} TEST_SERVER_REF: ${{ vars.TEST_SERVER_REF || 'main' }} TEST_GIT_SERVER_URL: ${{ vars.TEST_GIT_SERVER_URL || 'https://git.ktrix.dev' }} TEST_DATABASE_URI: ${{ vars.TEST_DATABASE_URI || 'mongodb://mongo:27017/?tls=false' }} jobs: test-node: name: Test Node runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with Node.js (npm) uses: ./ with: install-node: 'true' node-version: '24' server-path: './test-server' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify installation run: | test -d ./test-server || exit 1 test -d ./test-server/node_modules || exit 1 chmod +x ./scripts/health-check.sh ./scripts/health-check.sh ./test-server true false false echo "✓ Node.js (npm) installation successful" - name: Run server tests run: | cd ./test-server npm run test:unit test-php: name: Test PHP runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with PHP uses: ./ with: install-php: 'true' php-version: '8.5' server-path: './test-server' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify installation run: | test -d ./test-server || exit 1 php --version composer --version chmod +x ./scripts/health-check.sh ./scripts/health-check.sh ./test-server false true false echo "✓ PHP installation successful" - name: Run server tests run: | cd ./test-server composer test:unit test-database-config: name: Test Database Configuration runs-on: ubuntu-latest services: mongo: image: mongo:7 steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with database configuration uses: ./ with: install-php: 'true' php-version: '8.5' server-path: './test-server' database-uri: ${{ env.TEST_DATABASE_URI }} database-name: 'ktrix_ci' app-environment: 'test' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify configuration was written run: | cd ./test-server php -r ' $config = include "config/system.php"; $uri = $config["database"]["uri"] ?? null; $name = $config["database"]["database"] ?? null; $env = $config["environment"] ?? null; $expectedUri = getenv("TEST_DATABASE_URI"); if ($uri !== $expectedUri) { fwrite(STDERR, "database.uri not overridden, got: $uri\n"); exit(1); } if ($name !== "ktrix_ci") { fwrite(STDERR, "database.database not overridden, got: $name\n"); exit(1); } if ($env !== "test") { fwrite(STDERR, "environment not overridden, got: $env\n"); exit(1); } ' echo "✓ Database configuration verified" - name: Verify database is reachable with configured settings run: | cd ./test-server php bin/console tenant:list test-base-modules: name: Test Base Modules Installation runs-on: ubuntu-latest services: mongo: image: mongo:7 steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with base modules uses: ./ with: install-php: 'true' php-version: '8.5' server-path: './test-server' database-uri: ${{ env.TEST_DATABASE_URI }} database-name: 'ktrix_ci' install-base-modules: 'true' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify password authentication provider is installed and enabled run: | cd ./test-server OUTPUT=$(php bin/console module:list) echo "$OUTPUT" echo "$OUTPUT" | grep -q "authentication_provider_password" || { echo "::error::authentication_provider_password not found in module list"; exit 1; } echo "$OUTPUT" | grep "authentication_provider_password" | grep -q "Enabled" || { echo "::error::authentication_provider_password is not enabled"; exit 1; } echo "✓ authentication_provider_password is installed and enabled" - name: Verify a tenant and user can be provisioned end-to-end run: | cd ./test-server php bin/console tenant:create ci.test --identifier ci_smoke php bin/console user:create ci_smoke tester@ci.test php bin/console user:password ci_smoke tester@ci.test 'Sup3r-Secret!' php bin/console user:list ci_smoke | grep -q "tester@ci.test" || { echo "::error::provisioned user not found"; exit 1; } echo "✓ tenant and user provisioning verified" test-base-modules-requires-php: name: Test Base Modules Requires PHP runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Expect failure when install-base-modules is set without install-php id: expect-failure continue-on-error: true uses: ./ with: install-node: 'true' install-base-modules: 'true' server-path: './test-server' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify the action failed run: | if [ "${{ steps.expect-failure.outcome }}" != "failure" ]; then echo "::error::Expected action to fail when install-base-modules is set without install-php" exit 1 fi echo "✓ Action correctly rejected install-base-modules without install-php" test-nginx: name: Test nginx runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with nginx uses: ./ with: install-nginx: 'true' server-path: './test-server' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify installation run: | test -d ./test-server || exit 1 nginx -v # Verify nginx is running pgrep nginx || exit 1 chmod +x ./scripts/health-check.sh ./scripts/health-check.sh ./test-server false false true echo "✓ nginx installation successful" test-all-components: name: Test All Components runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with all components uses: ./ with: install-node: 'true' install-php: 'true' install-nginx: 'true' node-version: '24' php-version: '8.5' server-path: './test-server' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify installation run: | test -d ./test-server || exit 1 test -d ./test-server/node_modules || exit 1 node --version npm --version php --version composer --version nginx -v chmod +x ./scripts/health-check.sh ./scripts/health-check.sh ./test-server true true true echo "✓ All components installation successful" - name: Run integration tests run: | cd ./test-server if [ -f package.json ] && grep -q '"test:integration"' package.json; then npm run test:integration else echo "⚠ No integration test script configured, skipping" fi test-custom-paths: name: Test Custom Server Path runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with custom path uses: ./ with: install-node: 'true' server-path: './my-custom-server' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify installation run: | test -d ./my-custom-server || exit 1 test -d ./my-custom-server/node_modules || exit 1 echo "✓ Custom path installation successful" - name: Run server tests run: | cd ./my-custom-server if [ -f package.json ] && grep -q '"test"' package.json; then npm test else echo "⚠ No test script configured, skipping" fi test-build-command: name: Test Build Command runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Test action with build command uses: ./ with: install-node: 'true' server-path: './test-server' build-command: 'echo "Build complete" > build.log' server-repository: ${{ env.TEST_SERVER_REPOSITORY }} server-ref: ${{ env.TEST_SERVER_REF }} github-server-url: ${{ env.TEST_GIT_SERVER_URL }} checkout-token: ${{ secrets.TEST_SERVER_TOKEN }} - name: Verify build run: | cd ./test-server test -f build.log grep -q '^Build complete$' build.log echo "✓ Custom build command completed successfully"