|
| 1 | +name: Reusable Modal deploy workflow |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + description: 'The environment to deploy to (e.g., beta, prod)' |
| 10 | + modal_environment: |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + description: 'The Modal environment name (e.g., staging, main)' |
| 14 | + outputs: |
| 15 | + simulation_api_url: |
| 16 | + description: 'The deployed simulation API URL' |
| 17 | + value: ${{ jobs.deploy.outputs.simulation_api_url }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + deploy: |
| 21 | + name: Deploy to Modal |
| 22 | + runs-on: ubuntu-latest |
| 23 | + environment: ${{ inputs.environment }} |
| 24 | + outputs: |
| 25 | + simulation_api_url: ${{ steps.get-url.outputs.simulation_api_url }} |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repo |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up Python |
| 32 | + uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: "3.13" |
| 35 | + |
| 36 | + - name: Install uv |
| 37 | + uses: astral-sh/setup-uv@v3 |
| 38 | + |
| 39 | + - name: Make scripts executable |
| 40 | + run: chmod +x .github/scripts/*.sh |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + working-directory: projects/policyengine-api-simulation |
| 44 | + run: uv sync |
| 45 | + |
| 46 | + - name: Extract package versions |
| 47 | + id: versions |
| 48 | + run: .github/scripts/modal-extract-versions.sh projects/policyengine-api-simulation |
| 49 | + |
| 50 | + - name: Sync Modal secrets from GitHub |
| 51 | + working-directory: projects/policyengine-api-simulation |
| 52 | + env: |
| 53 | + MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }} |
| 54 | + MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }} |
| 55 | + LOGFIRE_TOKEN: ${{ secrets.LOGFIRE_TOKEN }} |
| 56 | + GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }} |
| 57 | + run: ../../.github/scripts/modal-sync-secrets.sh "${{ inputs.modal_environment }}" "${{ inputs.environment }}" |
| 58 | + |
| 59 | + - name: Deploy simulation API to Modal |
| 60 | + working-directory: projects/policyengine-api-simulation |
| 61 | + env: |
| 62 | + MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }} |
| 63 | + MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }} |
| 64 | + POLICYENGINE_US_VERSION: ${{ steps.versions.outputs.us_version }} |
| 65 | + POLICYENGINE_UK_VERSION: ${{ steps.versions.outputs.uk_version }} |
| 66 | + run: ../../.github/scripts/modal-deploy-app.sh "${{ inputs.modal_environment }}" src/modal/app.py |
| 67 | + |
| 68 | + - name: Get deployed URL |
| 69 | + id: get-url |
| 70 | + working-directory: projects/policyengine-api-simulation |
| 71 | + env: |
| 72 | + MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }} |
| 73 | + MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }} |
| 74 | + run: ../../.github/scripts/modal-get-url.sh "${{ inputs.modal_environment }}" |
| 75 | + |
| 76 | + - name: Verify deployment health |
| 77 | + run: .github/scripts/modal-health-check.sh "${{ steps.get-url.outputs.simulation_api_url }}" |
| 78 | + |
| 79 | + integ_test: |
| 80 | + name: Run integration tests |
| 81 | + needs: [deploy] |
| 82 | + runs-on: ubuntu-latest |
| 83 | + environment: ${{ inputs.environment }} |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout repo |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Set up Python |
| 90 | + uses: actions/setup-python@v5 |
| 91 | + with: |
| 92 | + python-version: "3.13" |
| 93 | + |
| 94 | + - name: Install uv |
| 95 | + uses: astral-sh/setup-uv@v3 |
| 96 | + |
| 97 | + - name: Make scripts executable |
| 98 | + run: chmod +x .github/scripts/*.sh |
| 99 | + |
| 100 | + - name: Generate API clients |
| 101 | + run: ./scripts/generate-clients.sh |
| 102 | + |
| 103 | + - name: Run simulation integration tests |
| 104 | + run: .github/scripts/modal-run-integ-tests.sh "${{ inputs.environment }}" "${{ needs.deploy.outputs.simulation_api_url }}" |
0 commit comments