From ee6f52876bfcc83fe3c14cbb60a7121150de35b2 Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Thu, 15 Feb 2024 22:08:25 +0100 Subject: [PATCH 1/8] add a workflow to automatically publish releases on PyPi/TestPyPi --- .github/workflows/lint.yml | 1 + .github/workflows/publish-package.yml | 114 ++++++++++++++++++++++++++ .github/workflows/tests.yml | 1 + 3 files changed, 116 insertions(+) create mode 100644 .github/workflows/publish-package.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e8cc018ba..49fc37eb9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,7 @@ on: push: branches: [ master ] pull_request: + workflow_call: jobs: black: diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml new file mode 100644 index 000000000..8f4ab268f --- /dev/null +++ b/.github/workflows/publish-package.yml @@ -0,0 +1,114 @@ +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI + +on: + release: + types: + - released + +jobs: + + test: + name: Test the latest release commit + uses: ./.github/workflows/tests.yml + + lint: + name: Lint the latest release commit + uses: ./.github/workflows/lint.yml + + build: + name: Build distribution 📦 + needs: + - test + - lint + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: 'pyproject.toml' + + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + + - name: Build a binary wheel and a source tarball + run: python3 -m build + + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distribution + path: dist/ + + publish-to-testpypi: + name: Publish Python 🐍 distribution 📦 to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/fundus + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + test-distribution: + name: Install and test TestPyPi distribution + needs: + - publish-to-testpypi + runs-on: ubuntu-latest + + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: 'pyproject.toml' + + - name: Install package + run: >- + python3 -m + pip install + --index-url https://test.pypi.org/simple/ + --extra-index-url https://pypi.org/simple/ + fundus==${{ github.event.release.tag_name }} + + publish-to-pypi: + name: Publish Python 🐍 distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags/') + + needs: + - test-distribution + runs-on: ubuntu-latest + + environment: + name: pypi + url: https://pypi.org/p/fundus + + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2b9e31359..77e120ce0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,6 +8,7 @@ on: push: branches: [ master ] pull_request: + workflow_call: jobs: pytest: From 2130f14666e2bb98f2d650aeebf6239019c82239 Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Thu, 15 Feb 2024 22:10:55 +0100 Subject: [PATCH 2/8] add link to publishing guide --- .github/workflows/publish-package.yml | 3 +++ .github/workflows/tests.yml | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 8f4ab268f..d502cc475 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -1,3 +1,6 @@ +# This release workflow was created using the following guide +# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ + name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI on: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 77e120ce0..1af880305 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: -# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - name: tests on: From 7e365cb23fd4a1cec89e376269be8403271fd088 Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Thu, 15 Feb 2024 22:18:16 +0100 Subject: [PATCH 3/8] remove leftover --- .github/workflows/publish-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index d502cc475..112cafd37 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -56,7 +56,7 @@ jobs: environment: name: testpypi - url: https://test.pypi.org/p/fundus + url: https://test.pypi.org/p/fundus permissions: id-token: write From 00e9a2ab6aef3d90808b0d71c33257afd7dd0b5a Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Tue, 26 Mar 2024 14:35:57 +0100 Subject: [PATCH 4/8] fix distribution action --- .github/workflows/publish-package.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 112cafd37..d4be7f697 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -45,7 +45,7 @@ jobs: - name: Store the distribution packages uses: actions/upload-artifact@v3 with: - name: python-package-distribution + name: python-package-distributions path: dist/ publish-to-testpypi: @@ -78,6 +78,7 @@ jobs: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: From 743aea816defa8122d3bee220aee9f1ad7b68714 Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Tue, 26 Mar 2024 15:40:23 +0100 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Conrad Dobberstein --- .github/workflows/publish-package.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index d4be7f697..4843b966f 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -57,6 +57,7 @@ jobs: environment: name: testpypi url: https://test.pypi.org/p/fundus + permissions: id-token: write @@ -66,6 +67,7 @@ jobs: with: name: python-package-distributions path: dist/ + - name: Publish distribution 📦 to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: @@ -113,6 +115,7 @@ jobs: with: name: python-package-distributions path: dist/ + - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 From 4e2849c0cd086d25b95b8e8c9e658c320af13b7a Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Tue, 26 Mar 2024 15:42:24 +0100 Subject: [PATCH 6/8] formatting and removed some leftovers --- .github/workflows/publish-package.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 4843b966f..6fdf7c0fe 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -87,7 +87,7 @@ jobs: python-version-file: 'pyproject.toml' - name: Install package - run: >- + run: >- python3 -m pip install --index-url https://test.pypi.org/simple/ @@ -96,10 +96,8 @@ jobs: publish-to-pypi: name: Publish Python 🐍 distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags/') - needs: - - test-distribution + - test-distribution runs-on: ubuntu-latest environment: From dc67c2d3f76654f4b342d1be22200874d7cadfe7 Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Tue, 26 Mar 2024 15:46:35 +0100 Subject: [PATCH 7/8] pin python version to `3.8` --- .github/workflows/publish-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 6fdf7c0fe..6a56dda5d 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -30,7 +30,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version-file: 'pyproject.toml' + python-version: '3.8' - name: Install pypa/build run: >- @@ -84,7 +84,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version-file: 'pyproject.toml' + python-version: '3.8' - name: Install package run: >- From 9d4d6a803e116085e8d2b37f8bb3995655a4c071 Mon Sep 17 00:00:00 2001 From: Max Dallabetta Date: Tue, 26 Mar 2024 17:25:35 +0100 Subject: [PATCH 8/8] add 2m sleep to ensure package is available after publishing on testpypi --- .github/workflows/publish-package.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 6a56dda5d..33f489899 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -73,6 +73,10 @@ jobs: with: repository-url: https://test.pypi.org/legacy/ + - name: Sleep for 2 minutes + run: sleep 2m + shell: bash + test-distribution: name: Install and test TestPyPi distribution needs: