Release (PyPI) #7
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: Release (PyPI + Conda) | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| id-token: write # Needed for PyPI Trusted Publishing | |
| env: | |
| RECIPE_DIR: conda-recipe | |
| ANACONDA_USER: metorial | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: astral-sh/setup-uv@v3 | |
| with: | |
| version: latest | |
| - name: Install deps | |
| working-directory: metorial-py | |
| run: uv sync --all-extras --dev | |
| - name: Run tests (skip if none) | |
| working-directory: metorial-py | |
| run: | | |
| set -e | |
| if ls tests/*.py 2>/dev/null; then | |
| uv run pytest -q | |
| else | |
| echo "No tests found; skipping pytest." | |
| fi | |
| build_publish_pypi: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| environment: pypi # remove if you don't use a protected env | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: astral-sh/setup-uv@v3 | |
| with: | |
| version: latest | |
| - name: Build sdist & wheel | |
| working-directory: metorial-py | |
| run: uv build | |
| # OPTIONAL: only to source the sdist from PyPI in meta.yaml | |
| - name: Compute sdist sha256 | |
| working-directory: metorial-py | |
| run: | | |
| SDIST=$(ls dist/*.tar.gz | head -n1) | |
| echo "PYPI_SDIST_SHA256=$(sha256sum $SDIST | cut -d' ' -f1)" >> $GITHUB_ENV | |
| - name: Publish to PyPI (OIDC) | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: metorial-py/dist | |
| skip-existing: true | |
| conda: | |
| needs: test # or [build_publish_pypi] if you require PyPI first | |
| runs-on: ubuntu-latest | |
| env: | |
| GIT_TAG: ${{ github.ref_name }} # e.g. v1.0.0 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Miniconda | |
| uses: conda-incubator/setup-miniconda@v3 | |
| with: | |
| auto-update-conda: true | |
| activate-environment: build | |
| python-version: "3.11" | |
| channels: conda-forge,defaults | |
| channel-priority: strict | |
| mamba-version: "*" | |
| - name: Install build tools | |
| shell: bash -l {0} | |
| run: mamba install -y conda-build boa anaconda-client | |
| - name: Export build vars | |
| run: echo "BUILD_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV | |
| - name: Build noarch Conda package | |
| shell: bash -l {0} | |
| run: conda mambabuild "$RECIPE_DIR" --output-folder conda_artifacts | |
| - name: Upload to Anaconda.org (dev) | |
| if: github.event.release.prerelease == true | |
| shell: bash -l {0} | |
| env: | |
| BINSTAR_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} | |
| run: | | |
| anaconda upload $(find conda_artifacts -name '*.tar.bz2') \ | |
| --user "$ANACONDA_USER" \ | |
| --label dev \ | |
| --skip-existing | |
| - name: Upload to Anaconda.org (main) | |
| if: github.event.release.prerelease == false | |
| shell: bash -l {0} | |
| env: | |
| BINSTAR_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} | |
| run: | | |
| anaconda upload $(find conda_artifacts -name '*.tar.bz2') \ | |
| --user "$ANACONDA_USER" \ | |
| --label main \ | |
| --skip-existing |