Publish Python package #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: "Publish Python package" | |
| "on": | |
| release: | |
| types: | |
| - published | |
| # Allow for manual trigger on the selected branch in UI | |
| # Reducing it to only execute on devel branch today. | |
| workflow_dispatch: | |
| inputs: | |
| TESTPYPI_VERSION: | |
| description: "PEP 440 Version string to use for manual push to test Pypi" | |
| required: true | |
| type: string | |
| # For now only pyavd-utils | |
| jobs: | |
| build-pyavd-utils-wheels: | |
| name: Build and test pyavd-utils wheel on ${{ matrix.os }} | |
| if: github.repository == 'aristanetworks/pyavd-utils' | |
| permissions: | |
| contents: read | |
| actions: write | |
| pull-requests: write | |
| strategy: | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - ubuntu-24.04-arm | |
| - windows-latest | |
| - macos-15-intel | |
| - macos-latest | |
| uses: ./.github/workflows/build-wheel.yml | |
| with: | |
| runner: ${{ matrix.os }} | |
| # Default value to '' to not overwrite the version in the child workflow | |
| TESTPYPI_VERSION: ${{ inputs.TESTPYPI_VERSION || '' }} | |
| target_version: | |
| name: Set target version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| target_version: ${{ steps.target_version.outputs.TARGET_VERSION }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| - name: Install `bump-my-version` | |
| run: |- | |
| pip install bump-my-version | |
| - name: Set target version | |
| id: target_version | |
| run: |- | |
| CURRENT_VERSION=$(bump-my-version show current_version | tr '-' '.') | |
| INPUT_VALUE="${{ inputs.TESTPYPI_VERSION }}" | |
| TARGET_VERSION="${INPUT_VALUE:-$CURRENT_VERSION}" | |
| echo "TARGET_VERSION=$TARGET_VERSION" >> $GITHUB_OUTPUT | |
| publish-pyavd-utils-testpypi: | |
| name: Publish pyavd-utils to Test PyPI | |
| needs: [build-pyavd-utils-wheels] | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event_name == 'release' | |
| || (github.event_name == 'workflow_dispatch') | |
| # && github.ref == 'refs/heads/main') | |
| environment: | |
| name: test | |
| url: https://test.pypi.org/p/pyavd-utils | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download pyavd-utils wheels | |
| uses: actions/download-artifact@v7 | |
| with: | |
| path: dist/ | |
| merge-multiple: true | |
| pattern: pyavd-utils-wheels-* | |
| - name: Publish distribution to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| skip-existing: true | |
| test-pyavd-utils-from-test-pypi: | |
| name: Install from test-pypi and test on ${{ matrix.os }} for python ${{ matrix.python }} | |
| needs: [target_version, publish-pyavd-utils-testpypi] | |
| runs-on: ${{ matrix.os }} | |
| if: | | |
| github.event_name == 'release' | |
| || (github.event_name == 'workflow_dispatch') | |
| # && github.ref == 'refs/heads/main') | |
| strategy: | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - ubuntu-24.04-arm | |
| - windows-latest | |
| - macos-15-intel | |
| - macos-latest | |
| python: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - name: Checkout only the tests | |
| uses: actions/checkout@v6 | |
| with: | |
| sparse-checkout: |- | |
| tests | |
| pyproject.toml | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python }} | |
| - name: Install `pyavd-utils` from test Pypi | |
| run: |- | |
| pip install -i https://test.pypi.org/simple/ "pyavd-utils==${{ needs.target_version.outputs.target_version }}" --group pytest --extra-index-url https://pypi.org/simple | |
| - name: Run tests | |
| run: |- | |
| pytest tests | |
| test-pyavd-utils-from-test-pypi-musl: | |
| name: Install from test-pypi and test on musl linux for python ${{ matrix.python }} | |
| needs: [target_version, publish-pyavd-utils-testpypi] | |
| runs-on: ${{ matrix.os }} | |
| if: | | |
| github.event_name == 'release' | |
| || (github.event_name == 'workflow_dispatch') | |
| # && github.ref == 'refs/heads/main') | |
| strategy: | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - ubuntu-24.04-arm | |
| python: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| container: | |
| image: python:${{ matrix.python }}-alpine | |
| options: --user root | |
| volumes: | |
| - /opt:/opt:rw,rshared | |
| # checkout v6 - download-artifact v7 | |
| - /opt:/__e/node24:ro,rshared | |
| steps: | |
| - name: Allow Linux musl containers on ARM64 runners | |
| # https://github.com/actions/runner/issues/801#issuecomment-2976165281 | |
| if: contains(matrix.os, 'arm') | |
| run: | | |
| sed -i "/^ID=/s/alpine/NotpineForGHA/" /etc/os-release | |
| apk add nodejs --update-cache | |
| mkdir /opt/bin | |
| ln -s /usr/bin/node /opt/bin/node | |
| - name: Checkout only the tests | |
| uses: actions/checkout@v6 | |
| with: | |
| sparse-checkout: |- | |
| tests | |
| pyproject.toml | |
| - name: Install `pyavd-utils` from test Pypi | |
| run: |- | |
| pip install --upgrade "pip>=25.1.0" | |
| pip install -i https://test.pypi.org/simple/ "pyavd-utils==${{ needs.target_version.outputs.target_version }}" --group pytest --extra-index-url https://pypi.org/simple | |
| - name: Run tests | |
| run: |- | |
| pytest tests | |
| publish-pyavd-utils-pypi: | |
| name: Publish pyavd-utils to PyPI | |
| needs: [test-pyavd-utils-from-test-pypi, test-pyavd-utils-from-test-pypi-musl] | |
| runs-on: ubuntu-latest | |
| # We can only publish to Pypi if running on a published release, not with workflow_dispatch | |
| if: github.event_name == 'release' | |
| environment: | |
| name: production | |
| url: https://pypi.org/p/pyavd-utils | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download pyavd-utils wheels | |
| uses: actions/download-artifact@v7 | |
| with: | |
| path: dist/ | |
| merge-multiple: true | |
| pattern: pyavd-utils-wheels-* | |
| - name: Publish distribution to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |