diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index c61f9ca..6db7acb 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -13,13 +13,25 @@ jobs: if: ${{ !env.ACT }} uses: actions/checkout@v4 + - name: Determine branch for E2E setup + id: branch + env: + EVENT_NAME: ${{ github.event_name }} + PR_HEAD: ${{ github.event.pull_request.head.ref }} + run: | + if [ "$EVENT_NAME" = "pull_request" ]; then + echo "branch_name=$PR_HEAD" >> $GITHUB_OUTPUT + else + echo "branch_name=base" >> $GITHUB_OUTPUT + fi + - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '20' cache: 'npm' - - name: Install dependencies + - name: Install JS dependencies run: npm ci - name: Setup PHP @@ -37,11 +49,19 @@ jobs: composer-8.2-L12 composer-8.2 + - name: Cache Playwright browsers + uses: actions/cache@v3 + with: + path: ~/.cache/ms-playwright + key: playwright-browsers-${{ runner.os }}-v1 + restore-keys: | + playwright-browsers-${{ runner.os }}- + - name: Install Playwright Browsers - run: npx playwright install --with-deps + run: npx playwright install - name: Setup E2E test repo - run: bash tests/E2E/setup.sh + run: bash tests/E2E/setup.sh "${{ steps.branch.outputs.branch_name }}" - name: Run Playwright tests run: bash tests/E2E/launch.sh & (sleep 5 && npm run test:e2e) diff --git a/tests/E2E/install-current-nimbus-branch.php b/tests/E2E/install-current-nimbus-branch.php new file mode 100644 index 0000000..bb46021 --- /dev/null +++ b/tests/E2E/install-current-nimbus-branch.php @@ -0,0 +1,95 @@ + 'path', + 'url' => $localPackagePath, + 'options' => [ + 'symlink' => true, + ], + ]; +} + +/** + * Ensure require section exists. + */ +$composerJson['require'] ??= []; + +if (! array_key_exists($packageName, $composerJson['require'])) { + fwrite( + STDERR, + "Error: Package '{$packageName}' is not present in require.\n" + ); + exit(1); +} + +/** + * Force the package version to the requested dev branch. + */ +$composerJson['require'][$packageName] = "dev-{$branchName}"; + +/** + * Write back composer.json with stable formatting. + */ +file_put_contents( + $composerFilePath, + json_encode( + $composerJson, + JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES + ).PHP_EOL +); + +echo "composer.json updated successfully.\n"; diff --git a/tests/E2E/launch.sh b/tests/E2E/launch.sh index 75a889e..b66a89a 100644 --- a/tests/E2E/launch.sh +++ b/tests/E2E/launch.sh @@ -2,20 +2,65 @@ set -euo pipefail +print_help() { + cat </dev/null 2>&1; then - composer install --no-progress --ansi + echo "Setting current Nimbus branch in composer..." + php "$SCRIPT_DIR/install-current-nimbus-branch.php" "$BRANCH_NAME" + + echo "Installing/updating nimbus PHP package..." + composer update sunchayn/nimbus --no-progress --ansi else echo "Composer is not installed. Aborting." exit 1 fi +# Install Node dependencies +if command -v npm >/dev/null 2>&1; then + echo "Installing Node.js dependencies..." + npm install +else + echo "npm is not installed. Aborting." + exit 1 +fi + # -------------------------------------- # ENVIRONMENT SETUP # -------------------------------------- ENV_FILE="$TARGET_DIR/.env" -rm -f ENV_FILE +echo "Setting up environment file..." +rm -f "$ENV_FILE" cp "$SCRIPT_DIR/.env.template" "$ENV_FILE" -# Install Node dependencies. -if command -v npm >/dev/null 2>&1; then - npm install -else - echo "npm is not installed. Aborting." - exit 1 -fi - # -------------------------------------- # APPLICATION BOOTSTRAP # -------------------------------------- -# Run migrations against a local SQLite database. +echo "Bootstrapping application..." + +# Run migrations against a local SQLite database touch database/database.sqlite php artisan migrate --force -# Publish Nimbus-related frontend assets. +# Publish Nimbus-related frontend assets php artisan vendor:publish --tag=nimbus-assets + +echo "Setup complete. Ready for E2E tests or further local usage."