Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/actions/version-matrix/src/matrices/node/normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import {
setParametersForTriggeringUpdateWorkflowOnActorTemplates,
supportedNodeVersions,
} from '../../shared/constants.ts';
import { resolveCrawleeVersionForApify } from '../../shared/crawlee.ts';
import { fetchPackageVersions } from '../../shared/npm.ts';
import { fetchNodeRuntimeVersions } from '../../shared/runtime-versions.ts';

const apifyVersions = await fetchPackageVersions('apify');
const crawleeVersions = await fetchPackageVersions('crawlee');
const nodeRuntimeVersions = await fetchNodeRuntimeVersions(supportedNodeVersions);

let latestCrawleeVersion = crawleeVersions.at(-1)!;
let latestApifyVersion = apifyVersions.at(-1)!;
let latestCrawleeVersion = await resolveCrawleeVersionForApify(latestApifyVersion, crawleeVersions);

console.error('Latest crawlee version:', latestCrawleeVersion);
console.error('Latest apify version:', latestApifyVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
shouldUseLastFive,
supportedNodeVersions,
} from '../../shared/constants.ts';
import { resolveCrawleeVersionForApify } from '../../shared/crawlee.ts';
import { fetchPackageVersions } from '../../shared/npm.ts';
import { fetchNodeRuntimeVersions } from '../../shared/runtime-versions.ts';

Expand All @@ -28,7 +29,7 @@ if (!shouldUseLastFive) {
const latestFivePlaywrightVersions = playwrightVersions.slice(shouldUseLastFive ? -5 : -1);
const latestPlaywrightVersion = latestFivePlaywrightVersions.at(-1)!;
let latestApifyVersion = apifyVersions.at(-1)!;
let latestCrawleeVersion = crawleeVersions.at(-1)!;
let latestCrawleeVersion = await resolveCrawleeVersionForApify(latestApifyVersion, crawleeVersions);
let latestCamoufoxVersion = camoufoxVersions.at(-1)!;

// Camoufox does not support every Playwright release, so its images are built with the newest Playwright versions it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
shouldUseLastFive,
supportedNodeVersions,
} from '../../shared/constants.ts';
import { resolveCrawleeVersionForApify } from '../../shared/crawlee.ts';
import { fetchPackageVersions } from '../../shared/npm.ts';
import { fetchNodeRuntimeVersions } from '../../shared/runtime-versions.ts';

Expand All @@ -21,7 +22,7 @@ if (!shouldUseLastFive) {
const latestFivePuppeteerVersions = puppeteerVersions.slice(shouldUseLastFive ? -5 : -1);
const latestPuppeteerVersion = latestFivePuppeteerVersions.at(-1)!;
let latestApifyVersion = apifyVersions.at(-1)!;
let latestCrawleeVersion = crawleeVersions.at(-1)!;
let latestCrawleeVersion = await resolveCrawleeVersionForApify(latestApifyVersion, crawleeVersions);

console.error('Latest five versions', latestFivePuppeteerVersions);
console.error('Latest apify version', latestApifyVersion);
Expand Down
21 changes: 21 additions & 0 deletions .github/actions/version-matrix/src/shared/crawlee.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import { resolveCrawleeVersionForApify } from './crawlee.ts';

const crawleeVersions = ['3.17.0', '3.18.1', '3.18.2', '4.0.0'];

describe('resolveCrawleeVersionForApify', () => {
it('picks the newest crawlee version inside the range apify declares', async () => {
// apify 3.8.0 declares `@crawlee/core: ^3.18.2`
assert.equal(await resolveCrawleeVersionForApify('3.8.0', crawleeVersions), '3.18.2');
});

it('falls back to the newest crawlee version when nothing satisfies the range', async () => {
assert.equal(await resolveCrawleeVersionForApify('3.8.0', ['2.0.0', '4.0.0']), '4.0.0');
});

it('falls back to the newest crawlee version when the apify manifest cannot be read', async () => {
assert.equal(await resolveCrawleeVersionForApify('0.0.0-does-not-exist', crawleeVersions), '4.0.0');
});
});
46 changes: 46 additions & 0 deletions .github/actions/version-matrix/src/shared/crawlee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { satisfies } from 'semver';
import { fetchPackageManifest } from './npm.ts';

/**
* Picks the newest crawlee version the given apify version can run with, based on the range apify declares for
* `@crawlee/core`.
*
* The images force apify's `@crawlee/*` dependencies to the installed crawlee version, so pairing apify with a
* crawlee major it was not built for (e.g. crawlee 4 released before apify 4) produces an image that crashes on
* `require('apify')`.
*
* Falls back to the newest crawlee version if the range cannot be read or nothing satisfies it.
*/
export async function resolveCrawleeVersionForApify(apifyVersion: string, crawleeVersions: string[]) {
const latestCrawleeVersion = crawleeVersions.at(-1)!;

let range: string | undefined;

try {
const manifest = await fetchPackageManifest('apify', apifyVersion);

range = manifest.dependencies?.['@crawlee/core'] ?? manifest.peerDependencies?.['@crawlee/core'];
} catch (error) {
console.error(`Failed to read the supported crawlee range from apify@${apifyVersion}`, error);
}

if (range === undefined) {
return latestCrawleeVersion;
}

const compatibleVersion = crawleeVersions.findLast((version) => satisfies(version, range));

if (compatibleVersion === undefined) {
console.error(`No crawlee version satisfies ${range} (from apify@${apifyVersion}), using the latest one`);

return latestCrawleeVersion;
}

if (compatibleVersion !== latestCrawleeVersion) {
console.error(
`apify@${apifyVersion} supports crawlee ${range}, using crawlee@${compatibleVersion} instead of ${latestCrawleeVersion}`,
);
}

return compatibleVersion;
}
Loading