Skip to content

Have API url be dynamic, so that UIs for PRs can query API in respective Modal environment #16

Have API url be dynamic, so that UIs for PRs can query API in respective Modal environment

Have API url be dynamic, so that UIs for PRs can query API in respective Modal environment #16

Workflow file for this run

name: Pull Request Closed
on:
pull_request:
types: [closed]
jobs:
delete_modal_env:
name: Delete Modal Environment
runs-on: ubuntu-latest
env:
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Modal
run: |
python -m pip install --upgrade pip
pip install modal
- name: Delete Modal Environment
run: |
ENV_NAME=pr${{ github.event.number }}
set +e # Disable immediate exit on error
echo "Deleting Modal environment '$ENV_NAME' if it exists..."
CREATE_OUTPUT=$(modal environment delete --confirm $ENV_NAME 2>&1)
CREATE_EXIT_CODE=$?
set -e # Re-enable immediate exit on error
if [ $CREATE_EXIT_CODE -ne 0 ]; then
if [[ "$CREATE_OUTPUT" == *"AuthError"* ]]; then
echo "Create command output: $CREATE_OUTPUT"
echo "Authentication error occurred. Exiting."
exit 1
elif [[ "$CREATE_OUTPUT" == *"<Status.NOT_FOUND: 5>"* ]]; then
echo "Modal environment '$ENV_NAME' does not exist."
else
echo "Create command output: $CREATE_OUTPUT"
echo "An unknown error occurred. Exiting."
exit 1
fi
else
echo "Modal environment '$ENV_NAME' deleted successfully."
fi