diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..6ca9b7b --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,103 @@ +name: CI/CD Pipeline + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + + - name: Install dependencies + run: bundle install + + - name: Run linter (Standard Ruby) + run: bundle exec rake standard + + - name: Run tests + run: bundle exec rake test + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: | + coverage/ + tmp/ + retention-days: 7 + + validate-sam-template: + runs-on: ubuntu-latest + needs: lint-and-test + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + + - name: Set up AWS SAM CLI + uses: aws-actions/setup-sam@v2 + + - name: Validate SAM template + run: sam validate --template template.yaml + + - name: Build SAM application + run: sam build --template template.yaml + + - name: Upload SAM build artifacts + uses: actions/upload-artifact@v4 + with: + name: sam-build-artifacts + path: .aws-sam/ + retention-days: 7 + + # Deploy job is temporarily disabled for initial testing + # Will be enabled after manual deployment verification + # deploy: + # runs-on: ubuntu-latest + # needs: [lint-and-test, validate-sam-template] + # if: github.ref == 'refs/heads/main' && github.event_name == 'push' + # environment: production + # steps: + # - name: Checkout code + # uses: actions/checkout@v4 + # - name: Set up Ruby + # uses: ruby/setup-ruby@v1 + # with: + # ruby-version: '3.3' + # bundler-cache: true + # - name: Set up AWS SAM CLI + # uses: aws-actions/setup-sam@v2 + # - name: Configure AWS credentials + # uses: aws-actions/configure-aws-credentials@v4 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ap-northeast-1 + # - name: Deploy to AWS + # run: | + # sam deploy \ + # --template-file .aws-sam/build/template.yaml \ + # --stack-name smalruby-infra-prod \ + # --parameter-overrides Stage=prod \ + # --capabilities CAPABILITY_IAM \ + # --no-confirm-changeset \ + # --no-fail-on-empty-changeset \ No newline at end of file diff --git a/Rakefile b/Rakefile index 71a579d..1d3463f 100644 --- a/Rakefile +++ b/Rakefile @@ -15,11 +15,15 @@ end desc "Run all tests" RSpec::Core::RakeTask.new(:test) do |t| t.pattern = "spec/**/*_spec.rb" + # Set CI environment variable to prevent lambda_handler redefinition warnings + ENV["CI"] = "true" end desc "Run Lambda function tests only" RSpec::Core::RakeTask.new("test:lambda") do |t| t.pattern = "spec/lambda/*_spec.rb" + # Set CI environment variable to prevent lambda_handler redefinition warnings + ENV["CI"] = "true" end desc "Run lint and tests" diff --git a/lambda/cors-for-smalruby/lambda_function.rb b/lambda/cors-for-smalruby/lambda_function.rb index 68f7293..56c711d 100644 --- a/lambda/cors-for-smalruby/lambda_function.rb +++ b/lambda/cors-for-smalruby/lambda_function.rb @@ -24,6 +24,8 @@ def self.lambda_handler(event:, context:) end # AWS Lambda entry point -def lambda_handler(event:, context:) - CorsForSmalruby.lambda_handler(event: event, context: context) +unless ENV["CI"] == "true" + def lambda_handler(event:, context:) + CorsForSmalruby.lambda_handler(event: event, context: context) + end end diff --git a/lambda/smalruby-cors-proxy/lambda_function.rb b/lambda/smalruby-cors-proxy/lambda_function.rb index e2f3569..9d1480f 100644 --- a/lambda/smalruby-cors-proxy/lambda_function.rb +++ b/lambda/smalruby-cors-proxy/lambda_function.rb @@ -199,6 +199,8 @@ def self.is_binary_content?(content_type) end # AWS Lambda entry point -def lambda_handler(event:, context:) - SmalrubyCorsProxy.lambda_handler(event: event, context: context) +unless ENV["CI"] == "true" + def lambda_handler(event:, context:) + SmalrubyCorsProxy.lambda_handler(event: event, context: context) + end end diff --git a/lambda/smalruby-mesh-zone-get/lambda_function.rb b/lambda/smalruby-mesh-zone-get/lambda_function.rb index 29e2468..860591c 100644 --- a/lambda/smalruby-mesh-zone-get/lambda_function.rb +++ b/lambda/smalruby-mesh-zone-get/lambda_function.rb @@ -20,6 +20,8 @@ def self.lambda_handler(event:, context:) end # AWS Lambda entry point -def lambda_handler(event:, context:) - SmalrubyMeshZoneGet.lambda_handler(event: event, context: context) +unless ENV["CI"] == "true" + def lambda_handler(event:, context:) + SmalrubyMeshZoneGet.lambda_handler(event: event, context: context) + end end diff --git a/lambda/smalruby-scratch-api-proxy-get-project-info/lambda_function.rb b/lambda/smalruby-scratch-api-proxy-get-project-info/lambda_function.rb index e99bc4a..2094b27 100644 --- a/lambda/smalruby-scratch-api-proxy-get-project-info/lambda_function.rb +++ b/lambda/smalruby-scratch-api-proxy-get-project-info/lambda_function.rb @@ -30,6 +30,8 @@ def self.lambda_handler(event:, context:) end # AWS Lambda entry point -def lambda_handler(event:, context:) - SmalrubyScratchApiProxyGetProjectInfo.lambda_handler(event: event, context: context) +unless ENV["CI"] == "true" + def lambda_handler(event:, context:) + SmalrubyScratchApiProxyGetProjectInfo.lambda_handler(event: event, context: context) + end end diff --git a/lambda/smalruby-scratch-api-proxy-translate/lambda_function.rb b/lambda/smalruby-scratch-api-proxy-translate/lambda_function.rb index dece040..71413eb 100644 --- a/lambda/smalruby-scratch-api-proxy-translate/lambda_function.rb +++ b/lambda/smalruby-scratch-api-proxy-translate/lambda_function.rb @@ -58,6 +58,8 @@ def self.lambda_handler(event:, context:) end # AWS Lambda entry point -def lambda_handler(event:, context:) - SmalrubyScratchApiProxyTranslate.lambda_handler(event: event, context: context) +unless ENV["CI"] == "true" + def lambda_handler(event:, context:) + SmalrubyScratchApiProxyTranslate.lambda_handler(event: event, context: context) + end end diff --git a/spec/lambda/smalruby_mesh_zone_get_spec.rb b/spec/lambda/smalruby_mesh_zone_get_spec.rb index 5b2dbe0..b0f4e93 100644 --- a/spec/lambda/smalruby_mesh_zone_get_spec.rb +++ b/spec/lambda/smalruby_mesh_zone_get_spec.rb @@ -35,8 +35,8 @@ end it "generates consistent domain for same IP" do - result1 = lambda_handler(event: event, context: context) - result2 = lambda_handler(event: event, context: context) + result1 = SmalrubyMeshZoneGet.lambda_handler(event: event, context: context) + result2 = SmalrubyMeshZoneGet.lambda_handler(event: event, context: context) body1 = JSON.parse(result1[:body]) body2 = JSON.parse(result2[:body])