1+ name : Test and Deploy
2+
3+ on :
4+ push :
5+ branches : [main]
6+ tags :
7+ - ' v*'
8+ pull_request :
9+ branches : [main, "release/*", "dev"]
10+
11+ permissions :
12+ contents : read
13+ packages : write
14+
15+ jobs :
16+ test :
17+ runs-on : ${{ matrix.os }}
18+ strategy :
19+ fail-fast : false
20+ matrix :
21+ os : ["ubuntu-latest", "windows-latest"]
22+ python-version : ["3.11"]
23+ timeout-minutes : 20
24+
25+ steps :
26+ - name : Checkout
27+ uses : actions/checkout@v4
28+
29+ - name : Set up Python ${{ matrix.python-version }}
30+ uses : actions/setup-python@v4
31+ with :
32+ python-version : ${{ matrix.python-version }}
33+
34+ - name : Install dependencies
35+ run : |
36+ python -m pip install --upgrade pip
37+ pip install -r requirements.txt
38+ shell : bash
39+
40+ - name : Install sh (Ubuntu only)
41+ if : matrix.os == 'ubuntu-latest'
42+ run : pip install sh
43+
44+ - name : List dependencies
45+ run : python -m pip list
46+
47+ - name : Run pytest
48+ run : pytest -v
49+
50+ build-and-push :
51+ needs : test
52+ runs-on : ubuntu-latest
53+ # Only run on pushes to main/workflow_test or tags, not on PRs
54+ if : github.event_name == 'push'
55+
56+ steps :
57+ - name : Checkout
58+ uses : actions/checkout@v4
59+
60+ - name : Set up Docker Buildx
61+ uses : docker/setup-buildx-action@v3
62+
63+ - name : Log in to GHCR
64+ uses : docker/login-action@v3
65+ with :
66+ registry : ghcr.io
67+ username : ${{ github.actor }}
68+ password : ${{ secrets.PASSWORD }}
69+
70+ - name : Create dummy .env for CI
71+ run : |
72+ echo "host_config_dir=/tmp/configs" >> .env
73+ echo "host_data_dir=/tmp/data" >> .env
74+ echo "host_log_dir=/tmp/logs" >> .env
75+
76+ - name : Extract Docker metadata
77+ id : meta
78+ uses : docker/metadata-action@v5
79+ with :
80+ images : |
81+ ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
82+ tags : |
83+ type=raw,value=latest
84+
85+ - name : Build and push
86+ uses : docker/bake-action@v5
87+ with :
88+ files : |
89+ docker-compose.yaml
90+ push : true
91+ set : |
92+ *.platform=linux/amd64
93+ *.cache-from=type=gha
94+ *.cache-to=type=gha,mode=max
95+ deepvisionxplain.tags=${{ steps.meta.outputs.tags }}
96+
97+ cleanup-old-packages :
98+ needs : build-and-push
99+ runs-on : ubuntu-latest
100+ if : github.event_name == 'push'
101+
102+ steps :
103+ - name : Delete old packages
104+ uses : actions/delete-package-versions@v4
105+ with :
106+ package-name : ' deepvisionxplain'
107+ package-type : ' container'
108+ min-versions-to-keep : 4
109+ delete-only-untagged-versions : false
110+ token : ${{ secrets.PASSWORD }}
0 commit comments