Skip to content

CD

CD #325

Workflow file for this run

name: CD
on: [push, pull_request, workflow_dispatch]
jobs:
pypi:
name: build and deploy to PyPI
if: github.repository == 'ACCESS-NRI/ACCESS-MOPPeR' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: "ubuntu-latest"
permissions:
id-token: write
steps:
- name: Checkout source
uses: actions/checkout@v5
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install build dependencies
run: python -m pip install build twine
- name: Build distributions
shell: bash -l {0}
run: |
git clean -xdf
pyproject-build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
conda:
name: build and deploy to conda (${{ matrix.os }})
needs: pypi
if: always() && needs.pypi.result == 'success'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macOS-latest, ubuntu-latest]
python-version: [3.11]
steps:
- name: Debug matrix info
run: |
echo "Running on: ${{ matrix.os }}"
echo "Python version: ${{ matrix.python-version }}"
echo "Runner OS: ${{ runner.os }}"
- name: Checkout source
uses: actions/checkout@v5
- name: Wait for PyPI propagation
run: |
echo "Waiting for PyPI package to be available..."
PACKAGE_NAME="access_mopper"
VERSION=$(python -c "import versioneer; print(versioneer.get_version())")
# Strip 'v' prefix if present (git tags often have 'v' but PyPI versions don't)
VERSION=${VERSION#v}
echo "Looking for package: ${PACKAGE_NAME}==${VERSION}"
# Wait up to 15 minutes for the package to be available
for i in {1..90}; do
echo "Attempt $i/90: Checking PyPI availability..."
# Try multiple methods to check package availability
# Method 1: Check PyPI JSON API
if curl -s "https://pypi.org/pypi/${PACKAGE_NAME}/json" | grep -q "\"${VERSION}\""; then
echo "✅ Package ${PACKAGE_NAME}==${VERSION} found via PyPI API!"
break
fi
# Method 2: Try pip install --dry-run (fallback)
if pip install --dry-run ${PACKAGE_NAME}==${VERSION} >/dev/null 2>&1; then
echo "✅ Package ${PACKAGE_NAME}==${VERSION} is installable!"
break
fi
if [ $i -eq 90 ]; then
echo "❌ Package not found on PyPI after 15 minutes"
echo "Available versions:"
curl -s "https://pypi.org/pypi/${PACKAGE_NAME}/json" | grep -o '"[0-9][^"]*"' | head -10 || echo "Could not fetch versions"
exit 1
fi
echo "Package not yet available, waiting 10 seconds..."
sleep 10
done
- name: Setup conda environment
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
environment-file: .conda/environment.yml
auto-update-conda: false
auto-activate-base: false
show-channel-urls: true
- name: Build and upload the conda package
uses: ACCESS-NRI/[email protected]
with:
meta_yaml_dir: .conda
upload: true
user: accessnri
label: main
token: ${{ secrets.anaconda_token }}