forked from PolusAI/image-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (145 loc) · 4.66 KB
/
package-tests.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Package tests
on:
pull_request:
branches:
- main
- master
- dev
push:
branches-ignore:
- main
- master
- dev
workflow_call:
permissions:
contents: read
jobs:
package-filter:
name: Filter for updated package
uses: ./.github/workflows/package-filter.yml
with:
num-commits: 0
ignore-missing-dev: false
pre-commit:
name: Pre-commit | ${{ matrix.package_name }}
needs: package-filter
if: ${{ needs.package-filter.outputs.num_packages > 0 }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install pre-commit
run: |
pip install pre-commit
- name: Run pre-commit hooks and check for changes
run: |
cd "${{ matrix.package_dir }}"
poetry run pre-commit run --files ./**/**
if [[ $(git status --porcelain) ]]
then
echo "::error::pre-commit hooks failed for ${{ matrix.package_name }}" && exit 1
fi
docker:
name: Docker | Build ${{ matrix.package_name }}
needs: package-filter
if: ${{ needs.package-filter.outputs.num_packages > 0 }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if Dockerfile exists
id: check_dockerfile
run: |
if [ -f "${{ matrix.package_dir }}/Dockerfile" ]; then
echo "Dockerfile exists"
echo "dockerfile_exists=true" >> $GITHUB_ENV
else
echo "Dockerfile does not exist"
echo "dockerfile_exists=false" >> $GITHUB_ENV
fi
- name: Docker | Tag
id: docker_tag
if: env.dockerfile_exists == 'true'
run: |
version=$(cat ${{ matrix.package_dir }}/VERSION)
tag=polusai/${{ matrix.package_name }}:${version}
echo "tag will be ${tag}"
echo "tag=${tag}" >> $GITHUB_OUTPUT
- name: Docker | Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Docker | Check if Image exists
if: env.dockerfile_exists == 'true'
run: |
tag=${{ steps.docker_tag.outputs.tag }}
docker pull ${tag} > /dev/null \
&& $(echo "::error::${tag} already exists on DockerHub" && exit 1) \
|| echo "success"
- name: Docker | Build Image
if: env.dockerfile_exists == 'true'
run: |
cp .gitignore ${{ matrix.package_dir }}/.dockerignore
cd "${{ matrix.package_dir }}"
if [ -f "build-docker.sh" ]; then
bash build-docker.sh
else
docker build . -t ${{ steps.docker_tag.outputs.tag }}
fi
bash build-docker.sh
# docker buildx build --platform linux/amd64,linux/arm64 -t ${tag} --push .
tests:
name: Test | ${{ matrix.package_name }}
needs: package-filter
if: ${{ needs.package-filter.outputs.num_packages > 0 }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install Conda
uses: conda-incubator/setup-miniconda@v2
- name: Run tests with conda
run: |
package_dir=${{ matrix.package_dir }}
cd $package_dir
if [ -f "environment.yml" ]; then
conda init bash
source ~/.bashrc
conda env create -f environment.yml
conda activate project_env
pip install -e ".[all]"
conda install pytest
python -X faulthandler -m pytest -v -p no:faulthandler
echo "conda_installed=true" >> $GITHUB_ENV
else
echo "conda_installed=false" >> $GITHUB_ENV
fi
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Run tests with poetry
if: env.conda_installed == 'false'
run: |
poetry config virtualenvs.create false
package_dir=${{ matrix.package_dir }}
cd $package_dir
poetry install
python -X faulthandler -m pytest -v -p no:faulthandler