-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (67 loc) · 2.5 KB
/
ci_cd.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: CI/CD
on:
push:
branches:
- main
pull_request:
jobs:
deploy:
name: Deploy
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.9"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
- name: Install Poetry Dependencies
working-directory: ./backend
run: |
poetry install --no-interaction --no-root
- name: Determine Modal Environment Name
id: set_env_name
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "::set-output name=env_name::dev"
else
echo "::set-output name=env_name::pr${{ github.event.pull_request.number }}"
fi
- name: Create and Set Modal Environment
working-directory: ./backend
run: |
ENV_NAME=${{ steps.set_env_name.outputs.env_name }}
set +e # Disable immediate exit on error
echo "Creating Modal environment '$ENV_NAME' if it doesn't already exist..."
CREATE_OUTPUT=$(poetry run modal environment create $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.ALREADY_EXISTS: 6>"* ]]; then
echo "Modal environment '$ENV_NAME' already exists. Setting it as the current environment."
else
echo "Create command output: $CREATE_OUTPUT"
echo "An unknown error occurred. Exiting."
exit 1
fi
else
echo "Modal environment '$ENV_NAME' created successfully."
fi
echo "Setting Modal environment to '$ENV_NAME'..."
poetry run modal config set-environment $ENV_NAME
echo "Environment '$ENV_NAME' is now set as the current Modal environment."
- name: Deploy Modal stubs as applications
working-directory: ./backend
run: |
poetry run modal deploy src.common