mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
32ac8e73fd
* Fix Biome lint violations and add Biome CI check Biome was not configured to respect .gitignore, so ~92% of the 13,355 reported diagnostics came from gitignored build artifacts. Enable VCS integration (useIgnoreFile), apply safe auto-fixes across the repo, fix the remaining mechanical errors by hand, downgrade judgment-call a11y / dangerouslySetInnerHTML rules to warnings, and add a 'biome ci' job to the Lint workflow so violations block PRs going forward. * Use an empty changeset (no behavior change, no release needed)
138 lines
4.1 KiB
JavaScript
138 lines
4.1 KiB
JavaScript
import { execSync } from 'node:child_process';
|
|
import { createHash } from 'node:crypto';
|
|
import {
|
|
copyFileSync,
|
|
existsSync,
|
|
readdirSync,
|
|
readFileSync,
|
|
writeFileSync,
|
|
} from 'node:fs';
|
|
|
|
function runCommand(command) {
|
|
try {
|
|
execSync(command, { stdio: 'inherit', shell: true });
|
|
} catch (error) {
|
|
console.error(`Command failed: ${command}: ${error}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
function commandExists(command) {
|
|
try {
|
|
execSync(`${command} --version`, { stdio: 'ignore', shell: true });
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
console.log('Building swc-plugin-workflow WASM...');
|
|
|
|
// Check if cargo is installed
|
|
if (!commandExists('cargo')) {
|
|
if (process.env.CI) {
|
|
console.log('Installing Rust...');
|
|
if (process.platform === 'win32') {
|
|
runCommand(
|
|
'powershell -Command "iwr https://win.rustup.rs -OutFile rustup-init.exe; .\\rustup-init.exe -y --profile minimal; del rustup-init.exe"'
|
|
);
|
|
} else {
|
|
runCommand(
|
|
'curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal'
|
|
);
|
|
// Add Rust to PATH for this process so cargo commands work
|
|
const cargoPath = `${process.env.HOME}/.cargo/bin`;
|
|
process.env.PATH = `${cargoPath}:${process.env.PATH}`;
|
|
console.log('Rust installed and PATH updated');
|
|
}
|
|
} else {
|
|
console.error('Rust is required but not installed.');
|
|
console.error(
|
|
'Please visit https://rustup.rs and follow the installation instructions.'
|
|
);
|
|
console.error(
|
|
'After installing, run "rustup target add wasm32-unknown-unknown"'
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Check if wasm32-unknown-unknown target exists and install if needed
|
|
console.log('Checking wasm32-unknown-unknown target...');
|
|
try {
|
|
const installedTargets = execSync('rustup target list --installed', {
|
|
stdio: 'pipe',
|
|
shell: true,
|
|
}).toString();
|
|
if (!installedTargets.includes('wasm32-unknown-unknown')) {
|
|
console.log('wasm32-unknown-unknown target not found, installing...');
|
|
runCommand('rustup target add wasm32-unknown-unknown');
|
|
} else {
|
|
console.log('wasm32-unknown-unknown target already installed');
|
|
}
|
|
} catch (error) {
|
|
console.error(
|
|
'Failed to check/install wasm32-unknown-unknown target:',
|
|
error.message
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Build the WASM plugin
|
|
console.log('Running cargo build...');
|
|
runCommand('cargo build-wasm32 --release -p swc_plugin_workflow');
|
|
|
|
// Copy the WASM file
|
|
const wasmSource = new URL(
|
|
'../../target/wasm32-unknown-unknown/release/swc_plugin_workflow.wasm',
|
|
import.meta.url
|
|
);
|
|
const wasmDest = new URL('swc_plugin_workflow.wasm', import.meta.url);
|
|
console.log(`Source: ${wasmSource}`);
|
|
console.log(`Destination: ${wasmDest}`);
|
|
|
|
if (!existsSync(wasmSource)) {
|
|
console.error(`WASM file not found at ${wasmSource}`);
|
|
console.error(
|
|
'The cargo build may have failed or produced output at a different location.'
|
|
);
|
|
|
|
// TODO: Remove this once we verify what's going on in CI
|
|
try {
|
|
const targetDir = new URL('../../target', import.meta.url);
|
|
console.error('\nDebug: Listing target directory contents...');
|
|
const files = readdirSync(targetDir, { recursive: true });
|
|
const wasmFiles = files.filter(
|
|
(f) => typeof f === 'string' && f.endsWith('.wasm')
|
|
);
|
|
console.error(
|
|
`Found ${files.length} total files, ${wasmFiles.length} WASM-related`
|
|
);
|
|
if (wasmFiles.length > 0) {
|
|
console.error('WASM files:', wasmFiles.slice(0, 10));
|
|
} else {
|
|
console.error('Sample files in target:', files.slice(0, 20));
|
|
}
|
|
} catch (err) {
|
|
console.error('Debug: Cannot read target directory:', err.message);
|
|
}
|
|
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('Copying WASM file...');
|
|
copyFileSync(wasmSource, wasmDest);
|
|
|
|
// Generate hash of the WASM file for cache invalidation
|
|
console.log('Generating build hash...');
|
|
const wasmContent = readFileSync(wasmDest);
|
|
const buildHash = createHash('sha256')
|
|
.update(wasmContent)
|
|
.digest('hex')
|
|
.slice(0, 16);
|
|
const buildHashPath = new URL('build-hash.json', import.meta.url);
|
|
writeFileSync(buildHashPath, JSON.stringify({ buildHash }, null, 2));
|
|
console.log(`Build hash: ${buildHash}`);
|
|
|
|
console.log('Build complete!');
|