Skip to content

Commit

Permalink
Dont require Dockerfile, build before test (#530)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Duane Walker <[email protected]>
  • Loading branch information
misterbrandonwalker and Brandon Duane Walker authored Apr 12, 2024
1 parent 8d7852e commit f8e24f8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
id: package-filter
run: |
PACKAGE_DIRS=""
COMPANION_FILES="VERSION Dockerfile .bumpversion.cfg plugin.json"
COMPANION_FILES="VERSION .bumpversion.cfg plugin.json"
# echo the base ref
base_ref=${{ github.base_ref }}
Expand Down
80 changes: 56 additions & 24 deletions .github/workflows/package-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,6 @@ jobs:
echo "::error::pre-commit hooks failed for ${{ matrix.package_name }}" && exit 1
fi
tests:
name: Test | ${{ matrix.package_name }}
needs: package-filter
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: Run tests
run: |
package_dir=${{ matrix.package_dir }}
cd $package_dir
poetry install
poetry run pytest -v
docker:
name: Docker | Build ${{ matrix.package_name }}
needs: package-filter
Expand All @@ -87,8 +63,19 @@ jobs:
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}
Expand All @@ -97,14 +84,59 @@ jobs:
- 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 }}"
docker build . -t ${{ steps.docker_tag.outputs.tag }}
# docker buildx build --platform linux/amd64,linux/arm64 -t ${tag} --push .

tests:
name: Test | ${{ matrix.package_name }}
needs: package-filter
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 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
pytest -v
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: |
package_dir=${{ matrix.package_dir }}
cd $package_dir
poetry install
poetry run pytest -v

0 comments on commit f8e24f8

Please sign in to comment.