Skip to content

Commit a07fbcf

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/error-analyzer-9
2 parents e214f14 + bf1ba2b commit a07fbcf

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

.gitlab-ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,43 @@ integration_tests:
136136

137137
# Run integration test deployment
138138
- python3 scripts/integration_test_deployment.py
139+
140+
after_script:
141+
# Capture CodeBuild logs using the tracked execution ID
142+
- |
143+
echo "=== IDP Pipeline Results ===" > pipeline_summary.txt
144+
echo "Branch: $CI_COMMIT_REF_NAME" >> pipeline_summary.txt
145+
echo "Commit: $CI_COMMIT_SHA" >> pipeline_summary.txt
146+
echo "Status: $CI_JOB_STATUS" >> pipeline_summary.txt
147+
echo "" >> pipeline_summary.txt
148+
149+
# Get CodeBuild logs using the exact execution ID from Python script
150+
if [ -f "pipeline_execution_id.txt" ]; then
151+
EXECUTION_ID=$(cat pipeline_execution_id.txt)
152+
echo "Pipeline Execution: $EXECUTION_ID" >> pipeline_summary.txt
153+
echo "" >> pipeline_summary.txt
154+
155+
# Get CodeBuild ID from the pipeline execution
156+
BUILD_ID=$(aws codepipeline list-action-executions --pipeline-name ${IDP_PIPELINE_NAME:-idp-sdlc-deploy-pipeline} --filter pipelineExecutionId=$EXECUTION_ID --query 'actionExecutionDetails[?actionName==`BuildAction`].output.executionResult.externalExecutionId' --output text 2>/dev/null || echo "")
157+
158+
if [ "$BUILD_ID" != "" ] && [ "$BUILD_ID" != "None" ]; then
159+
echo "CodeBuild ID: $BUILD_ID" >> pipeline_summary.txt
160+
# Extract just the build ID part (after the colon)
161+
LOG_STREAM_NAME="${BUILD_ID#*:}"
162+
echo "Log Stream: $LOG_STREAM_NAME" >> pipeline_summary.txt
163+
echo "" >> pipeline_summary.txt
164+
echo "=== CODEBUILD LOGS ===" >> pipeline_summary.txt
165+
aws logs get-log-events --log-group-name "/aws/codebuild/app-sdlc" --log-stream-name "$LOG_STREAM_NAME" --limit 100 --query 'events[].message' --output text 2>/dev/null >> pipeline_summary.txt || echo "Could not retrieve CodeBuild logs" >> pipeline_summary.txt
166+
else
167+
echo "Could not find CodeBuild execution" >> pipeline_summary.txt
168+
fi
169+
else
170+
echo "No pipeline execution ID found" >> pipeline_summary.txt
171+
fi
172+
173+
artifacts:
174+
when: always
175+
paths:
176+
- pipeline_summary.txt
177+
- pipeline_execution_id.txt
178+
expire_in: 1 week

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test:
1515
cd idp_cli && python -m pytest -v
1616

1717
# Run both linting and formatting in one command
18-
lint: ruff-lint format check-arn-partitions
18+
lint: ruff-lint format check-arn-partitions ui-lint
1919

2020
# Run linting checks and fix issues automatically
2121
ruff-lint:
@@ -38,7 +38,19 @@ lint-cicd:
3838
echo -e "$(RED)ERROR: Code formatting check failed!$(NC)"; \
3939
echo -e "$(YELLOW)Please run 'make format' locally to fix these issues.$(NC)"; \
4040
exit 1; \
41+
fi; \
42+
echo "All checks passed!"
43+
@echo "Frontend checks"
44+
@if ! make ui-lint; then \
45+
echo -e "$(RED)ERROR: UI lint failed$(NC)"; \
46+
exit 1; \
47+
fi
48+
49+
@if ! make ui-build; then \
50+
echo -e "$(RED)ERROR: UI build failed$(NC)"; \
51+
exit 1; \
4152
fi
53+
4254
@echo -e "$(GREEN)All code quality checks passed!$(NC)"
4355

4456
# Check CloudFormation templates for hardcoded AWS partition ARNs and service principals
@@ -90,6 +102,14 @@ typecheck-pr:
90102
python3 scripts/typecheck_pr_changes.py $(TARGET_BRANCH)
91103

92104

105+
ui-lint:
106+
@echo "Checking UI lint"
107+
cd src/ui && npm ci --prefer-offline --no-audit && npm run lint
108+
109+
ui-build:
110+
@echo "Checking UI build"
111+
cd src/ui && npm ci --prefer-offline --no-audit && npm run build
112+
93113
commit: lint test
94114
$(info Generating commit message...)
95115
export COMMIT_MESSAGE="$(shell q chat --no-interactive --trust-all-tools "Understand pending local git change and changes to be committed, then infer a commit message. Return this commit message only" | tail -n 1 | sed 's/\x1b\[[0-9;]*m//g')" && \
File renamed without changes.

scripts/codebuild_deployment.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def get_env_var(name, default=None):
6060

6161

6262
def generate_stack_prefix():
63-
"""Generate unique stack prefix with timestamp"""
64-
timestamp = datetime.now().strftime("%m%d-%H%M") # Shorter format: MMDD-HHMM
63+
"""Generate unique stack prefix with timestamp including seconds"""
64+
timestamp = datetime.now().strftime("%m%d-%H%M%S") # Format: MMDD-HHMMSS
6565
return f"idp-{timestamp}"
6666

6767

@@ -222,7 +222,39 @@ def cleanup_stack(stack_name, pattern_name):
222222
"""Clean up a deployed stack"""
223223
print(f"[{pattern_name}] Cleaning up: {stack_name}")
224224
try:
225-
run_command(f"idp-cli delete --stack-name {stack_name} --force", check=False)
225+
# Check stack status first
226+
result = run_command(f"aws cloudformation describe-stacks --stack-name {stack_name} --query 'Stacks[0].StackStatus' --output text", check=False)
227+
stack_status = result.stdout.strip() if result.returncode == 0 else "NOT_FOUND"
228+
229+
print(f"[{pattern_name}] Stack status: {stack_status}")
230+
231+
# Delete the stack and wait for completion
232+
print(f"[{pattern_name}] Attempting stack deletion...")
233+
run_command(f"idp-cli delete --stack-name {stack_name} --force --empty-buckets --wait", check=False)
234+
235+
# Always clean up orphaned resources after deletion attempt
236+
print(f"[{pattern_name}] Cleaning up orphaned resources...")
237+
238+
# Set AWS retry configuration to handle throttling
239+
os.environ['AWS_MAX_ATTEMPTS'] = '10'
240+
os.environ['AWS_RETRY_MODE'] = 'adaptive'
241+
242+
# ECR repositories
243+
stack_name_lower = stack_name.lower()
244+
run_command(f"aws ecr describe-repositories --query 'repositories[?contains(repositoryName, `{stack_name_lower}`)].repositoryName' --output text | xargs -r -n1 aws ecr delete-repository --repository-name --force", check=False)
245+
246+
# S3 buckets (empty and delete orphaned buckets)
247+
run_command(f"aws s3api list-buckets --query 'Buckets[?contains(Name, `{stack_name}`)].Name' --output text | xargs -r -n1 -I {{}} sh -c 'aws s3 rm s3://{{}} --recursive && aws s3api delete-bucket --bucket {{}}'", check=False)
248+
249+
# CloudWatch log groups (single comprehensive search)
250+
run_command(f"aws logs describe-log-groups --query 'logGroups[?contains(logGroupName, `{stack_name}`)].logGroupName' --output text | xargs -r -n1 aws logs delete-log-group --log-group-name", check=False)
251+
252+
# AppSync logs (requires separate handling due to random API IDs)
253+
run_command(f"aws appsync list-graphql-apis --query 'graphqlApis[?contains(name, `{stack_name}`)].apiId' --output text | xargs -r -I {{}} aws logs delete-log-group --log-group-name '/aws/appsync/apis/{{}}'", check=False)
254+
255+
# Clean up CloudWatch Logs Resource Policy (ignore errors if policy doesn't exist)
256+
run_command(f"aws logs describe-resource-policies --query 'resourcePolicies[0].policyName' --output text | xargs -r aws logs delete-resource-policy --policy-name || true", check=False)
257+
226258
print(f"[{pattern_name}] ✅ Cleanup completed")
227259
except Exception as e:
228260
print(f"[{pattern_name}] ⚠️ Cleanup failed: {e}")
@@ -232,7 +264,7 @@ def main():
232264
"""Main execution function"""
233265
print("Starting CodeBuild deployment process...")
234266

235-
admin_email = get_env_var("IDP_ADMIN_EMAIL", "strahanr@amazon.com")
267+
admin_email = get_env_var("IDP_ADMIN_EMAIL", "tanimath@amazon.com")
236268
stack_prefix = generate_stack_prefix()
237269

238270
print(f"Stack Prefix: {stack_prefix}")

scripts/integration_test_deployment.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ def monitor_pipeline(pipeline_name, version_id, max_wait=7200):
173173

174174
if not execution_id:
175175
return False
176+
177+
# Write execution ID to file for GitLab CI to use
178+
with open("pipeline_execution_id.txt", "w") as f:
179+
f.write(execution_id)
180+
print(f"Pipeline execution ID written to file: {execution_id}")
176181

177182
# Then monitor that specific execution
178183
return monitor_pipeline_execution(pipeline_name, execution_id, max_wait)

src/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"build": "npm run lint && vite build",
6464
"preview": "vite preview",
6565
"test": "vitest",
66-
"lint": "npx eslint \"src/**/*.{js,jsx}\""
66+
"lint": "eslint \"src/**/*.{js,jsx}\""
6767
},
6868
"eslintConfig": {
6969
"extends": [

0 commit comments

Comments
 (0)