Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start package publishing workflow #32

Merged
merged 7 commits into from
Feb 19, 2024
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
3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "10:00"
interval: weekly
allow:
- dependency-type: direct
- dependency-type: indirect
136 changes: 136 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

# yamllint disable-line rule:truthy
on:
push:
# Attempt to run on all pushes.
# branches:
# - main
# tags:
# - v*

# For now always take the "reduced" form of the version, even for those
# actions runs that do not push to a package index.
env:
VERSIONINGIT_FOR_PACKAGE_INDEX: true

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

steps:
- uses: actions/checkout@v4
with:
# so versioningit can figure out the version
fetch-depth: 0
fetch-tags: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: |
python3 -m pip install -U pip setuptools
python3 -m pip install build
- 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/

# publish-to-pypi:
# name: >-
# Publish Python 🐍 distribution 📦 to PyPI
# # only publish to PyPI on tag pushes
# if: startsWith(github.ref, 'refs/tags/v')
# needs:
# - build
# runs-on: ubuntu-latest
# environment:
# name: pypi
# url: https://pypi.org/p/pyresponse
# permissions:
# id-token: write # IMPORTANT: mandatory for trusted publishing

# 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

# 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/gh-action-sigstore-python@v1.2.3
# 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 }}'

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

# publish on merge to default branch or any tag
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')

environment:
name: testpypi
url: https://test.pypi.org/p/pyresponse

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

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/
13 changes: 6 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ name: test
# yamllint disable-line rule:truthy
on:
push:
branches:
- "master"
- "main"
pull_request:
branches:
- "master"
- "main"

jobs:
test:
Expand All @@ -24,6 +17,10 @@ jobs:
shell: "bash -l {0}"
steps:
- uses: actions/checkout@v4
with:
# so versioningit can figure out the version
fetch-depth: 0
fetch-tags: true
- name: Set up Python ${{ matrix.python-version }} with conda
uses: conda-incubator/setup-miniconda@v3
with:
Expand All @@ -36,6 +33,8 @@ jobs:
show-channel-urls: true
- name: Print Python environment
run: python -m pip list
- name: Update installation infrastructure
run: python -m pip install -U setuptools pip
- name: Print conda environment
run: conda list
- name: Print conda info
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

_version.py
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ section-order = ["future", "standard-library", "attrs", "third-party", "chemistr
"attrs" = ["attr"]
"chemistry" = ["psi4", "pyscf"]

[tool.versioningit]
default-version = "1+unknown"

[tool.versioningit.format]
distance = "{base_version}+{distance}.{vcs}{rev}"
dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
method = { module = "versioningit_override", value = "my_format", module-dir = "pyresponse" }

[tool.versioningit.template-fields.version-tuple]
pep440 = true

[tool.versioningit.vcs]
method = "git"
Expand Down
35 changes: 35 additions & 0 deletions pyresponse/versioningit_override.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from os import getenv
from typing import Any, Dict

from versioningit import VCSDescription
from versioningit.basics import DEFAULT_FORMATS

_ENVVARNAME = "VERSIONINGIT_FOR_PACKAGE_INDEX"


def my_format(
*, description: VCSDescription, base_version: str, next_version: str, params: Dict[str, Any]
) -> str:
state = description.state
assert state in {"distance", "dirty", "distance-dirty"}

if getenv(_ENVVARNAME, "False").lower() in ("true", "1", "t"):
fmt_distance = "{base_version}.post{distance}"
if state != "distance":
raise RuntimeError("dirty state doesn't make sense when building for a package index")
else:
# Default but missing {vcs} before {rev}
fmt_distance = "{base_version}.post{distance}+{rev}"
# Default
fmt_dirty = DEFAULT_FORMATS["dirty"]
# Default but missing {vcs} before {rev}
fmt_distance_dirty = "{base_version}.post{distance}+{rev}.d{build_date:%Y%m%d}"

if state == "distance":
fmt = fmt_distance
elif state == "dirty":
fmt = fmt_dirty
elif state == "distance-dirty":
fmt = fmt_distance_dirty

return fmt.format_map({**description.fields, "base_version": base_version})
Loading