diff --git a/.github/workflows/build_test_push_images.yml b/.github/workflows/build_test_push_images.yml new file mode 100644 index 0000000..eed57e8 --- /dev/null +++ b/.github/workflows/build_test_push_images.yml @@ -0,0 +1,98 @@ +name: Build, Test and Push changed Dockerfiles + +on: + push: + branches: + - main + pull_request: + branches: [main] + types: [synchronize, opened, reopened, ready_for_review] + +jobs: + prepare-matrix-jobs: + name: Prepare Build and Test Jobs + runs-on: "ubuntu-latest" + outputs: + has_changed_files: ${{ steps.changed-files.outputs.any_changed }} + sorters: ${{ steps.get-changed-sorters.outputs.sorters }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v23 + with: + files: | + */Dockerfile + files_ignore: | + hdsort-compiled/* + ironclust-compiled/* + kilosort_no_license/* + kilosort_with_license/* + spikeinterface-jupyterlab/* + tests/* + waveclus-compiled/* + + - name: Prepare jobs matrix + id: get-changed-sorters + run: | + # sorters variable will be a JSON-like array + sorters="[" + + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + # Removing /Dockerfile from string + parsed=${file%*/Dockerfile*} + + # Appending to final string + sorters+="\"${parsed}\", " + done + sorters=${sorters%*, *} + sorters+="]" + + echo ${sorters} + echo "::set-output name=sorters::${sorters}" + + build-and-test-image: + name: Build and Test (${{ matrix.sorter }}) + if: needs.prepare-matrix-jobs.outputs.has_changed_files == 'true' + needs: prepare-matrix-jobs + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # "macos-latest", "windows-latest" + os: ["ubuntu-latest", ] + sorter: ${{ fromJSON(needs.prepare-matrix-jobs.outputs.sorters) }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + python-version: 3.8 + + - name: Build ${{ matrix.sorter }} Docker image + run: | + cd ${{ matrix.sorter }} + bash build.sh + + - uses: eWaterCycle/setup-singularity@v7 + with: + singularity-version: 3.8.3 + + - name: Install dependencies & Test ${{ matrix.sorter }} image + run: | + if [[ ${{ matrix.sorter }} == 'tridesclous' ]]; then + pip install tridesclous + fi + pip install -r requirements_test.txt + pytest -sv tests/test_singularity_containers.py::test_${{ matrix.sorter }} + + - name: Docker login & Push image + if: github.ref == 'refs/heads/main' + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + cd ${{ matrix.sorter }} + bash push.sh diff --git a/.github/workflows/test_containers_singularity.yml b/.github/workflows/test_containers_singularity.yml index cdc2545..59fbca5 100644 --- a/.github/workflows/test_containers_singularity.yml +++ b/.github/workflows/test_containers_singularity.yml @@ -31,5 +31,4 @@ jobs: - name: Run test singularity containers run: | - pip install tridesclous pytest -sv tests/test_singularity_containers.py