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
14 changes: 14 additions & 0 deletions .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ jobs:
steps:
- name: "Check out the repo"
uses: "actions/checkout@v7"
with:
fetch-depth: 0

- name: "Check git tags"
run: |
git fetch --tags
git describe --tags --always

- name: "Set up Python"
uses: "actions/setup-python@v6"
Expand Down Expand Up @@ -109,6 +116,13 @@ jobs:

steps:
- uses: "actions/checkout@v7"
with:
fetch-depth: 0

- name: "Check git tags"
run: |
git fetch --tags
git describe --tags --always

- name: "Set up Python"
uses: "actions/setup-python@v6"
Expand Down
58 changes: 25 additions & 33 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
tags:
# Matches any tags; tags are only used for versioning in this project.
- '*'
- '!*dev*'
workflow_dispatch:

jobs:
Expand All @@ -17,44 +18,35 @@ jobs:
name: Build tests
uses: ./.github/workflows/build_tests.yml

deploy:
build:
name: Build package
needs: [source_test, build_test]
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v2
with:
python-version: '3.12'
save_artifacts: true
upload_to_pypi: false # never let this workflow attempt the upload itself

upload:
name: Upload to PyPI
if: ${{ github.event_name != 'workflow_dispatch' }}
needs: [build]
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/project/astrodata/

permissions:
# This permission is required for trusted publishing.
id-token: write
contents: read
id-token: write # required for trusted publishing

steps:
- uses: actions/checkout@v7

- name: Set up Python 3.10
uses: actions/setup-python@v6
- name: Download built dists
uses: actions/download-artifact@v7
with:
python-version: '3.10'
merge-multiple: true
pattern: dist-*
path: dist

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false

- name: Update version (kept at 0.0.0) in pyproject.toml and build
if: ${{ github.event_name != 'workflow_dispatch' }}
run: |
poetry version ${{ github.ref_name }}
poetry version
poetry build

- name: Mint token
if: ${{ github.event_name != 'workflow_dispatch' }}
id: mint
uses: tschm/[email protected]

- name: Publish the package with poetry
# Allow workflow dispatch to trigger this job, but don't allow it
# to publish the package to PyPI.
if: ${{ github.event_name != 'workflow_dispatch' }}
run: |
echo "PUBLISHING!!!! ✨🚀"
poetry publish -u __token__ -p '${{ steps.mint.outputs.api-token }}'
- name: Publish the package
uses: pypa/gh-action-pypi-publish@release/v1
33 changes: 22 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def conda_unit_tests(session: nox.Session) -> None:
session.run("pytest", *SessionVariables.unit_pytest_options, *pos_args)


def unit_test_build(session: nox.Session) -> None:
def unit_test_build(session: nox.Session, version: str) -> None:
"""Run the unit tests using the build version of the package.

This is meant to be called from the `build_tests` session.
Expand All @@ -687,7 +687,7 @@ def unit_test_build(session: nox.Session) -> None:
"localhost",
"--index-url",
session.env["PIP_INDEX_URL"],
"astrodata==0.0.0",
f"astrodata=={version}",
)

# Positional arguments after -- are passed to pytest.
Expand All @@ -697,7 +697,7 @@ def unit_test_build(session: nox.Session) -> None:
session.run("pytest", *SessionVariables.unit_pytest_options, *pos_args)


def integration_test_build(session: nox.Session) -> None:
def integration_test_build(session: nox.Session, version: str) -> None:
"""Run the integration tests using the build version of the package.

This is meant to be called from the `build_tests` session.
Expand Down Expand Up @@ -730,7 +730,7 @@ def integration_test_build(session: nox.Session) -> None:
"localhost",
"--index-url",
session.env["PIP_INDEX_URL"],
"astrodata==0.0.0",
f"astrodata=={version}",
)

# Positional arguments after -- are passed to pytest.
Expand Down Expand Up @@ -793,7 +793,7 @@ def wrapper(session, *args, **kwargs):
return wrapper


def build_and_publish_to_devpi(session: nox.Session):
def build_and_publish_to_devpi(session: nox.Session) -> str:
"""Build the astrodata package and publish it.

If the devpi server is not running, this will raise an error.
Expand All @@ -804,6 +804,9 @@ def build_and_publish_to_devpi(session: nox.Session):

session.run("poetry", "build", f"--output={tmp_build_dir}", external=True)

sdist = next(Path(tmp_build_dir).glob("astrodata-*.tar.gz"))
version = sdist.stem.removeprefix("astrodata-").removesuffix(".tar")

_DEBUG = False
if _DEBUG:
session.run(
Expand Down Expand Up @@ -845,6 +848,8 @@ def build_and_publish_to_devpi(session: nox.Session):
env=poetry_config_env_vars,
) # fmt: skip

return version


@nox.session(python=SessionVariables.python_versions, tags=["build_tests"])
@use_devpi_server
Expand All @@ -855,12 +860,12 @@ def build_tests_unit(session: nox.Session) -> None:
and run the tests using the build version of the package.
"""
apply_data_caching_environment_variable(session)
build_and_publish_to_devpi(session)
version = build_and_publish_to_devpi(session)

working_dir = Path(session.create_tmp())

with session.chdir(working_dir):
unit_test_build(session)
unit_test_build(session, version)


@nox.session(
Expand All @@ -877,12 +882,12 @@ def build_tests_integration(session):
and run the tests using the build version of the package.
"""
apply_data_caching_environment_variable(session)
build_and_publish_to_devpi(session)
version = build_and_publish_to_devpi(session)

working_dir = Path(session.create_tmp())

with session.chdir(working_dir):
integration_test_build(session)
integration_test_build(session, version)


@nox.session(python=SessionVariables.python_versions)
Expand All @@ -901,7 +906,7 @@ def script_tests(session: nox.Session) -> None:
def build_tests_scripts(session: nox.Session) -> None:
"""Run the script tests using the build version of the package."""
apply_data_caching_environment_variable(session)
build_and_publish_to_devpi(session)
version = build_and_publish_to_devpi(session)

# This debug block proved useful in debugging the devpi server.
_DEBUG = False
Expand Down Expand Up @@ -939,8 +944,14 @@ def build_tests_scripts(session: nox.Session) -> None:
"localhost",
"--index-url",
session.env["PIP_INDEX_URL"],
"astrodata==0.0.0",
f"astrodata=={version}",
)
if _DEBUG:
session.run(
"python",
"-c",
"import astrodata; print(astrodata.__version__)",
)

# Run the tests. Need to pass arguments to pytest.
test_dir = Path(__file__).parent / "tests" / "script_tests"
Expand Down
13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ authors = ["D. J. Teal <[email protected]>", "DRAGONS development team"]
license = "BSD3"
readme = "README.md"


[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "pep440"
# your tags are plain "1.2.3", not "v1.2.3", so drop the v from the pattern:
pattern = "^(?P<base>\\d+\\.\\d+\\.\\d+)(\\.?(?P<stage>[a-zA-Z]+)\\.?(?P<revision>\\d+)?)?"
fallback-version = "0.0.0.dev0"

[tool.poetry.urls]
"Homepage" = "https://github.com/GeminiDRSoftware/astrodata/"
"Documentation" = "https://geminidrsoftware.github.io/astrodata/"
Expand Down Expand Up @@ -62,8 +71,8 @@ devpi-server = "^6.14.0"
devpi-client = "^7.2.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[tool.pytest.ini_options]
testpaths = [
Expand Down
Loading