hotfix professor role #303
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: CD | |
| on: | |
| push: | |
| branches: | |
| - prod | |
| - dev | |
| - homolog | |
| - fix/githubActions | |
| workflow_dispatch: | |
| jobs: | |
| DeployToAWS: | |
| environment: | |
| name: ${{ github.ref_name }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set AWS Account ID | |
| run: | | |
| if [[ "${{ github.ref_name }}" == "dev" ]]; then | |
| echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID_DEV }}" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref_name }}" == "homolog" ]]; then | |
| echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID_HOML }}" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref_name }}" == "prod" ]]; then | |
| echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID_PROD }}" >> $GITHUB_ENV | |
| else | |
| echo "Invalid branch name!" && exit 1 | |
| fi | |
| - name: Setup AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| with: | |
| aws-region: ${{ vars.AWS_REGION }} | |
| role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/GithubActionsRole | |
| role-session-name: github-action | |
| - name: Setting stage and stack name | |
| run: | | |
| echo "STAGE=${{ github.ref_name }}" | |
| if [[ "${{ github.ref_name }}" == "prod" ]]; then | |
| echo "STAGE=prod" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref_name }}" == "homolog" ]]; then | |
| echo "STAGE=homolog" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref_name }}" == "dev" ]]; then | |
| echo "STAGE=dev" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref_name }}" == "fix/githubActions" ]]; then | |
| echo "STAGE=dev" >> $GITHUB_ENV | |
| else | |
| echo "Invalid branch name!" && exit 1 | |
| fi | |
| echo "STACK_NAME=ReservationStackApi" >> $GITHUB_ENV | |
| - name: Fetch config from SSM | |
| run: | | |
| STAGE="${{ github.ref_name }}" | |
| USER_API_BASE=$(aws ssm get-parameter \ | |
| --name "/reservationmssuser/$STAGE/api/url" \ | |
| --query "Parameter.Value" --output text) || true | |
| if [ -n "$USER_API_BASE" ]; then | |
| echo "::add-mask::$USER_API_BASE" | |
| fi | |
| echo "USER_API_BASE=$USER_API_BASE" >> $GITHUB_ENV | |
| - name: Validate variables from ssm | |
| shell: /usr/bin/bash -e {0} | |
| run: | | |
| missing=() | |
| check_var() { | |
| local key=$1 | |
| local value=$2 | |
| if [ -z "$value" ]; then | |
| missing+=("$key") | |
| fi | |
| } | |
| check_var "USER_API_BASE" "$USER_API_BASE" | |
| if [ ${#missing[@]} -gt 0 ]; then | |
| echo "❌ Missing environment variables:" | |
| printf ' - %s\n' "${missing[@]}" | |
| exit 1 | |
| fi | |
| echo "✅ All environment variables from ssm are set" | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.13" | |
| - name: Installing Dependencies | |
| run: | | |
| npm install -g aws-cdk | |
| cd iac | |
| pip install -r requirements-infra.txt | |
| - name: DeployWithCDK | |
| run: | | |
| cd iac | |
| cdk synth | |
| cdk deploy --require-approval never | |
| env: | |
| AWS_REGION: ${{ vars.AWS_REGION }} | |
| AWS_ACCOUNT_ID: ${{ env.AWS_ACCOUNT_ID }} | |
| STACK_NAME: ${{ env.STACK_NAME }} | |
| GITHUB_REF_NAME: ${{ github.ref_name }} | |
| MSS_NAME: ${{ github.event.repository.name }} | |
| S3_ASSETS_CDN: ${{ vars.S3_ASSETS_CDN }} | |
| AUTH_DEV_SYSTEM_USERPOOL_ARN_DEV: ${{ secrets.AUTH_DEV_SYSTEM_USERPOOL_ARN_DEV }} | |
| FROM_EMAIL: ${{ vars.FROM_EMAIL }} | |
| HIDDEN_COPY: ${{ vars.HIDDEN_COPY }} | |
| REPLY_TO_EMAIL: ${{ vars.REPLY_TO_EMAIL }} | |
| USER_API_URL: ${{ env.USER_API_BASE }} |