Skip to content

Conversation

@takaokouji
Copy link
Contributor

Summary

This PR implements a comprehensive GitHub Actions CI/CD pipeline for automated testing and deployment of the smalruby-infra Lambda functions.

Features Implemented

🚀 Multi-Job CI/CD Workflow

  1. lint-and-test Job

    • Ruby 3.3 setup with bundler cache optimization
    • Runs bundle exec rake standard for Ruby Standard Style linting
    • Runs bundle exec rake test for comprehensive RSpec testing (29 tests)
    • Uploads test results artifacts for debugging
  2. validate-sam-template Job

    • Sets up AWS SAM CLI
    • Validates SAM template syntax (sam validate)
    • Builds SAM application (sam build)
    • Uploads build artifacts for deployment
  3. deploy Job (main branch only)

    • Deploys to AWS using SAM CLI
    • Configured for ap-northeast-1 region
    • Stack name: smalruby-infra-prod
    • Requires AWS credentials from GitHub secrets
    • Uploads deployment logs for monitoring

🔧 Triggers

  • Pull Requests: Runs lint-and-test + validate-sam-template jobs
  • Push to main: Runs all jobs including deployment

🛡️ Security & Best Practices

  • Environment protection for production deployment
  • Conditional deployment only on main branch pushes
  • Artifacts retention (7-30 days based on importance)
  • Uses latest stable GitHub Actions (v4)

Required GitHub Secrets

To enable deployment, the following secrets need to be configured:

  • AWS_ACCESS_KEY_ID: AWS access key for deployment
  • AWS_SECRET_ACCESS_KEY: AWS secret access key for deployment

Test Plan

  • CI/CD workflow syntax validation
  • Local testing confirms all 29 tests pass
  • Linting passes with Ruby Standard Style
  • PR creation will trigger CI/CD workflow for validation

Breaking Changes

None. This is purely additive infrastructure.

Notes

  • The workflow uses Ruby 3.3 to match our local development environment
  • SAM build artifacts are shared between jobs for efficiency
  • Deployment only occurs on main branch to prevent accidental deployments

🤖 Generated with Claude Code

takaokouji and others added 4 commits September 20, 2025 17:02
- Add conditional lambda_handler definition using ENV["CI"] check
- Prevent global lambda_handler definitions during test execution
- Update Rakefile to set CI=true for all test tasks
- Fix mesh zone test to use module method consistently

Changes implemented:
- All lambda_function.rb files now conditionally define global lambda_handler
- Only define lambda_handler when ENV["CI"] != "true"
- Rakefile sets CI=true for both :test and :test:lambda tasks
- Fixed remaining test that called global lambda_handler directly

Test results:
- ✅ 29 examples, 0 failures (no warnings)
- ✅ All lambda_handler redefinition warnings eliminated
- ✅ Local SAM testing still works (CI env not set)
- ✅ RSpec testing works cleanly (CI env set to true)

This maintains backward compatibility for AWS Lambda deployment
while providing a clean testing environment without warnings.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive GitHub Actions workflow for automated testing and deployment:

CI/CD Pipeline Features:
- **Triggers**: Push to main branch and Pull Requests to main
- **Multi-job workflow**: lint-and-test → validate-sam-template → deploy

Job 1: lint-and-test
- Ruby 3.3 setup with bundler cache
- Run `bundle exec rake standard` for linting
- Run `bundle exec rake test` for comprehensive testing
- Upload test results artifacts

Job 2: validate-sam-template
- AWS SAM CLI setup
- Validate SAM template syntax
- Build SAM application
- Upload build artifacts

Job 3: deploy (main branch only)
- Deploy to AWS using SAM CLI
- Requires AWS credentials from GitHub secrets
- Stack name: smalruby-infra-prod
- Deploys to ap-northeast-1 region
- Upload deployment logs

Security & Best Practices:
- Environment protection for production deployment
- Artifacts retention (7-30 days)
- Conditional deployment only on main branch pushes
- Uses latest GitHub Actions (v4)

This enables automated quality assurance and deployment for the
smalruby-infra Lambda functions and API Gateway infrastructure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
SAM build requires Ruby and bundler to be available for Ruby Lambda functions.
This fixes the 'No such file or directory: bundle' error in GitHub Actions.

Changes:
- Add Ruby 3.3 setup to validate-sam-template job
- Add Ruby 3.3 setup to deploy job
- Enable bundler-cache for faster builds
- Ensure consistent Ruby environment across all CI/CD jobs

This resolves the RubyBundlerBuilder:RubyBundle error during sam build.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment out the deploy job in GitHub Actions workflow until manual
deployment testing is completed. This ensures we can safely test
deployment manually before enabling automated deployment.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@takaokouji takaokouji merged commit ea7b03f into main Sep 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants