Update release.yml #3
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: Test, Release, and Verify PyPI Package | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| tags: | ||
| - 'v*.*.*' | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - master | ||
| workflow_dispatch: | ||
| jobs: | ||
| # Job 1: Test on all platforms (runs on push, PR, and before release) | ||
| test: | ||
| name: Test on ${{ matrix.os }} - Python ${{ matrix.python-version }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-latest] | ||
| python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install termcolor | ||
| - name: Run tests | ||
| run: python test.py | ||
| continue-on-error: false | ||
| # Job 2: Build and publish to PyPI (only on tags) | ||
| release-to-pypi: | ||
| name: Build and Release to PyPI | ||
| needs: test | ||
| runs-on: ubuntu-latest | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Install build dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build twine | ||
| - name: Build package | ||
| run: python -m build | ||
| - name: Check package | ||
| run: twine check dist/* | ||
| - name: Publish to PyPI | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
| run: twine upload dist/* | ||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| files: dist/* | ||
| generate_release_notes: true | ||
| # Job 3: Test installation from PyPI on all platforms (only after release) | ||
| test-after-release: | ||
| name: Verify Install on ${{ matrix.os }} - Python ${{ matrix.python-version }} | ||
| needs: release-to-pypi | ||
| runs-on: ${{ matrix.os }} | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-latest] | ||
| python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Extract version from tag | ||
| id: get_version | ||
| shell: bash | ||
| run: | | ||
| VERSION=${GITHUB_REF#refs/tags/v} | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| - name: Wait for PyPI to update | ||
| run: | | ||
| echo "Waiting 30 seconds for PyPI to process the package..." | ||
| sleep 30 | ||
| shell: bash | ||
| - name: Install package from PyPI | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install --force-reinstall --no-cache-dir dpqc==${{ steps.get_version.outputs.version }} | ||
| - name: pip_test: Ensure pip-installed dpqc | ||
| run: python pip_test.py | ||
| - name: Run tests with installed package | ||
| env: | ||
| PYTHONPATH: "" | ||
| run: python test.py | ||
| continue-on-error: false | ||