Skip to content

Commit ac2bb77

Browse files
authored
fix(ingest): tolerate missing artifacts and reuse-bundle collisions (#438)
1 parent e2afb9f commit ac2bb77

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

.github/workflows/ingest-results.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,31 @@ jobs:
5656
sleep "$attempt"
5757
done
5858
if [ "$ok" = false ]; then
59-
echo "::error::Failed to download artifact after 3 attempts: ${name} — skipping"
59+
echo "::warning::Failed to download artifact after 3 attempts: ${name} — skipping"
6060
rm -f artifact.zip
61-
echo 1 >> "$ARTIFACTS_PATH/.failures"
61+
echo "$name" >> "$ARTIFACTS_PATH/.failures"
6262
continue
6363
fi
6464
mkdir -p "${ARTIFACTS_PATH}/${name}"
65-
unzip -o artifact.zip -d "${ARTIFACTS_PATH}/${name}"
66-
rm artifact.zip
65+
if ! unzip -o artifact.zip -d "${ARTIFACTS_PATH}/${name}"; then
66+
echo "::warning::Failed to extract artifact: ${name} — skipping"
67+
rm -rf "${ARTIFACTS_PATH:?}/${name}"
68+
echo "$name" >> "$ARTIFACTS_PATH/.failures"
69+
fi
70+
rm -f artifact.zip
6771
done
6872
69-
echo "Downloaded artifacts:"
70-
ls "$ARTIFACTS_PATH/"
71-
7273
if [ -f "$ARTIFACTS_PATH/.failures" ]; then
7374
count=$(wc -l < "$ARTIFACTS_PATH/.failures")
7475
rm "$ARTIFACTS_PATH/.failures"
75-
echo "::error::${count} artifact(s) failed to download"
76+
echo "::warning::${count} artifact(s) failed to download; ingesting what's available"
77+
fi
78+
79+
echo "Downloaded artifacts:"
80+
ls "$ARTIFACTS_PATH/"
81+
82+
if [ -z "$(ls -A "$ARTIFACTS_PATH")" ]; then
83+
echo "::error::No artifacts could be downloaded from run ${RUN_ID}"
7684
exit 1
7785
fi
7886
@@ -92,8 +100,9 @@ jobs:
92100
name=$(basename "$child")
93101
dest="$ARTIFACTS_PATH/$name"
94102
if [ -e "$dest" ]; then
95-
echo "::error::Cannot flatten reused artifact '$name'; destination already exists"
96-
exit 1
103+
echo "::warning::Skipping reused artifact '$name'; the run has a fresher copy"
104+
rm -rf "$child"
105+
continue
97106
fi
98107
mv "$child" "$dest"
99108
echo " $name"

packages/db/src/etl/reused-ingest-metadata.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,23 @@ describe('flattenReusedIngestArtifactBundle', () => {
113113
expect(readReusedIngestMetadata(root)?.sourceRunId).toBe('25763435778');
114114
});
115115

116-
it('rejects flattening when it would overwrite an existing artifact', () => {
116+
it('keeps the run-local artifact when a reused artifact collides', () => {
117117
const root = tempDir();
118118
fs.mkdirSync(path.join(root, 'results_bmk'));
119+
fs.writeFileSync(path.join(root, 'results_bmk', 'fresh.json'), '[]');
119120
fs.mkdirSync(path.join(root, 'reused-ingest-artifacts', 'results_bmk'), {
120121
recursive: true,
121122
});
123+
fs.writeFileSync(
124+
path.join(root, 'reused-ingest-artifacts', 'results_bmk', 'reused.json'),
125+
'[]',
126+
);
127+
fs.mkdirSync(path.join(root, 'reused-ingest-artifacts', 'run-stats'), { recursive: true });
122128

123-
expect(() => flattenReusedIngestArtifactBundle(root)).toThrow(/destination already exists/u);
129+
expect(flattenReusedIngestArtifactBundle(root)).toEqual(['run-stats']);
130+
expect(fs.existsSync(path.join(root, 'reused-ingest-artifacts'))).toBe(false);
131+
expect(fs.existsSync(path.join(root, 'run-stats'))).toBe(true);
132+
expect(fs.existsSync(path.join(root, 'results_bmk', 'fresh.json'))).toBe(true);
133+
expect(fs.existsSync(path.join(root, 'results_bmk', 'reused.json'))).toBe(false);
124134
});
125135
});

packages/db/src/etl/reused-ingest-metadata.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export function flattenReusedIngestArtifactBundle(rootDir: string): string[] {
1919
const source = path.join(bundleDir, name);
2020
const dest = path.join(rootDir, name);
2121
if (fs.existsSync(dest)) {
22-
throw new Error(`Cannot flatten reused artifact '${name}'; destination already exists`);
22+
// The run re-produced this artifact itself; the fresh copy wins over
23+
// the one reused from the source run.
24+
console.warn(` [WARN] Skipping reused artifact '${name}'; the run has a fresher copy`);
25+
fs.rmSync(source, { recursive: true, force: true });
26+
continue;
2327
}
2428
fs.renameSync(source, dest);
2529
moved.push(name);

0 commit comments

Comments
 (0)