Skip to content

improve package management and some cleaning #2454

improve package management and some cleaning

improve package management and some cleaning #2454

Workflow file for this run

# This workflow builds and publishes SpectrochemPy packages to:
# - PyPI (Python Package Index)
# - Anaconda Cloud
# It runs after successful completion of the test workflow
name: Build and publish packages 📦
on:
push:
branches:
- master
pull_request:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Job 1: Build and publish to PyPI
build-and-publish_pypi:
name: Build and publish distribution to PyPI
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Step 2: Setup Python
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
# Step 3: Install pypa/build
- name: Install pypa/build
run: |
python -m pip install build --user
# Step 4: Build a binary wheel and a source tarball
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
# Step 5: Upload PyPI build artifacts
- name: Upload PyPI build artifacts
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: pypi-package
path: |
dist/*.whl
dist/*.tar.gz
retention-days: 5
# Step 6: Publish package to Test PyPI
- name: Publish package to Test PyPI
if: (github.event_name == 'push' && github.repository == 'spectrochempy/spectrochempy')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
# Step 7: Publish package to PyPI
- name: Publish package to PyPI
if: (github.event_name == 'release' && github.event.action == 'published' && github.repository == 'spectrochempy/spectrochempy')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# Job 2: Build and publish to Anaconda
build_and_publish_conda_package:
name: Build and publish conda package to Anaconda.org
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Step 2: Generate conda recipe (with the correct information on version, etc...)
- name: Generate conda recipe
run: |
pip install --upgrade setuptools>=61.0.0
pip install setuptools_scm toml jinja2
python3 .github/workflows/scripts/generate_conda_recipe.py
cat recipe/meta.yaml
# Step 3: Build conda package
- name: Build conda package
uses: prefix-dev/rattler-build-action@v0.2.29
env:
CONDA_BLD_PATH: ../output
with:
recipe-path: recipe/meta.yaml
upload-artifact: false
build-args: "-c conda-forge -c spectrocat"
- run: mv ../output .
# Step 4: Upload build artifacts
- name: Upload build artifacts
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: conda-package
path: |
output/**/*.conda
output/**/*.tar.bz2
retention-days: 5
# Step 5: Publish package for release
- name: Publish package for release
if: (github.event_name == 'release' && github.event.action == 'published' && github.repository == 'spectrochempy/spectrochempy')
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
run: |
anaconda upload --force output/*/*.tar.bz2
# Step 6: Publish development package
- name: Publish development package
if: (github.event_name == 'push' && github.repository == 'spectrochempy/spectrochempy')
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
run: |
anaconda upload -l dev --force output/*/*.tar.bz2