Skip to content

have pipelines fail on regeneration failure #1663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 9, 2023
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
5 changes: 2 additions & 3 deletions packages/autorest.python/autorest/postprocess/venvtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create(


def python_run( # pylint: disable=inconsistent-return-statements
venv_context, module, command, directory=_ROOT_DIR, *, error_ok=False
venv_context, module, command, directory=_ROOT_DIR
) -> Optional[str]:
try:
cmd_line = [
Expand All @@ -70,6 +70,5 @@ def python_run( # pylint: disable=inconsistent-return-statements
return f.read()
except subprocess.CalledProcessError as err:
print(err)
if not error_ok:
sys.exit(1)
sys.exit(1)
return None
5 changes: 2 additions & 3 deletions packages/autorest.python/venvtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_venv_with_package(packages):
subprocess.check_call(pip_call + packages)
yield myenv

def python_run(venv_context, module, command=None, *, additional_dir=".", error_ok=False):
def python_run(venv_context, module, command=None, *, additional_dir="."):
try:
cmd_line= [
venv_context.env_exe,
Expand All @@ -70,5 +70,4 @@ def python_run(venv_context, module, command=None, *, additional_dir=".", error_
)
except subprocess.CalledProcessError as err:
print(err)
if not error_ok:
sys.exit(1)
sys.exit(1)
12 changes: 4 additions & 8 deletions packages/cadl-python/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,22 @@ import {
getFormat,
getMinItems,
getMaxItems,
getNamespaceFullName,
EmitContext,
listServices,
Union,
isNullType,
SyntaxKind,
emitFile,
Type,
getKnownValues,
} from "@cadl-lang/compiler";
import {
getAuthentication,
getContentTypes,
getHeaderFieldName,
getHttpOperation,
getPathParamName,
getQueryParamName,
getServers,
HttpAuth,
HttpOperationParameter,
HttpOperationParameters,
HttpOperationRequestBody,
HttpOperationResponse,
HttpOperationResponseContent,
Expand All @@ -72,10 +67,11 @@ import {
DpgContext,
} from "@azure-tools/cadl-dpg";
import { getResourceOperation } from "@cadl-lang/rest";
import { execAsync, resolveModuleRoot, saveCodeModelAsYaml } from "./external-process.js";
import { resolveModuleRoot, saveCodeModelAsYaml } from "./external-process.js";
import { dirname } from "path";
import { fileURLToPath } from "url";
import { dump } from "js-yaml";
import { execFileSync } from "child_process";

interface HttpServerParameter {
type: "endpointPath";
Expand Down Expand Up @@ -152,7 +148,7 @@ export async function $onEmit(context: EmitContext<EmitterOptions>) {
commandArgs.push("--debug");
}
if (!program.compilerOptions.noEmit && !program.hasError()) {
await execAsync(process.execPath, commandArgs);
execFileSync(process.execPath, commandArgs);
}
}

Expand Down Expand Up @@ -1256,7 +1252,7 @@ function getNamespaces(context: DpgContext): Set<string> {

function emitCodeModel(context: EmitContext<EmitterOptions>) {
const dpgContext = createDpgContext(context);
const clientNamespaceString = getClientNamespaceString(dpgContext);
const clientNamespaceString = getClientNamespaceString(dpgContext)?.toLowerCase();
// Get types
const codeModel: Record<string, any> = {
namespace: clientNamespaceString,
Expand Down
4 changes: 2 additions & 2 deletions packages/cadl-python/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def _run_cadl(cmds):

def _run_single_cadl(cmd):
result = run(cmd, warn=True)
if result.ok or result.return_code is None:
if result.ok:
print(Fore.GREEN + f'Call "{cmd}" done with success')
return True
print(Fore.RED + f'Call "{cmd}" failed with {result.return_code}\n{result.stdout}\n{result.stderr}')
output_folder = re.findall(r"--output-path=([^\s]+)", cmd)[0]
output_folder = re.findall(r"--output-dir=([^\s]+)", cmd)[0]
shutil.rmtree(output_folder, ignore_errors=True)
return False