Skip to content

Feature/enable automatic deployment #10

Feature/enable automatic deployment

Feature/enable automatic deployment #10

Workflow file for this run

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:
runs-on: ubuntu-latest
needs: [lint-and-test, validate-sam-template]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment: production
permissions:
id-token: write
contents: read
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:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: GitHubActions-smalruby-infra-deploy
aws-region: ap-northeast-1
- name: Build SAM application
run: sam build --template template.yaml
- 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 \
--resolve-s3 \
--no-confirm-changeset \
--no-fail-on-empty-changeset
- name: Get deployment outputs
run: |
echo "=== Deployment Outputs ==="
aws cloudformation describe-stacks \
--stack-name smalruby-infra-prod \
--query 'Stacks[0].Outputs[*].{Key:OutputKey,Value:OutputValue}' \
--output table