From d9817eaf020235acde8aac8cd0476cfc313cb54e Mon Sep 17 00:00:00 2001 From: Giuseppe Peronato Date: Sat, 14 Dec 2024 12:53:40 +0100 Subject: [PATCH 1/6] Create test.yml --- .github/workflows/test.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..834fd89 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test pipeline + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag dhgen:$(date +%s) + - name: Run the tests + run: docker run --rm -it dhgen:$(date +%s) python -m unittest tests/*.py From d40e06481ce55736f69e538ad59e0ac3880c98c3 Mon Sep 17 00:00:00 2001 From: Giuseppe PERONATO Date: Sat, 14 Dec 2024 13:02:04 +0100 Subject: [PATCH 2/6] fix and improve test yaml --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 834fd89..986de10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up environment variables + run: echo "IMAGE_TAG=$(date +%s)" >> $GITHUB_ENV - name: Build the Docker image - run: docker build . --file Dockerfile --tag dhgen:$(date +%s) + run: docker build . --file Dockerfile --tag dhgen:${{ env.IMAGE_TAG }} - name: Run the tests - run: docker run --rm -it dhgen:$(date +%s) python -m unittest tests/*.py + run: docker run --rm dhgen:${{ env.IMAGE_TAG }} python -m unittest discover -s tests From cf81c115433f9d06a8d1f4561ece3b4a3b125883 Mon Sep 17 00:00:00 2001 From: Giuseppe PERONATO Date: Sat, 14 Dec 2024 13:34:25 +0100 Subject: [PATCH 3/6] fix test naming for unittest discover --- tests/{sample_networks.py => test_sample_networks.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{sample_networks.py => test_sample_networks.py} (100%) diff --git a/tests/sample_networks.py b/tests/test_sample_networks.py similarity index 100% rename from tests/sample_networks.py rename to tests/test_sample_networks.py From e31f1660a46295c4c117271090f2b8b2d779bf3f Mon Sep 17 00:00:00 2001 From: Giuseppe PERONATO Date: Sat, 14 Dec 2024 13:38:23 +0100 Subject: [PATCH 4/6] add legacy fiona requirement for tests --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 22da86a..de2fa28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,5 +45,6 @@ test = [ "pandas==1.5.3", "networkx==3.0", "requests==2.28.2", +"fiona==1.9.1", ] From dd0c7eb43473703806ca63e54031476f10039a3d Mon Sep 17 00:00:00 2001 From: Giuseppe PERONATO Date: Sat, 14 Dec 2024 13:43:22 +0100 Subject: [PATCH 5/6] separate build and test --- .github/workflows/test.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 986de10..9ea8e44 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,14 +9,23 @@ on: jobs: build: - runs-on: ubuntu-latest + outputs: + image_tag: ${{ steps.set_image_tag.outputs.image_tag }} steps: - uses: actions/checkout@v4 - name: Set up environment variables - run: echo "IMAGE_TAG=$(date +%s)" >> $GITHUB_ENV + id: set_image_tag + run: echo "::set-output name=image_tag::$(date +%s)" - name: Build the Docker image - run: docker build . --file Dockerfile --tag dhgen:${{ env.IMAGE_TAG }} + run: docker build . --file Dockerfile --tag dhgen:${{ steps.set_image_tag.outputs.image_tag }} + + test: + runs-on: ubuntu-latest + needs: build + + steps: + - uses: actions/checkout@v4 - name: Run the tests - run: docker run --rm dhgen:${{ env.IMAGE_TAG }} python -m unittest discover -s tests + run: docker run --rm dhgen:${{ needs.build.outputs.image_tag }} python -m unittest discover -s tests From 498f2071b0855df145b8cf5c174f4ed3a19a85c0 Mon Sep 17 00:00:00 2001 From: Giuseppe PERONATO Date: Sat, 14 Dec 2024 13:51:44 +0100 Subject: [PATCH 6/6] save built image as an artifact --- .github/workflows/test.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ea8e44..534e4a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,12 +20,24 @@ jobs: run: echo "::set-output name=image_tag::$(date +%s)" - name: Build the Docker image run: docker build . --file Dockerfile --tag dhgen:${{ steps.set_image_tag.outputs.image_tag }} + - name: Save Docker image as artifact + run: docker save dhgen:${{ steps.set_image_tag.outputs.image_tag }} -o dhgen.tar + - name: Upload Docker image artifact + uses: actions/upload-artifact@v3 + with: + name: dhgen-image + path: dhgen.tar test: runs-on: ubuntu-latest needs: build steps: - - uses: actions/checkout@v4 + - name: Download Docker image artifact + uses: actions/download-artifact@v3 + with: + name: dhgen-image + - name: Load Docker image + run: docker load -i dhgen.tar - name: Run the tests run: docker run --rm dhgen:${{ needs.build.outputs.image_tag }} python -m unittest discover -s tests