Skip to content

Commit ea7b03f

Browse files
authored
Merge pull request #1 from smalruby/feature/github-actions-ci-cd
feat: implement GitHub Actions CI/CD pipeline
2 parents a44ad77 + 24791c9 commit ea7b03f

8 files changed

Lines changed: 129 additions & 12 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
lint-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Ruby
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: '3.3'
21+
bundler-cache: true
22+
23+
- name: Install dependencies
24+
run: bundle install
25+
26+
- name: Run linter (Standard Ruby)
27+
run: bundle exec rake standard
28+
29+
- name: Run tests
30+
run: bundle exec rake test
31+
32+
- name: Upload test results
33+
uses: actions/upload-artifact@v4
34+
if: always()
35+
with:
36+
name: test-results
37+
path: |
38+
coverage/
39+
tmp/
40+
retention-days: 7
41+
42+
validate-sam-template:
43+
runs-on: ubuntu-latest
44+
needs: lint-and-test
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Ruby
51+
uses: ruby/setup-ruby@v1
52+
with:
53+
ruby-version: '3.3'
54+
bundler-cache: true
55+
56+
- name: Set up AWS SAM CLI
57+
uses: aws-actions/setup-sam@v2
58+
59+
- name: Validate SAM template
60+
run: sam validate --template template.yaml
61+
62+
- name: Build SAM application
63+
run: sam build --template template.yaml
64+
65+
- name: Upload SAM build artifacts
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: sam-build-artifacts
69+
path: .aws-sam/
70+
retention-days: 7
71+
72+
# Deploy job is temporarily disabled for initial testing
73+
# Will be enabled after manual deployment verification
74+
# deploy:
75+
# runs-on: ubuntu-latest
76+
# needs: [lint-and-test, validate-sam-template]
77+
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
78+
# environment: production
79+
# steps:
80+
# - name: Checkout code
81+
# uses: actions/checkout@v4
82+
# - name: Set up Ruby
83+
# uses: ruby/setup-ruby@v1
84+
# with:
85+
# ruby-version: '3.3'
86+
# bundler-cache: true
87+
# - name: Set up AWS SAM CLI
88+
# uses: aws-actions/setup-sam@v2
89+
# - name: Configure AWS credentials
90+
# uses: aws-actions/configure-aws-credentials@v4
91+
# with:
92+
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
93+
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
94+
# aws-region: ap-northeast-1
95+
# - name: Deploy to AWS
96+
# run: |
97+
# sam deploy \
98+
# --template-file .aws-sam/build/template.yaml \
99+
# --stack-name smalruby-infra-prod \
100+
# --parameter-overrides Stage=prod \
101+
# --capabilities CAPABILITY_IAM \
102+
# --no-confirm-changeset \
103+
# --no-fail-on-empty-changeset

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ end
1515
desc "Run all tests"
1616
RSpec::Core::RakeTask.new(:test) do |t|
1717
t.pattern = "spec/**/*_spec.rb"
18+
# Set CI environment variable to prevent lambda_handler redefinition warnings
19+
ENV["CI"] = "true"
1820
end
1921

2022
desc "Run Lambda function tests only"
2123
RSpec::Core::RakeTask.new("test:lambda") do |t|
2224
t.pattern = "spec/lambda/*_spec.rb"
25+
# Set CI environment variable to prevent lambda_handler redefinition warnings
26+
ENV["CI"] = "true"
2327
end
2428

2529
desc "Run lint and tests"

lambda/cors-for-smalruby/lambda_function.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def self.lambda_handler(event:, context:)
2424
end
2525

2626
# AWS Lambda entry point
27-
def lambda_handler(event:, context:)
28-
CorsForSmalruby.lambda_handler(event: event, context: context)
27+
unless ENV["CI"] == "true"
28+
def lambda_handler(event:, context:)
29+
CorsForSmalruby.lambda_handler(event: event, context: context)
30+
end
2931
end

lambda/smalruby-cors-proxy/lambda_function.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ def self.is_binary_content?(content_type)
199199
end
200200

201201
# AWS Lambda entry point
202-
def lambda_handler(event:, context:)
203-
SmalrubyCorsProxy.lambda_handler(event: event, context: context)
202+
unless ENV["CI"] == "true"
203+
def lambda_handler(event:, context:)
204+
SmalrubyCorsProxy.lambda_handler(event: event, context: context)
205+
end
204206
end

lambda/smalruby-mesh-zone-get/lambda_function.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def self.lambda_handler(event:, context:)
2020
end
2121

2222
# AWS Lambda entry point
23-
def lambda_handler(event:, context:)
24-
SmalrubyMeshZoneGet.lambda_handler(event: event, context: context)
23+
unless ENV["CI"] == "true"
24+
def lambda_handler(event:, context:)
25+
SmalrubyMeshZoneGet.lambda_handler(event: event, context: context)
26+
end
2527
end

lambda/smalruby-scratch-api-proxy-get-project-info/lambda_function.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def self.lambda_handler(event:, context:)
3030
end
3131

3232
# AWS Lambda entry point
33-
def lambda_handler(event:, context:)
34-
SmalrubyScratchApiProxyGetProjectInfo.lambda_handler(event: event, context: context)
33+
unless ENV["CI"] == "true"
34+
def lambda_handler(event:, context:)
35+
SmalrubyScratchApiProxyGetProjectInfo.lambda_handler(event: event, context: context)
36+
end
3537
end

lambda/smalruby-scratch-api-proxy-translate/lambda_function.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def self.lambda_handler(event:, context:)
5858
end
5959

6060
# AWS Lambda entry point
61-
def lambda_handler(event:, context:)
62-
SmalrubyScratchApiProxyTranslate.lambda_handler(event: event, context: context)
61+
unless ENV["CI"] == "true"
62+
def lambda_handler(event:, context:)
63+
SmalrubyScratchApiProxyTranslate.lambda_handler(event: event, context: context)
64+
end
6365
end

spec/lambda/smalruby_mesh_zone_get_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
end
3636

3737
it "generates consistent domain for same IP" do
38-
result1 = lambda_handler(event: event, context: context)
39-
result2 = lambda_handler(event: event, context: context)
38+
result1 = SmalrubyMeshZoneGet.lambda_handler(event: event, context: context)
39+
result2 = SmalrubyMeshZoneGet.lambda_handler(event: event, context: context)
4040

4141
body1 = JSON.parse(result1[:body])
4242
body2 = JSON.parse(result2[:body])

0 commit comments

Comments
 (0)