@@ -2,15 +2,9 @@ name: Package tests
22
33on :
44 pull_request :
5- branches :
6- - main
7- - master
8- - dev
5+ branches : [main, master, dev]
96 push :
10- branches-ignore :
11- - main
12- - master
13- - dev
7+ branches-ignore : [main, master, dev]
148 workflow_call :
159
1610permissions :
@@ -33,26 +27,30 @@ jobs:
3327 matrix : ${{ fromJson(needs.package-filter.outputs.matrix) }}
3428 runs-on : ubuntu-latest
3529 steps :
36- - name : Checkout
37- uses : actions/checkout@v4
38- - name : Set up Python
39- uses : actions/setup-python@v5
30+ - uses : actions/checkout@v4
4031 with :
41- python-version : ' 3.9'
42- - name : Install Poetry
43- uses : abatilo/actions-poetry@v2
44- - name : Install pre-commit
45- run : |
46- pip install pre-commit
47- - name : Run pre-commit hooks and check for changes
32+ fetch-depth : 0
33+
34+ - uses : actions/setup-python@v5
35+ with :
36+ python-version : ' 3.12'
37+
38+ - uses : astral-sh/setup-uv@v4
39+
40+ - name : Install and run pre-commit
4841 run : |
4942 cd "${{ matrix.package_dir }}"
43+ uv sync --all-extras
44+ uv run pre-commit run \
45+ --from-ref ${{ github.event.pull_request.base.sha || github.event.before }} \
46+ --to-ref ${{ github.event.pull_request.head.sha || github.sha }}
5047
51- poetry run pre-commit run --files ./**/**
52- if [[ $(git status --porcelain) ]]
53- then
54- echo "::error::pre-commit hooks failed for ${{ matrix.package_name }}" && exit 1
55- fi
48+ - name : Show dirty files (if pre-commit failed)
49+ if : failure()
50+ run : |
51+ cd "${{ matrix.package_dir }}"
52+ git status --porcelain
53+ git diff
5654
5755 docker :
5856 name : Docker | Build ${{ matrix.package_name }}
@@ -63,92 +61,70 @@ jobs:
6361 matrix : ${{ fromJson(needs.package-filter.outputs.matrix) }}
6462 runs-on : ubuntu-latest
6563 steps :
66- - name : Checkout
67- uses : actions/checkout@v4
68- - name : Check if Dockerfile exists
69- id : check_dockerfile
64+ - uses : actions/checkout@v4
65+
66+ - uses : docker/setup-buildx-action@v3
67+
68+ - name : Docker | Build Image
7069 run : |
71- if [ -f "${{ matrix.package_dir }}/Dockerfile" ]; then
72- echo "Dockerfile exists"
73- echo "dockerfile_exists=true" >> $GITHUB_ENV
74- else
75- echo "Dockerfile does not exist"
76- echo "dockerfile_exists=false" >> $GITHUB_ENV
70+ if [ ! -f "${{ matrix.package_dir }}/Dockerfile" ]; then
71+ echo "No Dockerfile found, skipping"
72+ exit 0
7773 fi
78- - name : Docker | Tag
79- id : docker_tag
80- if : env.dockerfile_exists == 'true'
81- run : |
8274 version=$(cat ${{ matrix.package_dir }}/VERSION)
8375 tag=polusai/${{ matrix.package_name }}:${version}
84- echo "tag will be ${tag}"
85- echo "tag=${tag}" >> $GITHUB_OUTPUT
86- - name : Docker | Setup Buildx
87- uses : docker/setup-buildx-action@v3
88- - name : Docker | Check if Image exists
89- if : env.dockerfile_exists == 'true'
90- run : |
91- tag=${{ steps.docker_tag.outputs.tag }}
9276 docker pull ${tag} > /dev/null \
93- && $(echo "::error::${tag} already exists on DockerHub" && exit 1) \
94- || echo "success"
95- - name : Docker | Build Image
96- if : env.dockerfile_exists == 'true'
97- run : |
77+ && (echo "::error::${tag} already exists on DockerHub" && exit 1) \
78+ || echo "Image does not exist, safe to build"
9879 cp .gitignore ${{ matrix.package_dir }}/.dockerignore
9980 cd "${{ matrix.package_dir }}"
10081 if [ -f "build-docker.sh" ]; then
10182 bash build-docker.sh
10283 else
103- docker build . -t ${{ steps.docker_tag.outputs. tag } }
84+ docker build . -t ${tag}
10485 fi
105- bash build-docker.sh
106- # docker buildx build --platform linux/amd64,linux/arm64 -t ${tag} --push .
10786
10887 tests :
10988 name : Test | ${{ matrix.package_name }}
11089 needs : package-filter
90+ timeout-minutes : 30
11191 if : ${{ needs.package-filter.outputs.num_packages > 0 }}
11292 strategy :
11393 fail-fast : false
11494 matrix : ${{ fromJson(needs.package-filter.outputs.matrix) }}
11595 runs-on : ubuntu-latest
11696 steps :
117- - name : Checkout
118- uses : actions/checkout@v4
97+ - uses : actions/checkout@v4
11998 with :
12099 lfs : true
121- - name : Set up Python
122- uses : actions/setup-python@v5
100+
101+ - uses : actions/setup-python@v5
123102 with :
124- python-version : ' 3.9'
125- - name : Install Conda
103+ python-version : ' 3.12'
104+
105+ - name : Run tests with conda
106+ if : ${{ hashFiles(format('{0}/environment.yml', matrix.package_dir)) != '' }}
126107 uses : conda-incubator/setup-miniconda@v2
108+
127109 - name : Run tests with conda
110+ if : ${{ hashFiles(format('{0}/environment.yml', matrix.package_dir)) != '' }}
111+ shell : bash -l {0}
128112 run : |
129- package_dir=${{ matrix.package_dir }}
130- cd $package_dir
131- if [ -f "environment.yml" ]; then
132- conda init bash
133- source ~/.bashrc
134- conda env create -f environment.yml
135- conda activate project_env
136- pip install -e ".[all]"
137- conda install pytest
138- python -X faulthandler -m pytest -v -p no:faulthandler
139- echo "conda_installed=true" >> $GITHUB_ENV
140- else
141- echo "conda_installed=false" >> $GITHUB_ENV
142- fi
143- - name : Install Poetry
144- uses : abatilo/actions-poetry@v2
145- - name : Run tests with poetry
146- if : env.conda_installed == 'false'
147- run : |
148- poetry config virtualenvs.create false
113+ cd ${{ matrix.package_dir }}
114+ conda env create -f environment.yml
115+ conda activate project_env
116+ pip install -e ".[all]"
117+ conda install pytest -y
118+ python -X faulthandler -m pytest -v -p no:faulthandler
149119
150- package_dir=${{ matrix.package_dir }}
151- cd $package_dir
120+ - name : Run tests with uv
121+ if : ${{ hashFiles(format('{0}/environment.yml', matrix.package_dir)) == '' }}
122+ uses : astral-sh/setup-uv@v4
152123
153- poetry install
154- python -X faulthandler -m pytest -v -p no:faulthandler
124+ - name : Run tests with uv
125+ if : ${{ hashFiles(format('{0}/environment.yml', matrix.package_dir)) == '' }}
126+ run : |
127+ cd ${{ matrix.package_dir }}
128+ uv sync --all-extras || uv pip install -e ".[all]"
129+ uv pip install pytest
130+ uv run python -X faulthandler -m pytest -v -p no:faulthandler
0 commit comments