moviestar

CI/CD Integration Guide

This guide explains how to integrate POD authentication testing into continuous integration and deployment pipelines. For general adaptation, see Adapting for Your App.

Documentation index: See README.md for complete documentation navigation.

Overview

Running integration tests with POD authentication in CI/CD requires:

GitHub Actions Integration

Complete Workflow Example

name: Integration Tests

on:
  push:
    branches: [main, dev]
  pull_request:
    branches: [main, dev]

jobs:
  integration-test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: 'stable'
          flutter-version: '3.24.0'

      - name: Install Chrome
        run: |
          wget -q -O - \
            https://dl-ssl.google.com/linux/linux_signing_key.pub \
            | sudo apt-key add -
          sudo sh -c 'echo "deb [arch=amd64] \
            http://dl.google.com/linux/chrome/deb/ stable main" \
            >> /etc/apt/sources.list.d/google.list'
          sudo apt-get update
          sudo apt-get install -y google-chrome-stable

      - name: Install dependencies
        run: flutter pub get

      - name: Setup test credentials
        run: |
          mkdir -p integration_test/fixtures
          echo '$' \
            > integration_test/fixtures/test_credentials.json

      - name: Generate auth data
        run: |
          dart run integration_test/tools/generate_auth_data.dart

      - name: Run integration tests
        run: |
          flutter test integration_test/app_test.dart \
            -d linux --dart-define=INTERACT=0
          flutter test integration_test/workflows/your_test.dart \
            -d linux --dart-define=INTERACT=0

Workflow Breakdown

Chrome installation:

Test credentials setup:

Auth data generation:

Individual test execution:

Storing Credentials Securely

GitHub Secrets Setup

Navigate to repository settings:

Repository → Settings → Secrets and variables → Actions

Add secret named TEST_CREDENTIALS with JSON content:

{
  "email": "test@example.com",
  "password": "your-test-password",
  "securityKey": "1234",
  "webId": "https://pods.example.com/test/profile/card#me",
  "podUrl": "https://pods.example.com/test/",
  "issuer": "https://pods.example.com/"
}

Using Secrets in Workflow

- name: Setup test credentials
  run: |
    mkdir -p integration_test/fixtures
    echo '$' \
      > integration_test/fixtures/test_credentials.json

Multi-Environment Secrets

For different environments (staging, production):

- name: Setup credentials (staging)
  if: github.ref == 'refs/heads/dev'
  run: |
    echo '$' \
      > integration_test/fixtures/test_credentials.json

- name: Setup credentials (production)
  if: github.ref == 'refs/heads/main'
  run: |
    echo '$' \
      > integration_test/fixtures/test_credentials.json

Alternative Approaches

Option A: Pre-Generated Tokens (Faster)

Generate tokens locally, encrypt, store in CI:

# Generate auth data locally
dart run integration_test/tools/generate_auth_data.dart

# Encrypt the file
gpg --symmetric --cipher-algo AES256 \
  integration_test/fixtures/complete_auth_data.json

# Commit encrypted version
git add integration_test/fixtures/complete_auth_data.json.gpg
git commit -m "Add encrypted auth data for CI"

CI workflow:

- name: Decrypt auth data
  run: |
    echo "$" | \
      gpg --quiet --batch --yes --decrypt \
      --passphrase-fd 0 \
      --output integration_test/fixtures/complete_auth_data.json \
      integration_test/fixtures/complete_auth_data.json.gpg

Pros:

Cons:

Option B: On-Demand Generation (Current)

Generate fresh tokens in CI using browser automation:

- name: Generate auth data
  run: dart run integration_test/tools/generate_auth_data.dart

Pros:

Cons:

Option C: Mock POD Service

Create mock POD service for CI that bypasses real authentication:

// In test setup
if (const bool.fromEnvironment('CI')) {
  // Use mock auth for CI
  await MockAuthService.injectMockCredentials();
} else {
  // Use real auth for local development
  await CredentialInjector.injectFullAuth();
}

Pros:

Cons:

Platform-Specific CI Configuration

Linux (Ubuntu)

runs-on: ubuntu-latest
steps:
  - name: Install Chrome
    run: |
      sudo apt-get update
      sudo apt-get install -y google-chrome-stable

  - name: Run tests
    run: flutter test integration_test/ -d linux

macOS

runs-on: macos-latest
steps:
  - name: Install Chrome
    run: brew install --cask google-chrome

  - name: Run tests
    run: flutter test integration_test/ -d macos

Windows

runs-on: windows-latest
steps:
  - name: Install Chrome
    run: |
      choco install googlechrome -y

  - name: Run tests
    run: flutter test integration_test/ -d windows

Migration Checklist for CI/CD

When setting up CI/CD for your adapted app:

Phase 1: Secrets Setup

Phase 2: Workflow Configuration

Phase 3: Test Execution

Phase 4: Verification

Troubleshooting CI Issues

Chrome Not Found

Symptom: Puppeteer can’t find Chrome executable

Solution: Verify Chrome installation in workflow:

- name: Verify Chrome installation
  run: which google-chrome || which chromium-browser

Auth Generation Timeout

Symptom: Browser automation times out in CI

Solution: Increase timeout or use pre-generated tokens:

// In generate_auth_data.dart
final browser = await puppeteer.launch(
  timeout: Duration(minutes: 5),  // Increased from default
);

Tests Fail in CI but Pass Locally

Symptom: Integration tests fail only in CI environment

Possible causes:

Solution: Add debug logging:

- name: Run tests with verbose output
  run: |
    flutter test integration_test/ \
      -d linux --dart-define=INTERACT=0 --verbose

Batch Mode Failures

Symptom: First test passes, subsequent tests fail

Solution: Run tests individually (see example workflow above)

- name: Run tests individually
  run: |
    flutter test integration_test/app_test.dart -d linux
    flutter test integration_test/workflows/test1.dart -d linux
    flutter test integration_test/workflows/test2.dart -d linux

See Also