feat: implement GitHub Actions CI/CD pipeline #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 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 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - 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: Download SAM build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: sam-build-artifacts | |
| path: .aws-sam/ | |
| - 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 | |
| - name: Upload deployment logs | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: deployment-logs | |
| path: | | |
| .aws-sam/ | |
| retention-days: 30 |