-
Notifications
You must be signed in to change notification settings - Fork 37
102 lines (90 loc) · 2.91 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: replicate-ci-cd
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[skip-cd]') }}
strategy:
matrix:
include:
- event: pull_request
model: 'dev', 'schnell'
env: 'test'
- event: push
model: 'dev', 'schnell'
env: 'prod'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine changes
id: what-changed
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
FILES_CHANGED=$(git diff --name-only --diff-filter=AMR origin/${{ github.base_ref }} HEAD)
else
FILES_CHANGED=$(git diff --name-only --diff-filter=AMR HEAD~1 HEAD)
fi
echo "FILES_CHANGED=$FILES_CHANGED" >> $GITHUB_ENV
if echo "$FILES_CHANGED" | grep -q 'cog.yaml' || ${{ contains(github.event.head_commit.message, '[cog build]') }}; then
echo "cog-push=true" >> $GITHUB_OUTPUT
else
echo "cog-push=false" >> $GITHUB_OUTPUT
fi
- name: Setup Cog
if: steps.what-changed.outputs.cog-push == 'true'
uses: replicate/setup-cog@v2
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}
install-cuda: false
cog-version: "v0.9.20"
- name: Free disk space
if: steps.what-changed.outputs.cog-push == 'true'
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- name: Cog build and push
if: steps.what-changed.outputs.cog-push == 'true'
run: |
./script/push.sh ${{ matrix.model }} ${{ matrix.env }}
- name: Install Yolo
if: steps.what-changed.outputs.cog-push == 'false'
run: |
sudo curl -o /usr/local/bin/yolo -L "https://github.com/replicate/yolo/releases/latest/download/yolo_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/yolo
- name: Yolo push
if: steps.what-changed.outputs.cog-push == 'false'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
run: |
echo "pushing changes to ${{ matrix.model }}"
echo "changed files: $FILES_CHANGED"
yolo push --base ${{ matrix.model }} --dest ${{ matrix.model }} $FILES_CHANGED
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python test dependencies
run: |
pip install -r requirements_test.txt
- name: Test model
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
MODEL: ${{ matrix.model }}
TEST_ENV: ${{ matrix.env }}
run: |
pytest integration-tests