Skip to content
Open
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
72 changes: 72 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
name: Publish

on:
push:
branches:
- "main"
tags:
- "v*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
# hatch-vcs derives the version from the git tag, so the full
# history and tags must be available (default checkout is shallow).
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.x"
- name: Build sdist and wheel
run: |
python -m pip install --upgrade pip build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist
path: dist/

# Every push to main and every tag publishes to TestPyPI.
testpypi:
needs: build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/project/morgan/
permissions:
id-token: write # required for PyPI trusted publishing (OIDC)
steps:
- name: Download distributions
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: dist
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true # tolerate re-runs of an already-uploaded version

# Tags additionally publish to PyPI, gated on TestPyPI succeeding.
pypi:
needs: [build, testpypi]
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/morgan/
permissions:
id-token: write # required for PyPI trusted publishing (OIDC)
steps:
- name: Download distributions
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
1 change: 0 additions & 1 deletion morgan/__about__.py

This file was deleted.

13 changes: 12 additions & 1 deletion morgan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import os.path
import re
import sys
import tarfile
import traceback
import urllib.error
Expand All @@ -23,7 +24,6 @@
import packaging.version

from morgan import configurator, metadata, server
from morgan.__about__ import __version__
from morgan.registry import GitLabRegistry, LocalRegistry, Registry
from morgan.utils import (
Cache,
Expand All @@ -33,6 +33,17 @@
touch_file,
)

if sys.version_info < (3, 8):
import importlib_metadata as _metadata
else:
from importlib import metadata as _metadata

try:
__version__ = _metadata.version("morgan")
except _metadata.PackageNotFoundError:
# Running from a source tree that hasn't been installed.
__version__ = "0.0.0+unknown"

PYPI_ADDRESS = "https://pypi.org/simple/"
PREFERRED_HASH_ALG = "sha256"

Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling>=1.10.0"]
requires = ["hatchling>=1.10.0", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
Expand Down Expand Up @@ -49,7 +49,12 @@ lint = [
]

[tool.hatch.version]
path = "morgan/__about__.py"
# Version is derived from the latest git tag, e.g. "v0.15.0" -> "0.15.0".
source = "vcs"

[tool.hatch.version.raw-options]
# Drop the local "+<hash>" segment; (Test)PyPI rejects local version labels.
local_scheme = "no-local-version"

[project.urls]
"Homepage" = "https://github.com/ido50/morgan"
Expand Down