-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (90 loc) · 3.27 KB
/
test.yml
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
80
81
82
83
84
85
86
87
88
89
90
name: Test, Deploy, and Verify
on:
pull_request:
types: [opened, reopened, synchronize]
pull_request_target:
types: [labeled, synchronize]
push:
branches:
- main
- "**"
workflow_dispatch:
jobs:
check_and_run:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install uv
run: pip install uv
- name: Create virtual environment and install dependencies
run: |
uv venv
. .venv/bin/activate
uv pip install -e ".[dev]"
- name: Check for 'safe to deploy' label
id: check_label
run: |
echo "Event name: ${{ github.event_name }}"
echo "Event action: ${{ github.event.action }}"
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
if [[ ${{ contains(github.event.pull_request.labels.*.name, 'safe to deploy') }} == 'true' ]]; then
echo "safe_to_deploy=true" >> $GITHUB_OUTPUT
else
echo "safe_to_deploy=false" >> $GITHUB_OUTPUT
fi
else
echo "safe_to_deploy=true" >> $GITHUB_OUTPUT
fi
- name: Run pre-deployment tests
if: steps.check_label.outputs.safe_to_deploy == 'true'
run: |
. .venv/bin/activate
pytest tests --ignore=tests/test_modal.py
- name: Check for Modal secrets
id: check_secrets
if: steps.check_label.outputs.safe_to_deploy == 'true'
run: |
if [ -z "${{ secrets.MODAL_TOKEN_ID }}" ] || [ -z "${{ secrets.MODAL_TOKEN_SECRET }}" ]; then
echo "modal_secrets_set=false" >> $GITHUB_OUTPUT
else
echo "modal_secrets_set=true" >> $GITHUB_OUTPUT
fi
- name: Deploy to dev
if: |
steps.check_label.outputs.safe_to_deploy == 'true' &&
steps.check_secrets.outputs.modal_secrets_set == 'true'
env:
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
run: |
. .venv/bin/activate
chemenv deploy
- name: Run post-deployment tests
if: |
steps.check_label.outputs.safe_to_deploy == 'true' &&
steps.check_secrets.outputs.modal_secrets_set == 'true'
env:
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
run: |
. .venv/bin/activate
pytest tests/test_modal.py
- name: Workflow summary
run: |
echo "Workflow Summary:"
echo "Safe to deploy: ${{ steps.check_label.outputs.safe_to_deploy }}"
echo "Modal secrets set: ${{ steps.check_secrets.outputs.modal_secrets_set }}"
if [ "${{ steps.check_label.outputs.safe_to_deploy }}" != "true" ]; then
echo "The 'safe to deploy' label is not present on this pull request."
fi
if [ "${{ steps.check_secrets.outputs.modal_secrets_set }}" != "true" ]; then
echo "Modal secrets are not properly set."
fi