Skip to content

Commit 6150581

Browse files
committed
fix: refactor integration tests to use cached fixtures and remove build-fixtures.sh
1 parent 1ab0db6 commit 6150581

File tree

3 files changed

+67
-219
lines changed

3 files changed

+67
-219
lines changed

.github/workflows/integration-tests.yml

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
paths:
77
- 'booster/**'
88
- 'tools/internal-test/**'
9-
- 'tools/build-fixtures.sh'
109
- '.github/workflows/integration-tests.yml'
1110
pull_request:
1211
branches: [main, develop]
@@ -103,7 +102,7 @@ jobs:
103102
uses: actions/cache@v4
104103
with:
105104
path: tests/.fixtures-cache
106-
key: ${{ runner.os }}-test-fixtures-v2-${{ matrix.project_type }}-${{ hashFiles('tools/build-fixtures.sh') }}
105+
key: ${{ runner.os }}-test-fixtures-v2-${{ matrix.project_type }}-${{ hashFiles('tools/internal-test/lib/project_setup.py') }}
107106
restore-keys: |
108107
${{ runner.os }}-test-fixtures-v2-${{ matrix.project_type }}-
109108
${{ runner.os }}-test-fixtures-v2-
@@ -119,6 +118,10 @@ jobs:
119118
ddev config global --omit-containers=ddev-ssh-agent
120119
ddev version
121120
121+
- name: Start DDEV for fixture building
122+
run: |
123+
ddev start
124+
122125
- name: Check requirements
123126
run: |
124127
python3 tools/internal-test/test-integration.py env-check
@@ -178,27 +181,6 @@ jobs:
178181
179182
echo "booster.zip contains all expected manifest and runtime files."
180183
181-
- name: Build test fixtures if not cached
182-
run: |
183-
TARGET_PROJECT="${{ matrix.project_type }}"
184-
185-
if [ ! -d "tests/.fixtures-cache/$TARGET_PROJECT" ]; then
186-
echo "📦 Building $TARGET_PROJECT fixture (first run or cache miss)..."
187-
chmod +x tools/build-fixtures.sh
188-
mkdir -p tests/.fixtures-cache
189-
bash tools/build-fixtures.sh tests/.fixtures-cache "$TARGET_PROJECT"
190-
191-
# Extract tarball to cache directory
192-
cd tests/.fixtures-cache
193-
tar xzf "$TARGET_PROJECT-fixture.tar.gz"
194-
195-
echo "✅ $TARGET_PROJECT fixture built and ready"
196-
ls -lh
197-
else
198-
echo "✅ Using cached $TARGET_PROJECT fixture"
199-
ls -lh "tests/.fixtures-cache/$TARGET_PROJECT/FIXTURE_VERSION"
200-
fi
201-
202184
- name: Run integration test
203185
run: |
204186
# Use manual input if workflow_dispatch, otherwise use matrix
@@ -275,7 +257,7 @@ jobs:
275257
uses: actions/cache@v4
276258
with:
277259
path: tests/.fixtures-cache
278-
key: ${{ runner.os }}-test-fixtures-v2-${{ github.event.inputs.project_type }}-${{ hashFiles('tools/build-fixtures.sh') }}
260+
key: ${{ runner.os }}-test-fixtures-v2-${{ github.event.inputs.project_type }}-${{ hashFiles('tools/internal-test/lib/project_setup.py') }}
279261
restore-keys: |
280262
${{ runner.os }}-test-fixtures-v2-${{ github.event.inputs.project_type }}-
281263
${{ runner.os }}-test-fixtures-v2-
@@ -291,6 +273,10 @@ jobs:
291273
ddev config global --omit-containers=ddev-ssh-agent
292274
ddev version
293275
276+
- name: Start DDEV for fixture building
277+
run: |
278+
ddev start
279+
294280
- name: Check requirements
295281
run: |
296282
python3 tools/internal-test/test-integration.py env-check
@@ -349,27 +335,6 @@ jobs:
349335
350336
echo "booster.zip contains all expected manifest and runtime files."
351337
352-
- name: Build test fixtures if not cached
353-
run: |
354-
TARGET_PROJECT="${{ github.event.inputs.project_type }}"
355-
356-
if [ ! -d "tests/.fixtures-cache/$TARGET_PROJECT" ]; then
357-
echo "📦 Building $TARGET_PROJECT fixture (first run or cache miss)..."
358-
chmod +x tools/build-fixtures.sh
359-
mkdir -p tests/.fixtures-cache
360-
bash tools/build-fixtures.sh tests/.fixtures-cache "$TARGET_PROJECT"
361-
362-
# Extract tarball to cache directory
363-
cd tests/.fixtures-cache
364-
tar xzf "$TARGET_PROJECT-fixture.tar.gz"
365-
366-
echo "✅ $TARGET_PROJECT fixture built and ready"
367-
ls -lh
368-
else
369-
echo "✅ Using cached $TARGET_PROJECT fixture"
370-
ls -lh "tests/.fixtures-cache/$TARGET_PROJECT/FIXTURE_VERSION"
371-
fi
372-
373338
- name: Run manual test
374339
run: |
375340
PROJECT_TYPE="${{ github.event.inputs.project_type }}"

tools/build-fixtures.sh

Lines changed: 0 additions & 125 deletions
This file was deleted.

tools/internal-test/lib/project_setup.py

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import shutil
88
import sys
9+
from datetime import datetime
910

1011
from .command_utils import CommandExecutor
1112
from .config import Config
@@ -29,6 +30,8 @@ def __init__(
2930
def setup_project(self) -> None:
3031
"""
3132
Set up the test project.
33+
Tries to use cached fixture first, then creates fresh project if needed.
34+
After creation, automatically caches for future runs.
3235
Exits with code 1 if project already exists or type is unknown.
3336
"""
3437
if self.state.is_project_created():
@@ -42,23 +45,23 @@ def setup_project(self) -> None:
4245
# Create target directory
4346
self.config.target_dir.mkdir(parents=True, exist_ok=True)
4447

45-
# Check if we should use fixtures (default: true)
46-
use_fixtures = os.getenv("USE_TEST_FIXTURES", "true").lower() == "true"
48+
# Try to use cached fixture first
49+
if self._try_use_cached_fixture(self.config.project_type):
50+
self.log.success(f"Project setup complete at {self.config.target_dir} (from cache)")
51+
return
4752

53+
# Create new project if cache not available
4854
if self.config.project_type == "symfony":
49-
if use_fixtures:
50-
self._setup_from_fixtures("symfony")
51-
else:
52-
self._setup_symfony_create_project()
55+
self._create_symfony_project()
5356
elif self.config.project_type == "laravel":
54-
if use_fixtures:
55-
self._setup_from_fixtures("laravel")
56-
else:
57-
self._setup_laravel_create_project()
57+
self._create_laravel_project()
5858
else:
5959
self.log.error(f"Unknown project type: {self.config.project_type}")
6060
sys.exit(1)
6161

62+
# Cache the newly created project for future runs
63+
self._cache_fixture_after_setup(self.config.project_type)
64+
6265
self.log.success(f"Project setup complete at {self.config.target_dir}")
6366

6467
def _get_fixtures_cache_dir(self):
@@ -81,51 +84,30 @@ def _ensure_fixtures_cache(self, project_type: str):
8184
return True
8285

8386
# No cached fixtures available
84-
self.log.info(f"No cached {project_type} fixture found (will be built by CI on first run)")
87+
self.log.info(f"No cached {project_type} fixture found")
8588
return False
8689

87-
def _setup_from_fixtures(self, project_type: str):
88-
"""Set up project by copying from pre-built fixtures"""
89-
self.log.info(f"Setting up {project_type} from fixtures (fast mode)...")
90-
91-
# Ensure we have the fixture (download from releases if needed)
92-
if not self._ensure_fixtures_cache(project_type):
93-
self.log.error(
94-
f"Failed to download {project_type} fixture. "
95-
"Falling back to create-project method..."
96-
)
97-
if project_type == "symfony":
98-
self._setup_symfony_create_project()
99-
else:
100-
self._setup_laravel_create_project()
101-
return
102-
103-
# Get fixture source path
104-
fixtures_cache = self._get_fixtures_cache_dir()
105-
source = fixtures_cache / project_type
90+
def _try_use_cached_fixture(self, project_type: str) -> bool:
91+
"""
92+
Try to use cached fixture. Returns True if successful, False if not available.
93+
If cache exists, sets up DDEV and runs composer install.
94+
"""
95+
cache_source = self._get_fixtures_cache_dir() / project_type
10696

107-
if not source.exists():
108-
self.log.error(
109-
f"Fixture not found at {source} after download. "
110-
"Falling back to create-project method..."
111-
)
112-
if project_type == "symfony":
113-
self._setup_symfony_create_project()
114-
else:
115-
self._setup_laravel_create_project()
116-
return
97+
if not cache_source.exists():
98+
return False
11799

118-
self.log.info(f"Copying {project_type} fixture from cache...")
100+
self.log.info(f"Using cached {project_type} fixture...")
119101

120-
# Copy everything including .git directory
121-
for item in source.iterdir():
102+
# Copy from cache
103+
for item in cache_source.iterdir():
122104
dest = self.config.target_dir / item.name
123105
if item.is_dir():
124106
shutil.copytree(item, dest)
125107
else:
126108
shutil.copy2(item, dest)
127109

128-
# Configure Git
110+
# Configure git
129111
self.log.info("Configuring Git for test environment...")
130112
self.cmd.run_command(
131113
["git", "config", "user.name", "Test User"], cwd=self.config.target_dir
@@ -173,10 +155,36 @@ def _setup_from_fixtures(self, project_type: str):
173155
cwd=self.config.target_dir,
174156
)
175157

176-
self.log.success(f"{project_type.capitalize()} fixture setup complete!")
158+
self.log.success(f"{project_type.capitalize()} fixture loaded from cache!")
159+
return True
160+
161+
def _cache_fixture_after_setup(self, project_type: str) -> None:
162+
"""Cache the project after initial setup for future test runs"""
163+
cache_dir = self._get_fixtures_cache_dir() / project_type
164+
165+
if cache_dir.exists():
166+
self.log.info(f"Cache already exists at {cache_dir}, skipping...")
167+
return
168+
169+
self.log.info(f"Caching {project_type} fixture for future runs...")
170+
cache_dir.mkdir(parents=True, exist_ok=True)
171+
172+
# Copy project directory to cache
173+
for item in self.config.target_dir.iterdir():
174+
dest = cache_dir / item.name
175+
if item.is_dir():
176+
shutil.copytree(item, dest)
177+
else:
178+
shutil.copy2(item, dest)
179+
180+
# Create version file with current date
181+
version_file = cache_dir / "FIXTURE_VERSION"
182+
version_file.write_text(datetime.now().strftime("%Y-%m-%d"))
183+
184+
self.log.success(f"Cached {project_type} fixture at {cache_dir}")
177185

178-
def _setup_symfony_create_project(self) -> None:
179-
"""Set up Symfony project using composer create-project (legacy/fallback method)"""
186+
def _create_symfony_project(self) -> None:
187+
"""Set up Symfony project using composer create-project via DDEV"""
180188
self.log.info("Creating Symfony project using DDEV...")
181189

182190
# Configure DDEV first
@@ -252,8 +260,8 @@ def _setup_symfony_create_project(self) -> None:
252260
cwd=self.config.target_dir,
253261
)
254262

255-
def _setup_laravel_create_project(self):
256-
"""Set up Laravel project using composer create-project (legacy/fallback method)"""
263+
def _create_laravel_project(self):
264+
"""Set up Laravel project using composer create-project via DDEV"""
257265
self.log.info("Creating Laravel project using DDEV...")
258266

259267
# Configure DDEV first

0 commit comments

Comments
 (0)