Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
fix: handle pr branch not exists (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
arantespp authored May 21, 2022
1 parent 59d24c6 commit 39e8517
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
26 changes: 11 additions & 15 deletions packages/cli/src/deploy/cicd/cicd.template.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import { pascalCase } from 'change-case';
import yaml from 'js-yaml';

import {
CloudFormationTemplate,
getIamPath,
getProjectName,
getEnvironment,
} from '../../utils';

import {
BASE_STACK_BUCKET_NAME_EXPORTED_NAME,
BASE_STACK_VPC_DEFAULT_SECURITY_GROUP_EXPORTED_NAME,
BASE_STACK_VPC_PUBLIC_SUBNET_0_EXPORTED_NAME,
BASE_STACK_VPC_PUBLIC_SUBNET_1_EXPORTED_NAME,
BASE_STACK_VPC_PUBLIC_SUBNET_2_EXPORTED_NAME,
} from '../baseStack/config';

import { getCicdConfig, CicdCommandOptions } from './command.options';

import type { Pipeline } from './pipelines';
import { CicdCommandOptions, getCicdConfig } from './command.options';
import {
CloudFormationTemplate,
getEnvironment,
getIamPath,
getProjectName,
} from '../../utils';
import {
ECS_TASK_DEFAULT_CPU,
ECS_TASK_DEFAULT_MEMORY,
PIPELINE_ECS_TASK_EXECUTION_MANUAL_APPROVAL_ACTION_NAME,
PIPELINE_ECS_TASK_EXECUTION_STAGE_NAME,
} from './config';
import { pascalCase } from 'change-case';
import yaml from 'js-yaml';
import type { Pipeline } from './pipelines';

import { getTriggerPipelinesObjectKey } from './getTriggerPipelineObjectKey';

Expand Down Expand Up @@ -338,7 +334,7 @@ export const getCicdTemplate = ({
],
},
null,
2,
2
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/deploy/cicd/ecsTaskReportCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandModule, InferredOptionTypes } from 'yargs';
import AWS from 'aws-sdk';
import log from 'npmlog';
import { CommandModule, InferredOptionTypes } from 'yargs';

import type { Event, Status } from './lambdas/ecsTaskReport.handler';

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/deploy/cicd/lambdas/executeTasks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ECS } from 'aws-sdk';

import { getProcessEnvVariable } from './getProcessEnvVariable';

import type { Status } from './ecsTaskReport.handler';

const ecs = new ECS({ apiVersion: '2014-11-13' });
const ecs = new ECS({ apiVersion: '2014-11-13', maxRetries: 3 });

const compileCommands = (commands: string[]) => {
return commands.map((c) => c.replace(/;$/, '')).join(' && ');
Expand Down
18 changes: 12 additions & 6 deletions packages/cli/src/deploy/cicd/pipelines.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as pipelinesModule from './pipelines';

test('pipelines', () => {
expect(pipelinesModule.pipelines).toMatchObject(
expect.arrayContaining(['pr', 'main', 'tag']),
expect.arrayContaining(['pr', 'main', 'tag'])
);
});

Expand All @@ -11,34 +11,40 @@ test('set +x', () => {

const tag = 'some-tag';

expect(pipelinesModule.getPrCommands({ branch })).toMatchObject(
expect.arrayContaining([
`git checkout ${branch} || echo 'branch not found, probably deleted'; exit 0`,
])
);

expect(pipelinesModule.getPrCommands({ branch })).toMatchObject(
expect.arrayContaining([
'set -e',
`sh -e ${pipelinesModule.getCommandFileDir('pr')}`,
]),
])
);

expect(pipelinesModule.getMainCommands()).toMatchObject(
expect.arrayContaining([
'set -e',
`sh -e ${pipelinesModule.getCommandFileDir('main')}`,
]),
])
);

expect(pipelinesModule.getTagCommands({ tag })).toMatchObject(
expect.arrayContaining([
'set -e',
`sh -e ${pipelinesModule.getCommandFileDir('tag')}`,
]),
])
);

expect(pipelinesModule.getClosedPrCommands({ branch })).not.toMatchObject(
expect.arrayContaining(['set -e']),
expect.arrayContaining(['set -e'])
);

expect(pipelinesModule.getClosedPrCommands({ branch })).toMatchObject(
expect.arrayContaining([
`[ -f "./cicd/commands/closed-pr" ] && sh ./cicd/commands/closed-pr || echo 'closed-pr command not found'; exit 0`,
]),
])
);
});
4 changes: 2 additions & 2 deletions packages/cli/src/deploy/cicd/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getPrCommands = ({ branch }: { branch: string }) => [
* Update to the most recent main branch to Lerna performs the diff properly.
*/
'git pull origin main',
`git checkout ${branch}`,
`git checkout ${branch} || echo 'branch not found, probably deleted'; exit 0`,
`git pull origin ${branch}`,
'git rev-parse HEAD',
'git status',
Expand All @@ -36,7 +36,7 @@ export const getClosedPrCommands = ({ branch }: { branch: string }) => [
* Exit without error if `closed-pr` does not exist.
*/
`[ -f "${getCommandFileDir('closed-pr')}" ] && sh ${getCommandFileDir(
'closed-pr',
'closed-pr'
)} || echo 'closed-pr command not found'; exit 0`,
];

Expand Down

0 comments on commit 39e8517

Please sign in to comment.