JavaScript Python PHP
import { stringify } from "yaml";
async function executar(values) {
function generateInfraActions(v) {
const stack = infraChoice(v.stack, ['Node.js', 'Python', 'PHP']), versions = stack === 'Node.js' ? ['22', '24'] : stack === 'Python' ? ['3.12', '3.13'] : ['8.3', '8.4'], runtime = infraChoice(v.runtime, versions);
if (!/^[A-Za-z0-9][A-Za-z0-9/_-]{0,99}$/.test(v.branch) || v.branch.includes('//') || v.branch.endsWith('/'))
throw new Error('Branch inválida: use letras, números, /, _ e -, sem barras repetidas ou finais.');
const lint = infraChoice(v.lint, ['Sim', 'Não']) === 'Sim', test = infraChoice(v.test, ['Sim', 'Não']) === 'Sim', build = infraChoice(v.build, ['Sim', 'Não']) === 'Sim';
const steps = [{ uses: 'actions/checkout@v6', with: { 'persist-credentials': false } }];
if (stack === 'Node.js') {
steps.push({ uses: 'actions/setup-node@v6', with: { 'node-version': runtime, cache: 'npm' } }, { name: 'Instalar dependências', run: 'npm ci' });
if (lint)
steps.push({ name: 'Lint', run: 'npm run lint' });
if (test)
steps.push({ name: 'Testes', run: 'npm test' });
if (build)
steps.push({ name: 'Build', run: 'npm run build' });
}
if (stack === 'Python') {
steps.push({ uses: 'actions/setup-python@v6', with: { 'python-version': runtime, cache: 'pip' } }, { name: 'Instalar dependências', run: 'python -m pip install -r requirements.txt' });
const tools = [lint ? 'ruff' : '', test ? 'pytest' : '', build ? 'build' : ''].filter(Boolean);
if (tools.length)
steps.push({ name: 'Ferramentas de CI', run: 'python -m pip install ' + tools.join(' ') });
if (lint)
steps.push({ name: 'Lint', run: 'python -m ruff check .' });
if (test)
steps.push({ name: 'Testes', run: 'python -m pytest' });
if (build)
steps.push({ name: 'Build', run: 'python -m build' });
}
if (stack === 'PHP') {
steps.push({ uses: 'shivammathur/setup-php@v2', with: { 'php-version': runtime, tools: 'composer:v2', coverage: 'none' } }, { name: 'Instalar dependências', run: 'composer install --no-interaction --prefer-dist' });
for (const [enabled, script] of [[lint, 'lint'], [test, 'test'], [build, 'build']])
if (enabled)
steps.push({ name: script, run: 'composer run ' + script });
}
const text = infraYaml({ name: 'CI', on: { push: { branches: [v.branch] }, pull_request: { branches: [v.branch] } }, permissions: { contents: 'read' }, concurrency: { group: '${{ github.workflow }}-${{ github.ref }}', 'cancel-in-progress': true }, jobs: { check: { 'runs-on': 'ubuntu-latest', 'timeout-minutes': 15, steps } } });
return { text, files: [{ name: 'ci.yml', content: text }], notes: ['Salve como .github/workflows/ci.yml somente após revisar lockfiles, scripts e dependências. Não há deploy ou segredo configurado.', 'Actions usam tags de versão, não SHAs imutáveis. Confira requisitos do runner e fixe as versões/SHAs segundo sua política.'] };
}
function infraText(value, limit = 100000) {
if (typeof value !== 'string' || value.length > limit)
throw new Error(`Use texto com até ${limit} caracteres.`);
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ufffe\uffff]/u.test(value) || /[\uD800-\uDFFF]/u.test(value))
throw new Error('Há caracteres de controle ou Unicode inválidos na entrada.');
return value;
}
function infraChoice(value, options) {
if (!options.includes(value))
throw new Error('Opção não suportada: ' + value);
return value;
}
function infraYaml(value) { return stringify(value, { indent: 2, lineWidth: 0, defaultStringType: 'QUOTE_DOUBLE' }); }
for (const value of Object.values(values)) infraText(value);
const output = await generateInfraActions(values);
if (output.text.length > 1000000) throw new Error("Resultado excede 1 milhão de caracteres.");
return output;
}
import json
import subprocess
def executar(values):
# Requer Node.js 22+ e os pacotes npm abaixo; a implementação completa está visível.
source = r'''
import { stringify } from "yaml";
async function executar(values) {
function generateInfraActions(v) {
const stack = infraChoice(v.stack, ['Node.js', 'Python', 'PHP']), versions = stack === 'Node.js' ? ['22', '24'] : stack === 'Python' ? ['3.12', '3.13'] : ['8.3', '8.4'], runtime = infraChoice(v.runtime, versions);
if (!/^[A-Za-z0-9][A-Za-z0-9/_-]{0,99}$/.test(v.branch) || v.branch.includes('//') || v.branch.endsWith('/'))
throw new Error('Branch inválida: use letras, números, /, _ e -, sem barras repetidas ou finais.');
const lint = infraChoice(v.lint, ['Sim', 'Não']) === 'Sim', test = infraChoice(v.test, ['Sim', 'Não']) === 'Sim', build = infraChoice(v.build, ['Sim', 'Não']) === 'Sim';
const steps = [{ uses: 'actions/checkout@v6', with: { 'persist-credentials': false } }];
if (stack === 'Node.js') {
steps.push({ uses: 'actions/setup-node@v6', with: { 'node-version': runtime, cache: 'npm' } }, { name: 'Instalar dependências', run: 'npm ci' });
if (lint)
steps.push({ name: 'Lint', run: 'npm run lint' });
if (test)
steps.push({ name: 'Testes', run: 'npm test' });
if (build)
steps.push({ name: 'Build', run: 'npm run build' });
}
if (stack === 'Python') {
steps.push({ uses: 'actions/setup-python@v6', with: { 'python-version': runtime, cache: 'pip' } }, { name: 'Instalar dependências', run: 'python -m pip install -r requirements.txt' });
const tools = [lint ? 'ruff' : '', test ? 'pytest' : '', build ? 'build' : ''].filter(Boolean);
if (tools.length)
steps.push({ name: 'Ferramentas de CI', run: 'python -m pip install ' + tools.join(' ') });
if (lint)
steps.push({ name: 'Lint', run: 'python -m ruff check .' });
if (test)
steps.push({ name: 'Testes', run: 'python -m pytest' });
if (build)
steps.push({ name: 'Build', run: 'python -m build' });
}
if (stack === 'PHP') {
steps.push({ uses: 'shivammathur/setup-php@v2', with: { 'php-version': runtime, tools: 'composer:v2', coverage: 'none' } }, { name: 'Instalar dependências', run: 'composer install --no-interaction --prefer-dist' });
for (const [enabled, script] of [[lint, 'lint'], [test, 'test'], [build, 'build']])
if (enabled)
steps.push({ name: script, run: 'composer run ' + script });
}
const text = infraYaml({ name: 'CI', on: { push: { branches: [v.branch] }, pull_request: { branches: [v.branch] } }, permissions: { contents: 'read' }, concurrency: { group: '${{ github.workflow }}-${{ github.ref }}', 'cancel-in-progress': true }, jobs: { check: { 'runs-on': 'ubuntu-latest', 'timeout-minutes': 15, steps } } });
return { text, files: [{ name: 'ci.yml', content: text }], notes: ['Salve como .github/workflows/ci.yml somente após revisar lockfiles, scripts e dependências. Não há deploy ou segredo configurado.', 'Actions usam tags de versão, não SHAs imutáveis. Confira requisitos do runner e fixe as versões/SHAs segundo sua política.'] };
}
function infraText(value, limit = 100000) {
if (typeof value !== 'string' || value.length > limit)
throw new Error(`Use texto com até ${limit} caracteres.`);
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ufffe\uffff]/u.test(value) || /[\uD800-\uDFFF]/u.test(value))
throw new Error('Há caracteres de controle ou Unicode inválidos na entrada.');
return value;
}
function infraChoice(value, options) {
if (!options.includes(value))
throw new Error('Opção não suportada: ' + value);
return value;
}
function infraYaml(value) { return stringify(value, { indent: 2, lineWidth: 0, defaultStringType: 'QUOTE_DOUBLE' }); }
for (const value of Object.values(values)) infraText(value);
const output = await generateInfraActions(values);
if (output.text.length > 1000000) throw new Error("Resultado excede 1 milhão de caracteres.");
return output;
}
let input=""; for await (const chunk of process.stdin) input+=chunk; try { process.stdout.write(JSON.stringify({ok:true,result:await executar(JSON.parse(input))})); } catch (error) { process.stdout.write(JSON.stringify({ok:false,error:error.message})); }
'''
process = subprocess.run(["node", "--input-type=module", "-e", source], input=json.dumps(values, ensure_ascii=True), capture_output=True, text=True, timeout=15, check=True)
response = json.loads(process.stdout)
if not response["ok"]:
raise ValueError(response["error"])
return response["result"]
<?php
function executar(array $values): array {
// Requer Node.js 22+ e os pacotes npm abaixo; a implementação completa está visível.
$source = <<<'JAVASCRIPT'
import { stringify } from "yaml";
async function executar(values) {
function generateInfraActions(v) {
const stack = infraChoice(v.stack, ['Node.js', 'Python', 'PHP']), versions = stack === 'Node.js' ? ['22', '24'] : stack === 'Python' ? ['3.12', '3.13'] : ['8.3', '8.4'], runtime = infraChoice(v.runtime, versions);
if (!/^[A-Za-z0-9][A-Za-z0-9/_-]{0,99}$/.test(v.branch) || v.branch.includes('//') || v.branch.endsWith('/'))
throw new Error('Branch inválida: use letras, números, /, _ e -, sem barras repetidas ou finais.');
const lint = infraChoice(v.lint, ['Sim', 'Não']) === 'Sim', test = infraChoice(v.test, ['Sim', 'Não']) === 'Sim', build = infraChoice(v.build, ['Sim', 'Não']) === 'Sim';
const steps = [{ uses: 'actions/checkout@v6', with: { 'persist-credentials': false } }];
if (stack === 'Node.js') {
steps.push({ uses: 'actions/setup-node@v6', with: { 'node-version': runtime, cache: 'npm' } }, { name: 'Instalar dependências', run: 'npm ci' });
if (lint)
steps.push({ name: 'Lint', run: 'npm run lint' });
if (test)
steps.push({ name: 'Testes', run: 'npm test' });
if (build)
steps.push({ name: 'Build', run: 'npm run build' });
}
if (stack === 'Python') {
steps.push({ uses: 'actions/setup-python@v6', with: { 'python-version': runtime, cache: 'pip' } }, { name: 'Instalar dependências', run: 'python -m pip install -r requirements.txt' });
const tools = [lint ? 'ruff' : '', test ? 'pytest' : '', build ? 'build' : ''].filter(Boolean);
if (tools.length)
steps.push({ name: 'Ferramentas de CI', run: 'python -m pip install ' + tools.join(' ') });
if (lint)
steps.push({ name: 'Lint', run: 'python -m ruff check .' });
if (test)
steps.push({ name: 'Testes', run: 'python -m pytest' });
if (build)
steps.push({ name: 'Build', run: 'python -m build' });
}
if (stack === 'PHP') {
steps.push({ uses: 'shivammathur/setup-php@v2', with: { 'php-version': runtime, tools: 'composer:v2', coverage: 'none' } }, { name: 'Instalar dependências', run: 'composer install --no-interaction --prefer-dist' });
for (const [enabled, script] of [[lint, 'lint'], [test, 'test'], [build, 'build']])
if (enabled)
steps.push({ name: script, run: 'composer run ' + script });
}
const text = infraYaml({ name: 'CI', on: { push: { branches: [v.branch] }, pull_request: { branches: [v.branch] } }, permissions: { contents: 'read' }, concurrency: { group: '${{ github.workflow }}-${{ github.ref }}', 'cancel-in-progress': true }, jobs: { check: { 'runs-on': 'ubuntu-latest', 'timeout-minutes': 15, steps } } });
return { text, files: [{ name: 'ci.yml', content: text }], notes: ['Salve como .github/workflows/ci.yml somente após revisar lockfiles, scripts e dependências. Não há deploy ou segredo configurado.', 'Actions usam tags de versão, não SHAs imutáveis. Confira requisitos do runner e fixe as versões/SHAs segundo sua política.'] };
}
function infraText(value, limit = 100000) {
if (typeof value !== 'string' || value.length > limit)
throw new Error(`Use texto com até ${limit} caracteres.`);
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ufffe\uffff]/u.test(value) || /[\uD800-\uDFFF]/u.test(value))
throw new Error('Há caracteres de controle ou Unicode inválidos na entrada.');
return value;
}
function infraChoice(value, options) {
if (!options.includes(value))
throw new Error('Opção não suportada: ' + value);
return value;
}
function infraYaml(value) { return stringify(value, { indent: 2, lineWidth: 0, defaultStringType: 'QUOTE_DOUBLE' }); }
for (const value of Object.values(values)) infraText(value);
const output = await generateInfraActions(values);
if (output.text.length > 1000000) throw new Error("Resultado excede 1 milhão de caracteres.");
return output;
}
let input=""; for await (const chunk of process.stdin) input+=chunk; try { process.stdout.write(JSON.stringify({ok:true,result:await executar(JSON.parse(input))})); } catch (error) { process.stdout.write(JSON.stringify({ok:false,error:error.message})); }
JAVASCRIPT;
$payload = json_encode($values, JSON_THROW_ON_ERROR);
$process = proc_open(["node", "--input-type=module", "-e", $source], [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
if (!is_resource($process)) throw new RuntimeException("Não foi possível iniciar Node.js.");
$offset = 0; while ($offset < strlen($payload)) { $n = fwrite($pipes[0], substr($payload, $offset)); if ($n === false || $n === 0) { proc_terminate($process); foreach ($pipes as $pipe) fclose($pipe); proc_close($process); throw new RuntimeException("Falha ao enviar a entrada."); } $offset += $n; }
fclose($pipes[0]); stream_set_timeout($pipes[1], 15); $output = stream_get_contents($pipes[1]); $timeout = stream_get_meta_data($pipes[1])["timed_out"]; fclose($pipes[1]); if ($timeout) proc_terminate($process); stream_get_contents($pipes[2]); fclose($pipes[2]); $status = proc_close($process);
if ($timeout || $status !== 0) throw new RuntimeException("Falha técnica ou timeout no Node.js; confira as dependências npm.");
$response = json_decode($output, true, 512, JSON_THROW_ON_ERROR); if (!$response["ok"]) throw new InvalidArgumentException($response["error"]);
return $response["result"];
}