Skip to content

Remove need for main branch to run testpypi #6

Remove need for main branch to run testpypi

Remove need for main branch to run testpypi #6

Workflow file for this run

name: Run tests, publish Python distribution to PyPI and TestPyPI
on:
push:
branches: ["main", "devel"]
pull_request:
branches: ["main", "devel"]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install -r requirements.txt
- name: Test with pytest
run: |
pytest
# Code below modified from
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
build:
name: Build distribution 📦
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
# If we've pushed to main we'll to a test release to TestPyPI
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/openghg_calscales
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/openghg_calscales
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
release_conda:
name: Build and publish conda package
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
needs:
- test
defaults:
run:
shell: bash -el {0}
steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@db1df3ba9e07ea86f759e98b575c002747e9e757
with:
init-shell: bash
- name: Build and push the conda package
run: |
micromamba create -n openghg_build anaconda-client boa -c conda-forge
micromamba activate openghg_build
conda config --append channels openghg
mkdir ${{ github.workspace }}/build
conda mambabuild --croot ${{ github.workspace }}/build recipes -c conda-forge
BUILD_DIR=${GITHUB_WORKSPACE}/build
BUILD=$(find "$BUILD_DIR" -name '*.tar.bz2')
anaconda --token "$ANACONDA_TOKEN" upload --user openghg --label main "$BUILD"
env:
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'