Create general_report.md #53
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: Deploy to Staging | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| # Terraform Infrastructure | |
| terraform: | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| environment: staging | |
| outputs: | |
| database_url: ${{ steps.database_url.outputs.database_url }} | |
| defaults: | |
| run: | |
| working-directory: terraform/staging/rds | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - 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: ${{ secrets.AWS_REGION }} | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.12.0 | |
| - name: Terraform Format Check | |
| run: terraform fmt -check | |
| continue-on-error: true | |
| - name: Terraform Init | |
| run: terraform init | |
| - name: Terraform Validate | |
| run: terraform validate | |
| - name: Terraform Plan | |
| run: | | |
| terraform plan -out=tfplan | |
| - name: Terraform Apply | |
| run: terraform apply -auto-approve tfplan | |
| - name: Get Database URL | |
| id: database_url | |
| run: | | |
| RDS_ENDPOINT=$(terraform output -raw db_endpoint) | |
| DB_PASSWORD=$(terraform output -raw db_password) | |
| DB_USERNAME=$(terraform output -raw db_username) | |
| ENCODED_PASSWORD=$(printf '%s' "$DB_PASSWORD" | jq -sRr @uri) | |
| DATABASE_URL="postgresql://${DB_USERNAME}:${ENCODED_PASSWORD}@${RDS_ENDPOINT}/analytics?sslmode=require" | |
| echo "database_url=$DATABASE_URL" >> $GITHUB_OUTPUT | |
| database-migrations: | |
| runs-on: ubuntu-latest | |
| needs: [terraform] | |
| if: github.ref == 'refs/heads/main' | |
| environment: staging | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Docker | |
| run: | | |
| curl -fsSL https://get.docker.com | sh | |
| - name: Run database migrations | |
| env: | |
| DATABASE_URL: ${{ needs.terraform.outputs.database_url || secrets.DATABASE_URL }} | |
| GITHUB_ACTIONS: true | |
| run: | | |
| chmod +x sql/migrate.sh | |
| bash sql/migrate.sh up |