Skip to content

Commit

Permalink
chore: improve ssh flow
Browse files Browse the repository at this point in the history
  • Loading branch information
phani-srikar committed Jul 29, 2023
1 parent 5b41eb8 commit 22ef4c0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ test.out.log
package-lock.json
.idea
scripts/.env
.codebuild/debug_workflow.yml
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"cloud-e2e-beta": "source scripts/cloud-utils.sh && cloudE2EBeta",
"split-e2e-tests": "yarn ts-node ./scripts/split-e2e-tests.ts && git add .codebuild/e2e_workflow.yml",
"view-test-artifacts": "yarn ts-node ./scripts/view-test-artifacts.ts",
"generate-debug-e2e-spec": "./scripts/generate-debug-spec-for-failed-e2e-tests.sh",
"cloud-e2e-debug": "source scripts/cloud-utils.sh && cloudE2EDebug"
},
"bugs": {
Expand Down
24 changes: 23 additions & 1 deletion scripts/cloud-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,41 @@ function triggerProjectBatchWithDebugSession {
echo AWS Account: $account_number
echo Project: $project_name
echo Target Branch: $target_branch
debug_spec=$(cat .codebuild/debug_workflow.yml)
RESULT=$(aws codebuild start-build-batch --region=$REGION --profile="${profile_name}" --project-name $project_name --source-version=$target_branch \
--debug-session-enabled \
--buildspec-override "codebuild_specs/debug_workflow.yml" \
--buildspec-override "$debug_spec" \
--environment-variables-override name=BRANCH_NAME,value=$target_branch,type=PLAINTEXT \
--query 'buildBatch.id' --output text)
echo "https://$REGION.console.aws.amazon.com/codesuite/codebuild/$account_number/projects/$project_name/batch/$RESULT?region=$REGION"
}

function cloudE2EDebug {
echo Generating the debug E2E buildspec
if [ $# -eq 0 ]; then
echo "Please provide the batch build id of codebuild"
exit 1
fi
generatedDebugSpecForFailedTests $1
echo Running Prod E2E Test Suite
E2E_ROLE_NAME=CodebuildDeveloper
E2E_PROFILE_NAME=AmplifyAPIE2EProd
E2E_PROJECT_NAME=amplify-codegen-e2e-workflow
TARGET_BRANCH=$CURR_BRANCH
triggerProjectBatchWithDebugSession $E2E_ACCOUNT_PROD $E2E_ROLE_NAME $E2E_PROFILE_NAME $E2E_PROJECT_NAME $TARGET_BRANCH
}

function generatedDebugSpecForFailedTests {
# Get temporary access for the account
E2E_ROLE_NAME=CodebuildDeveloper
E2E_PROFILE_NAME=AmplifyAPIE2EProd
authenticate $E2E_ACCOUNT_PROD $E2E_ROLE_NAME "$E2E_PROFILE_NAME"
local batch_build_id=$1
echo "Getting failed test suites"
failed_tests=$(aws codebuild batch-get-build-batches --profile="$E2E_PROFILE_NAME" --ids "$batch_build_id" --region us-east-1 --query 'buildBatches[0].buildGroups' | jq -c '.[] | select(.currentBuildSummary.buildStatus == "FAILED").identifier')
if [ -z "$failed_tests" ]; then
echo "No failed tests found in batch $1"
exit 0
fi
echo $failed_tests | xargs yarn ts-node ./scripts/split-e2e-tests.ts --debug
}
30 changes: 0 additions & 30 deletions scripts/generate-debug-spec-for-failed-e2e-tests.sh

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/split-e2e-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const REPO_ROOT = join(__dirname, '..');
const TEST_TIMINGS_PATH = join(REPO_ROOT, 'scripts', 'test-timings.data.json');
const CODEBUILD_CONFIG_BASE_PATH = join(REPO_ROOT, '.codebuild', 'e2e_workflow_base.yml');
const CODEBUILD_GENERATE_CONFIG_PATH = join(REPO_ROOT, '.codebuild', 'e2e_workflow.yml');
const CODEBUILD_DEBUG_CONFIG_PATH = join (REPO_ROOT, 'codebuild_specs', 'debug_workflow.yml');
const CODEBUILD_DEBUG_CONFIG_PATH = join (REPO_ROOT, '.codebuild', 'debug_workflow.yml');
const RUN_SOLO = [];
const EXCLUDE_TESTS = [
'src/__tests__/build-app-swift.test.ts',
Expand Down Expand Up @@ -209,7 +209,7 @@ function main(): void {
env: {
'compute-type': 'BUILD_GENERAL1_MEDIUM'
},
'depend-on': allBuilds.length > 0 ? [allBuilds[0].identifier] : 'publish_to_local_registry',
'depend-on': allBuilds.length > 0 ? [allBuilds[0].identifier] : ['publish_to_local_registry'],
}
console.log(`Total number of splitted jobs: ${allBuilds.length}`)
let currentBatch = [...baseBuildGraph, ...allBuilds, cleanupResources];
Expand Down
1 change: 1 addition & 0 deletions shared-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function _runE2ETestsLinux {
_installCLIFromLocalRegistry
_loadTestAccountCredentials
_setShell
codebuild-breakpoint
retry runE2eTest
}

Expand Down

0 comments on commit 22ef4c0

Please sign in to comment.