|
| 1 | +import { join } from 'node:path'; |
| 2 | +import cache from '@actions/cache'; |
| 3 | +import type { RunOptions } from '../../types'; |
| 4 | +import { $, cd, runInRepo } from '../../utils'; |
| 5 | + |
| 6 | +const isGitHubActions = !!process.env.GITHUB_ACTIONS; |
| 7 | + |
| 8 | +export async function test(options: RunOptions) { |
| 9 | + let nxCachePath: string; |
| 10 | + let nxCacheKey: string; |
| 11 | + |
| 12 | + await runInRepo({ |
| 13 | + ...options, |
| 14 | + repo: 'web-infra-dev/modern.js', |
| 15 | + branch: process.env.MODERN_REF ?? 'v2', |
| 16 | + beforeInstall: async () => { |
| 17 | + if (isGitHubActions) { |
| 18 | + const modernJsDir = join(process.cwd(), 'workspace/modernjs/modern.js'); |
| 19 | + nxCachePath = join(modernJsDir, '.nx/cache'); |
| 20 | + const sha = await $`git rev-parse HEAD`; |
| 21 | + nxCacheKey = `modernjs-nx-${sha.trim()}`; |
| 22 | + const restoreKeys = ['modernjs-nx-']; |
| 23 | + const cacheHitKey = await cache.restoreCache( |
| 24 | + [nxCachePath], |
| 25 | + nxCacheKey, |
| 26 | + restoreKeys, |
| 27 | + ); |
| 28 | + if (cacheHitKey) { |
| 29 | + console.log(`Cache hit for key: ${cacheHitKey}`); |
| 30 | + await $`ls -lah .nx/cache`; |
| 31 | + } else { |
| 32 | + console.log( |
| 33 | + `Cache miss for key: ${nxCacheKey}, proceeding without cache.`, |
| 34 | + ); |
| 35 | + } |
| 36 | + } |
| 37 | + }, |
| 38 | + afterInstall: async () => { |
| 39 | + if (isGitHubActions) { |
| 40 | + console.log('Caching `.nx/cache` directory for future builds.'); |
| 41 | + await $`ls -lah .nx/cache`; |
| 42 | + await cache.saveCache([nxCachePath], nxCacheKey); |
| 43 | + } |
| 44 | + }, |
| 45 | + beforeTest: async () => { |
| 46 | + cd('tests/e2e/builder'); |
| 47 | + await $`pnpm playwright install chromium`; |
| 48 | + cd('../../../'); |
| 49 | + }, |
| 50 | + test: ['test:rspack'], |
| 51 | + }); |
| 52 | +} |
0 commit comments