From acc8da1c8724a43e06df562fb8166ac09269a021 Mon Sep 17 00:00:00 2001 From: erikhuck Date: Wed, 17 Apr 2024 16:57:09 -0400 Subject: [PATCH] Adds running tests to release workflow --- .github/workflows/package_release.yml | 44 ++++++++++++++------------- .github/workflows/pypi.yml | 33 ++++++++++++++++++++ .github/workflows/tests.yml | 35 +++++++++++++++++++++ 3 files changed, 91 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/pypi.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/package_release.yml b/.github/workflows/package_release.yml index b9d2c02..5c84d95 100644 --- a/.github/workflows/package_release.yml +++ b/.github/workflows/package_release.yml @@ -1,33 +1,35 @@ -name: Release the Next Version of the Package +name: Release the Next Version of the Package and Documentation on: release: types: [published] - workflow_dispatch: jobs: - deploy: + release-version: + name: Parse the release version runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies + - id: parse-version + name: Parse release version run: | - python3 -m pip install --upgrade pip - python3 -m pip install build - python3 -m pip install twine - - name: Build package - run: python -m build - - name: Check package - run: python3 -m twine check dist/* - - name: Publish package to Test-PyPi - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository-url: https://test.pypi.org/legacy/ + echo "version=${RELEASE_VERSION/v/}" >> "$GITHUB_OUTPUT" + env: + RELEASE_VERSION: ${{ github.event.release.tag_name }} + outputs: + version: ${{ steps.parse-version.outputs.version }} + publish-test-pypi: + name: Publish the package to Test-PyPi + uses: ./.github/workflows/pypi.yml + with: + pypi_api_token: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + test-test-pypi: + name: Run the tests on the Test-PyPi package + needs: [release-version, publish-test-pypi] + uses: ./.github/workflows/tests.yml + with: + install_command: "python3 -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple gpu-tracker==${{ needs.release-version.outputs.version }}" + # - name: Publish package to PyPi # uses: pypa/gh-action-pypi-publish@release/v1 # with: diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..99c280e --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,33 @@ +name: Publish package + +on: + workflow_call: + inputs: + pypi_api_token: + description: The API token to access the PyPi distribution + required: true + type: string + repository_url: + description: The URL of the PyPi distribution + required: true + type: string + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install build + - name: Build package + run: python3 -m build + - name: Publish package to a PyPi distribution + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ inputs.pypi_api_token }} + repository-url: ${{ inputs.repository_url }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..6d220eb --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,35 @@ +name: Run Tests + +on: + workflow_call: + inputs: + install_command: + description: The command for installing the package to test. + required: true + type: string +jobs: + run-tests: + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12"] + os: [ ubuntu-latest, windows-latest, macOS-latest ] + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install testing environment + run: | + python3 -m pip install --upgrade pip + python3 -m pip install pytest pytest-mock pytest-cov + - name: Install package + uses: Wandalen/wretry.action@master + with: + command: ${{ inputs.install_command }} + attempt_limit: 10 + attempt_delay: 10000 + - name: Run tests on package + run: python3 -m pytest tests --cov --cov-branch --cov-report=term-missing