Fix: Use unique database per job for parallel test execution #90
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [master, main] | |
| pull_request: | |
| branches: [master, main] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| ruby: ['3.3', '3.4', '4.0'] | |
| gemfile: | |
| - rails_7.x_active_admin_4.x | |
| - rails_8.x_active_admin_4.x | |
| env: | |
| BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile | |
| RAILS_ENV: test | |
| PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/ms-playwright | |
| # Unique database suffix for parallel test execution | |
| GITHUB_JOB: test-ruby${{ matrix.ruby }}-${{ matrix.gemfile }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: ${{ matrix.ruby }} | |
| bundler-cache: true | |
| # Install Playwright dependencies | |
| - name: Install Playwright APT dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libdbus-1-3 libatspi2.0-0 libx11-6 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxrandr2 libgbm1 libxcb1 libxkbcommon0 libpango-1.0-0 libcairo2 libasound2t64 | |
| # Get Playwright version for cache key | |
| - name: Get Playwright version | |
| id: playwright-version | |
| run: | | |
| PLAYWRIGHT_VERSION=$(npm ls @playwright/test 2>/dev/null | grep @playwright/test | sed 's/.*@//' | head -1) | |
| if [ -z "$PLAYWRIGHT_VERSION" ]; then | |
| PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //') | |
| fi | |
| echo "version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT | |
| # Cache Playwright browsers | |
| - name: Cache Playwright browsers | |
| id: playwright-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ github.workspace }}/ms-playwright | |
| key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}- | |
| ${{ runner.os }}-playwright- | |
| - name: Install npm dependencies | |
| run: | | |
| cd npm-package | |
| npm install | |
| - name: Build and install npm package | |
| run: | | |
| # Build the npm package | |
| cd npm-package | |
| npm pack | |
| # Extract it to a temporary location | |
| mkdir -p /tmp/npm-package | |
| tar -xzf *.tgz -C /tmp/npm-package | |
| # Update spec/internal to use the extracted package | |
| cd ../spec/internal | |
| # Remove any existing symlink/folder | |
| rm -rf package | |
| rm -rf node_modules/activeadmin-tom_select | |
| npm install | |
| # Install from the extracted package | |
| npm install /tmp/npm-package/package | |
| # Build assets (JS and CSS) | |
| echo "Building JavaScript assets..." | |
| npm run build:js | |
| echo "Building CSS assets with Tailwind..." | |
| bundle exec rake active_admin:build | |
| # Verify assets were built | |
| echo "Checking built assets..." | |
| ls -la app/assets/builds/ | |
| - name: Install Playwright browsers | |
| if: steps.playwright-cache.outputs.cache-hit != 'true' | |
| run: | | |
| cd npm-package | |
| npx playwright install chromium | |
| - name: Setup test database | |
| run: | | |
| cd spec/internal | |
| ./bin/rails db:create db:schema:load RAILS_ENV=test | |
| - name: Run tests with coverage | |
| run: | | |
| bundle exec rspec --format progress --format RspecJunitFormatter --out rspec-results.xml | |
| - name: Fix coverage paths for SonarQube | |
| if: matrix.ruby == '3.4' && matrix.gemfile == 'rails_7.x_active_admin_4.x' | |
| run: | | |
| # SonarQube runs in Docker container where workspace is /github/workspace | |
| # Coverage has paths like /home/runner/work/activeadmin-tom_select/activeadmin-tom_select/ | |
| # Need to replace GitHub runner paths with Docker container paths | |
| if [ -f coverage/coverage.json ]; then | |
| sed -i "s|/home/runner/work/activeadmin-tom_select/activeadmin-tom_select/|/github/workspace/|g" coverage/coverage.json | |
| echo "Coverage paths fixed for SonarQube Docker container" | |
| fi | |
| - name: SonarQube Scan | |
| if: matrix.ruby == '3.4' && matrix.gemfile == 'rails_7.x_active_admin_4.x' && github.event_name != 'pull_request' | |
| uses: sonarsource/sonarqube-scan-action@v3 | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL || 'https://sonarcloud.io' }} | |
| with: | |
| args: > | |
| -Dsonar.projectKey=rs-pro_activeadmin-tom_select | |
| -Dsonar.ruby.coverage.reportPaths=coverage/coverage.json | |
| -Dsonar.ruby.rspec.reportPaths=rspec-results.xml | |
| continue-on-error: true | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.4' | |
| bundler-cache: true | |
| - name: Run RuboCop | |
| run: bundle exec rubocop --force-exclusion | |
| build-npm: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| cache-dependency-path: npm-package/package-lock.json | |
| - name: Install dependencies | |
| run: | | |
| cd npm-package | |
| npm ci | |
| - name: Check package | |
| run: | | |
| cd npm-package | |
| npm pack --dry-run |