From ab093ad63c8f4cbadc865953fde0aaf2eadbd9d3 Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Wed, 11 Oct 2023 09:19:21 -0700 Subject: [PATCH] Update test.pypi.org upload workflow (#25) * fix: Update some type-hinting directive comments. * ci: Refactored the test.pypi.org upload workflow to have separate sections to limit elevated permissions usage. * ci: Add a retry to the installation step to let the package become available on the index server. --- .github/workflows/package-testpypi.yml | 65 +++++++++++++------ .../drivers/pi/scopes/tekscope/tekscope.py | 2 +- tests/test_device_manager.py | 2 +- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/.github/workflows/package-testpypi.yml b/.github/workflows/package-testpypi.yml index eef683b1..f1dec71d 100644 --- a/.github/workflows/package-testpypi.yml +++ b/.github/workflows/package-testpypi.yml @@ -1,20 +1,16 @@ --- +# Upload to Test PyPI on every push to main name: Publish package to test.pypi.org on: push: branches: [main] -permissions: - contents: write - id-token: write concurrency: - group: test-pypi-upload + group: pypi jobs: - # Upload to Test PyPI on every push to main - test-pypi: - name: Publish package to test.pypi.org + test-pypi-build: + name: Build package with unique version for test.pypi.org if: github.repository == 'tektronix/tm_devices' runs-on: ubuntu-latest - environment: package-testpypi steps: - uses: actions/checkout@v3 with: @@ -26,27 +22,56 @@ jobs: python-version: 3.11 check-latest: true - name: Install workflow dependencies - run: pip install poetry tomli tomli_w requests + run: pip install poetry-core tomli tomli_w requests - name: Create unique package version + id: create-version run: | CURRENT_VERSION=$(python scripts/pypi_latest_version.py --package=tm_devices --index=test.pypi) echo CURRENT_VERSION: $CURRENT_VERSION NEW_VERSION=$(python scripts/create_post_version_for_testpypi.py --version=$CURRENT_VERSION) echo NEW_VERSION: $NEW_VERSION python scripts/project_version.py --set-version=$NEW_VERSION - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - - uses: hynek/build-and-inspect-python-package@v1.5 - id: build-pkg - - name: Copy package to dist/ folder - run: | - mkdir -p dist/ - cp ${{ steps.build-pkg.outputs.dist }}/*.whl ${{ steps.build-pkg.outputs.dist }}/*.tar.gz dist/ + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT + - name: Build package + uses: hynek/build-and-inspect-python-package@v1.5 + outputs: + built-version: ${{ steps.create-version.outputs.NEW_VERSION }} + test-pypi-upload: + name: Upload package to test.pypi.org + needs: test-pypi-build + if: github.repository == 'tektronix/tm_devices' + runs-on: ubuntu-latest + environment: package-testpypi + permissions: + id-token: write + steps: + - name: Download built packages + uses: actions/download-artifact@v3 + with: + name: Packages + path: dist - name: Upload package to Test PyPI uses: pypa/gh-action-pypi-publish@v1.8.8 with: repository-url: https://test.pypi.org/legacy/ - - name: Wait for package to be available - run: sleep 30 + test-pypi-install: + name: Install package from test.pypi.org + needs: [test-pypi-build, test-pypi-upload] + if: github.repository == 'tektronix/tm_devices' + runs-on: ubuntu-latest + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: x + check-latest: true - name: Test installing from test.pypi.org - run: pip install --index-url=https://test.pypi.org/simple/ --extra-index-url=https://pypi.org/simple - tm_devices==${{ env.NEW_VERSION }} + # A retry is used to allow for some downtime before the package is installable + uses: nick-fields/retry@v2 + with: + timeout_minutes: 2 + max_attempts: 5 + retry_wait_seconds: 30 + warning_on_retry: false + command: pip install --index-url=https://test.pypi.org/simple/ --extra-index-url=https://pypi.org/simple + tm_devices==${{ needs.test-pypi-build.outputs.built-version }} diff --git a/src/tm_devices/drivers/pi/scopes/tekscope/tekscope.py b/src/tm_devices/drivers/pi/scopes/tekscope/tekscope.py index d80489f5..773c26aa 100644 --- a/src/tm_devices/drivers/pi/scopes/tekscope/tekscope.py +++ b/src/tm_devices/drivers/pi/scopes/tekscope/tekscope.py @@ -168,7 +168,7 @@ def channel(self) -> "MappingProxyType[str, TekScopeChannel]": # Set scope PI verbosity back to previous value self.set_and_check(":VERBose", old_pi_verbosity) - return MappingProxyType(channel_map) + return MappingProxyType(channel_map) # pyright: ignore[reportUnknownVariableType] @property def commands( diff --git a/tests/test_device_manager.py b/tests/test_device_manager.py index f8e63215..d90370b5 100644 --- a/tests/test_device_manager.py +++ b/tests/test_device_manager.py @@ -66,7 +66,7 @@ class TestDeviceManager: # pylint: disable=no-self-use # Get the list of device types, ignore the unit test ones since # this test only applies to actual supported devices. "device_type", - list(filter(lambda x: "UNIT_TEST" not in x, (y.name for y in DeviceTypes))), # type: ignore + list(filter(lambda x: "UNIT_TEST" not in x, (y.name for y in DeviceTypes))), ) def test_supported_device_type_methods(self, device_type: str) -> None: """Test that all supported device types have a getter method in the DeviceManager.