-
-
Notifications
You must be signed in to change notification settings - Fork 28
[#1976] Upload SUT test artifacts in vortex-test-workflow CI #2255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,9 @@ protected function tearDown(): void { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $test_failed = $this->status() instanceof Failure || $this->status() instanceof Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Collect SUT test artifacts before cleanup. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->collectSutArtifacts($test_failed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($test_failed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->logNote('Skipping cleanup as test has failed.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->log(static::locationsInfo()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,6 +82,29 @@ protected function tearDown(): void { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parent::tearDown(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected function collectSutArtifacts(bool $test_failed): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // On failure, containers are still running but syncToHost() may not have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // been called before the failure. Try to sync artifacts from the container. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($test_failed && !$this->volumesMounted()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->syncToHost('.logs'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (\Throwable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ignore - container may not be running or .logs may not exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $sut_logs = static::$sut . '/.logs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!is_dir($sut_logs)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dest = dirname(__DIR__, 2) . '/.logs/sut/' . $this->name(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File::copy($sut_logs, $dest); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->logNote('SUT test artifacts copied to: ' . $dest); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+102
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 🧩 Analysis chain🏁 Script executed: # Find the File class being used
rg 'class File' --type php -A 5 | head -50Repository: drevops/vortex Length of output: 40 🏁 Script executed: # Look for File class imports or usage
rg 'use.*File' .vortex/tests/phpunit/Functional/FunctionalTestCase.phpRepository: drevops/vortex Length of output: 85 🏁 Script executed: # Search for File::copy definition
rg 'function copy\(' --type phpRepository: drevops/vortex Length of output: 40 🏁 Script executed: # Check if File class is from a composer package
cat composer.json | jq '.require, .require-dev' 2>/dev/null || find . -name "composer.json" -type f -exec cat {} \; | head -100Repository: drevops/vortex Length of output: 4691 🌐 Web query:
💡 Result: For Example (from the v0.19.0 README): use AlexSkrypnyk\File\Exception\FileException;
use AlexSkrypnyk\File\File;
try {
File::copy('/path/to/source', '/path/to/destination');
} catch (FileException $e) {
echo $e->getMessage();
}
``` [1]
**Where it’s listed:**
- “Available Methods” table: **`copy()` — Copy file or directory.** [1]
**Source:** Packagist README for `alexskrypnyk/file` **0.19.0**. [1]
References:
[1] https://packagist.org/packages/alexskrypnyk/file
---
🌐 Web query:
`github AlexSkrypnyk file php copy method parent directories`
💡 Result:
I couldn’t find a specific `File.php` (or a `copy()` implementation) in an `AlexSkrypnyk` GitHub repo from that query, but in plain PHP the key point is: **`copy($from, $to)` will fail if the destination directory doesn’t exist**—it does not create parent directories for you. [1]
Create the parent dirs first (recursively), then copy:
```php
$from = $src;
$to = $dst;
$dir = dirname($to);
if (!is_dir($dir)) {
mkdir($dir, 0777, true); // recursive parent directories
}
if (!copy($from, $to)) {
throw new RuntimeException("Failed to copy $from to $to");
}
Sources: [1] [2] Defensive directory creation + copy error handling. The ♻️ Suggested hardening- $dest = dirname(__DIR__, 2) . '/.logs/sut/' . $test_id;
- File::copy($sut_logs, $dest);
+ $dest_root = dirname(__DIR__, 2) . '/.logs/sut';
+ if (!is_dir($dest_root) && !mkdir($dest_root, 0777, TRUE) && !is_dir($dest_root)) {
+ $this->logNote('Unable to create SUT artifacts directory: ' . $dest_root);
+ return;
+ }
+ $dest = $dest_root . '/' . $test_id;
+ try {
+ File::copy($sut_logs, $dest);
+ }
+ catch (\Throwable $e) {
+ $this->logNote('Failed to copy SUT artifacts: ' . $e->getMessage());
+ return;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * {@inheritdoc} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.