Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
name: Build and publish package

on:
pull_request:
release:
# Only trigger on GitHub Releases - but include "pre-relesae" if that box is ticked
types:
- released
- prereleased

workflow_dispatch:
inputs:
source_branch:
description: "Branch containing the source code to publish"
required: true
type: string
version:
description: "Package version to publish (e.g. 0.15.1)"
required: true
type: string

# Deny permissions by default. Each job gets only what it needs.
permissions: {}

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

# We want to track the commit we use to build, so we use the same commit to test
outputs:
source_sha: ${{ steps.source.outputs.sha }}

permissions:
contents: read

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Grab the ref from the workflow dispatch if that method was used as the trigger, else use the ref that triggered the workflow
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/heads/{0}', inputs.source_branch) || github.ref }}
# Important for projects using setuptools-scm.
fetch-depth: 0
# We don't need the token for more git operations
persist-credentials: false

- name: Record source commit
id: source
run: |
sha=$(git rev-parse HEAD)
echo "sha=$sha" >> "$GITHUB_OUTPUT"
echo "Building from commit: $sha"

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
# Recommend using min python version supported
python-version: "3.12"

- name: Install build frontend
run: python -m pip install build

- name: Build distributions
shell: bash
env:
BACKFILL_VERSION: ${{ inputs.version }}
run: |
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
export SETUPTOOLS_SCM_PRETEND_VERSION="$BACKFILL_VERSION"
fi
python -m build

- name: Show distributions
run: ls -lh dist/

# archive: false means the wheel itself is stored directly rather
# than being wrapped in an additional GitHub artifact ZIP.
#
# This requires the glob to resolve to exactly one file.
- name: Upload wheel
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
path: dist/*.whl
archive: false
if-no-files-found: error

- name: Upload sdist
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
path: dist/*.tar.gz
archive: false
if-no-files-found: error

test-package:
name: Test built package
needs: build
runs-on: ubuntu-latest

permissions:
contents: read

steps:
# We need the checkout for the test suite, but we do NOT install
# the package from this checkout.
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.build.outputs.source_sha }}
fetch-depth: 1
persist-credentials: false

- name: Download wheel
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: "*.whl"
path: dist
merge-multiple: true

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.12"

- name: Install built wheel with test dependencies
shell: bash
run: |
shopt -s nullglob
wheels=(dist/*.whl)
if (( ${#wheels[@]} != 1 )); then
echo "Expected exactly one wheel, found ${#wheels[@]}"
exit 1
fi
python -m pip install "${wheels[0]}"
python -m pip install -r devtools/test-requirements.txt

- name: Verify installed wheel version
env:
PACKAGE: openforcefields
DISTRIBUTION: openff-forcefields
run: |
python -I - <<'PY'
import importlib
import os
from importlib.metadata import version

package = os.environ["PACKAGE"]
module = importlib.import_module(package)
installed_version = version(os.getenv("DISTRIBUTION", package))

print(f"Package path: {module.__file__}")
print(f"Module version: {module.__version__}")
print(f"Installed version: {installed_version}")

assert module.__version__ == installed_version
PY

- name: Run tests
# include discvery of all openforcefields/ when toolkit is added as a test dep
run: python -m pytest -n auto -v --color=yes --durations=10 openforcefields/tests/test_openforcefields.py

publish:
name: Publish to PyPI

# The publish job exists only for an actual GitHub Release.
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'

# We only publish if both building and testing the built artifact succeeded.
needs:
- build
- test-package

runs-on: ubuntu-latest

environment:
name: pypi

# This is the only job that can request an OIDC identity.
permissions:
id-token: write

steps:
- name: Download wheel
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: "*.whl"
path: dist
merge-multiple: true

- name: Download sdist
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: "*.tar.gz"
path: dist
merge-multiple: true

- name: Publish distributions to PyPI
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
5 changes: 5 additions & 0 deletions devtools/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packaging
pytest
pytest-cov
pytest-xdist
pandas
2 changes: 1 addition & 1 deletion openforcefields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

from openforcefields.openforcefields import get_forcefield_dirs_paths

__version__ = version("openforcefields")
__version__ = version("openff-forcefields")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = [
]

[project]
name = "openforcefields"
name = "openff-forcefields"
description = "Force fields released by the Open Force Field Initiative"
readme = { file = "README.md", content-type = "text/markdown" }
license = { text = "CC-BY-4.0" }
Expand Down
Loading