Merge pull request #33 from rdkit/EdgarHarutyunian-patch-14 #21
Workflow file for this run
This file contains 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 🐍 distribution 📦 to PyPI and TestPyPI | |
## from packaging tutorial: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ | |
# Trigger the workflow on push to a tag (used for releases) | |
on: | |
push: | |
tags: | |
- "v*" # Push events to matching v*, like v1.0, v20.15.10 | |
jobs: | |
build: | |
name: Build distribution 📦 | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
# Step 2: Set up Miniconda | |
- name: Set up Conda | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-activate-base: false | |
# Step 3: Create and activate a new environment called "buildenv" | |
- name: Create & activate Build Env | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda create -y -n buildenv python=3.9 rdkit -c conda-forge | |
conda activate buildenv | |
# Step 4: Install build tools(pip, pdm, twine) | |
- name: Install build tools | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda activate buildenv | |
pip install --upgrade pip | |
pip install pdm twine | |
# Step 5: Build a binary wheel and a source tarball | |
- name: Build a binary wheel and a source tarball | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda activate buildenv | |
pdm build | |
# Step 6: Validate the distribution | |
- name: Validate the distribution | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda activate buildenv | |
twine check dist/* | |
# Step 7: Store the distribution artifacts for later use | |
- name: Store the distribution artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
publish-to-pypi: | |
name: Publish Python 🐍 distribution 📦 to PyPI | |
needs: build | |
runs-on: ubuntu-latest | |
if: "! contains(github.ref_name, '-')" # Only run for stable tags (no '-' in tag name) | |
defaults: | |
run: | |
shell: bash | |
environment: | |
name: pypi | |
url: https://pypi.org/project/laplaciannb/ | |
permissions: | |
contents: read | |
steps: | |
# Step 1: Download the distribution artifacts | |
- name: Download all the dists | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
# Step 2: Set up Miniconda | |
- name: Set up Conda | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-activate-base: false | |
# Step 3: Create and activate a new environment called "pypienv" | |
- name: Create & activate PyPi Env | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda create -y -n pypienv python=3.9 rdkit -c conda-forge | |
conda activate pypienv | |
pip install --upgrade pip | |
pip install twine | |
# Step 4: Publish distribution 📦 to PyPI | |
- name: Publish distribution 📦 to PyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda activate pypienv | |
twine upload --non-interactive --repository-url https://upload.pypi.org/legacy/ dist/* | |
publish-to-testpypi: | |
name: Publish Python 🐍 distribution 📦 to TestPyPI | |
needs: build | |
runs-on: ubuntu-latest | |
if: contains(github.ref_name, '-') # Only run for beta tags (contains '-' in tag name) | |
defaults: | |
run: | |
shell: bash | |
environment: | |
name: testpypi | |
url: https://test.pypi.org/project/laplaciannb/ | |
permissions: | |
contents: read | |
steps: | |
# Step 1: Download the distribution artifacts | |
- name: Download all the dists | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
# Step 2: Set up Miniconda | |
- name: Set up Conda | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-activate-base: false | |
# Step 3: Create and activate a new environment called "testenv" | |
- name: Create & activate Test Env | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda create -y -n testenv python=3.9 rdkit -c conda-forge | |
conda activate testenv | |
pip install --upgrade pip | |
pip install twine | |
# Step 4: Publish distribution 📦 to TestPyPI | |
- name: Publish distribution 📦 to TestPyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: pypi-AgENdGVzdC5weXBpLm9yZwIkNDA5YTI4NjAtMGQ2Ni00MDhjLWIyNTEtZjE0MGMwOTZkNjEzAAITWzEsWyJsYXBsYWNpYW5uYiJdXQACLFsyLFsiMDE4NmFlNGEtZDU3Zi00NGY1LWJhZTEtZWJhOTgwNzdlZDc1Il1dAAAGIEi0TXsH8htF5P2HgdXO-N66z08IdmH-WpGZLgt7gY9s | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda activate testenv | |
twine upload --verbose --non-interactive --repository-url https://test.pypi.org/legacy/ dist/* | |
# Step 5: Validate after publishing to TestPyPI | |
- name: Install from TestPyPI | |
run: | | |
eval "$(conda shell.bash hook)" | |
conda activate testenv | |
pip install --index-url https://test.pypi.org/simple/ laplaciannb==0.6.4 | |
python3 -c "import laplaciannb; print('laplaciannb installed OK from TestPyPi!')" | |
github-release: | |
name: Create a GitHub release | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
# Step 2: Download the distribution artifacts | |
- name: Download all the dists | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
# Step 3: Create a GitHub release | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ github.ref_name }} | |
name: Release ${{ github.ref_name }} | |
body: | | |
## Chnages in this Release | |
- This is the automatically generated release notes for ${{ github.ref_name }}. | |
draft: false | |
prerelease: ${{ contains(github.ref_name, '-') }} # Set to true for beta releases | |
# Step 4: Attach the distribution artifacts to the GitHub release | |
- name: Attach the distribution artifacts to the GitHub release | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./dist/* | |
asset_name: $(basename $file) | |
asset_content_type: application/octet-stream |