setup-php/src/fetch.ts
google-labs-jules[bot] a3e458a5fa feat: Enable local PHP setup outside GitHub Actions
This commit introduces a mechanism to use the setup-php scripts for configuring PHP environments on local Linux/Ubuntu machines.

Key changes:
- Added `src/local_installer.ts`: A Node.js script that takes command-line arguments to define the desired PHP setup (version, extensions, tools, INI settings) and generates a `run.sh` script.
- Added `src/local_utils.ts`: A utility module with functions adapted for local execution, removing dependencies on `@actions/core`. It supports fetching inputs from yargs/environment variables.
- Modified `src/fetch.ts`: Replaced `@actions/http-client` with `node-fetch` for compatibility.
- Updated `src/config.ts`, `src/coverage.ts`, `src/extensions.ts`, and `src/tools.ts` to import utilities from `local_utils.ts` instead of `utils.ts`.
- Added `LOCAL_SETUP_INSTRUCTIONS.md`: Comprehensive documentation on prerequisites, how to run the local installer, command-line options, and troubleshooting.

This allows users to leverage the robust PHP environment configuration capabilities of this project directly on their development machines.
2025-06-24 06:07:03 +00:00

38 lines
1.5 KiB
TypeScript

// This is a modified version of fetch.ts for local execution, using node-fetch.
// User should install node-fetch: npm install node-fetch@2
// (or node-fetch@3 if using ESM modules, but this project seems to be CJS for now)
import OriginalNodeFetch from 'node-fetch';
// node-fetch v3 is ESM-only. If the project is CJS, we need v2 or a dynamic import.
// For simplicity, assuming node-fetch v2 or that the project can handle ESM.
// If using ts-node with commonjs, node-fetch v2 is easier.
const fetchModule = OriginalNodeFetch as any; // Type assertion to handle CJS/ESM differences if any
const actualFetch = fetchModule.default || fetchModule; // Handle default export for ESM
interface FetchResult {
data: string | null;
statusCode: number;
error?: string;
}
export async function fetch(url: string): Promise<FetchResult> {
try {
const response = await actualFetch(url, {
// node-fetch options if needed, e.g., timeout, retries (though http-client handled retries)
// For simplicity, no complex retry logic here, but could be added.
});
const data = await response.text();
if (response.ok) {
return { data, statusCode: response.status };
}
return { data, statusCode: response.status, error: `Request failed with status ${response.status}` };
} catch (error: any) {
// console.error(`Fetch error for URL ${url}:`, error);
return {
data: null,
statusCode: 0, // Indicate a client-side error or network issue
error: error.message
};
}
}