Skip to content
Open
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
58 changes: 40 additions & 18 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,19 @@ export const deployPackage = async (
hide
);

// TODO: We should do something with the return value, for example
// check for error or show the output to the user
await api.upload(
name,
archive,
additionalJsons,
descriptor.runners
);

const env = await getEnv(rootPath, args['env'], args['envFile']);
try {
// TODO: We should do something with the return value, for example
// check for error or show the output to the user
await api.upload(
name,
archive,
additionalJsons,
descriptor.runners
);

info(`Deploying ${rootPath}...\n`);
const env = await getEnv(rootPath, args['env'], args['envFile']);

try {
info(`Deploying ${rootPath}...\n`);
const deploy = await api.deploy(
name,
env,
Expand All @@ -100,9 +99,21 @@ export const deployPackage = async (
);
}
} catch (err) {
apiError(err as ProtocolError);
}
};
const protocolErr = err as ProtocolError;
if (
protocolErr.response?.status === 400 &&
String(protocolErr.response?.data).includes(
'already'
)
) {
return error(
`Deployment "${name}" already exists.\nUse --force to redeploy or --delete to remove it.`
);
}
apiError(protocolErr);
}
};


const createJsonAndDeploy = async (saveConsent: string) => {
let languages: LanguageId[] = [];
Expand Down Expand Up @@ -232,6 +243,7 @@ export const deployFromRepository = async (
plan: Plans,
url: string
) => {
let name = '';
try {
const { branches } = await api.branchList(url);

Expand All @@ -252,7 +264,7 @@ export const deployFromRepository = async (
findRunners(await api.fileList(url, selectedBranch))
);

const name = (await api.add(url, selectedBranch, [])).id;
name = (await api.add(url, selectedBranch, [])).id;

const env = await getEnv(undefined, args['env'], args['envFile']);

Expand All @@ -272,6 +284,16 @@ export const deployFromRepository = async (
'Repository deployed, Use command $ metacall-deploy --inspect, to know more about deployment'
);
} catch (e) {
error(String(e), ErrorCode.DeployRepositoryFailed);
}
const protocolErr = e as ProtocolError;

if (
protocolErr.response?.status === 400 &&
String(protocolErr.response?.data).includes('already')
) {
return error(
`Deployment "${name}" already exists.\nUse --force to redeploy or --delete to remove it.`
);
}
apiError(protocolErr);
}
};