Skip to content

Commit

Permalink
Add PyPI release draft (#200)
Browse files Browse the repository at this point in the history
* Add pypi release YAML file

* Use `iodata` from PyPI release

* Update the installation of `iodata` in tox.ini

* Add MacOS testing runner

* Update configurations of website building and pytest

* Rename yaml file for building website

* Use `iodata` as an optional dependency

* Set `iodata` an optional dependency

* Use actions-gh-pages v4.0.0

* Update the PyPI release YAML file

* Update the GitHub Action workflow name

* Support actual PyPI release

* Update the badges in README.md
  • Loading branch information
FanwangM authored Oct 1, 2024
1 parent ef1574a commit 83809c2
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ on:
push:
branches:
- master
- main
- website

pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
- master
# If your git repository has the Jupyter Book within some-subfolder next to
# unrelated files, you can make this run only if a file within that specific
# folder has been modified.
#
#paths:
#- book/
# paths:
# - book/

# This job installs dependencies, builds the book, and pushes it to `gh-pages`
jobs:
Expand All @@ -32,7 +34,7 @@ jobs:

# Install dependencies
- name: Set up Python 3.11
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.11

Expand Down Expand Up @@ -65,8 +67,8 @@ jobs:
# inspired by https://github.com/orgs/community/discussions/26724
# only push to gh-pages if the master branch has been updated
- name: GitHub Pages Action
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/_build/html
Expand Down
134 changes: 134 additions & 0 deletions .github/workflows/pypi_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# This workflow is adapted from:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# Changes made:
# - Removed emoticons
# - Updated some actions to more recent versions
# - Customized for the qc-gbasis repository

name: PyPI Release
on:
push:
tags:
# Trigger on version tags (e.g., v1.0.0)
- "v[0-9].[0-9].[0-9]*"
- "[0-9].[0-9].[0-9]*"
# Trigger on pre-release tags (e.g., v1.0.0-alpha.1)
- "v[0-9].[0-9].[0-9]*-*"
- "[0-9].[0-9].[0-9]*-*"

env:
# The name of the package to be published to PyPI and TestPyPI.
PYPI_NAME: qc-gbasis

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pypa/build
run: >-
python -m pip install build
- name: Build package
run: >-
python -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish Python distribution to PyPI
# only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/${{ env.PYPI_NAME }}
permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

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
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
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 }}
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python distribution to TestPyPI
if: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'theochem' }}
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/project/${{ env.PYPI_NAME }}

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
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/
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
# Need editable mode in order to include the test files
pip install -e .[dev,iodata]
- name: Install Libcint library
- name: Install Libcint library in Ubuntu
if: ${{ matrix.os != 'windows-latest' }}
run: |
echo "${{ matrix.os }}"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# GBasis

[![pytest](https://github.com/theochem/gbasis/actions/workflows/pytest.yaml/badge.svg)](https://github.com/theochem/gbasis/actions/workflows/pytest.yaml)
[![This project supports Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://python.org/downloads)
[![pytest](https://github.com/theochem/gbasis/actions/workflows/pytest.yaml/badge.svg?branch=master)](https://github.com/theochem/gbasis/actions/workflows/pytest.yaml)
[![codecov](https://codecov.io/gh/theochem/gbasis/graph/badge.svg?token=QPUfAWj7vf)](https://codecov.io/gh/theochem/gbasis)
[![PyPI](https://img.shields.io/pypi/v/qc-gbasis.svg)](https://pypi.python.org/pypi/qc-gbasis/)
![Version](https://img.shields.io/pypi/pyversions/qc-gbasis.svg)
![License](https://img.shields.io/github/license/theochem/gbasis)
<!-- [![release](https://github.com/theochem/gbasis/actions/workflows/release.yaml/badge.svg)](https://github.com/theochem/gbasis/actions/workflows/release.yaml) -->
<!-- [![CodeFactor](https://www.codefactor.io/repository/github/tovrstra/stepup-core/badge)](https://www.codefactor.io/repository/github/tovrstra/stepup-core) -->
[![documentation](https://github.com/theochem/gbasis/actions/workflows/build_website.yaml/badge.svg?branch=master)](https://github.com/theochem/gbasis/actions/workflows/build_website.yaml)

## About

Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ doc = [
"docutils==0.16", # Needed to show bullet points in sphinx_rtd_theme
"nbsphinx-link"
]
# iodata = [
# "qc-iodata@git+https://github.com/theochem/iodata.git@main"
# ]
iodata = [
"qc-iodata@git+https://github.com/theochem/iodata.git@main"
"qc-iodata>=1.0.0a5"
]
pyscf = [
"pyscf>=1.6.1"
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ deps =
{[testenv]deps}
Cython # dependency of iodata
commands =
pip install git+https://github.com/theochem/iodata.git@master
# pip install git+https://github.com/theochem/iodata.git@main
pip install qc-iodata
coverage run --rcfile=tox.ini -m pytest tests/test_wrappers.py
ignore_errors = true

Expand Down

0 comments on commit 83809c2

Please sign in to comment.