diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 798e6a2..26e9a05 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -155,7 +155,7 @@ jobs: run: | version=$(python scripts/update_version.py -g) title="modflowapi $version" - notes=$(cat "changelog/CHANGELOG_$version.md" | grep -v "### Version $version") + notes=$(cat "changelog/CHANGELOG.md" | grep -v "### Version $version") gh release create "$version" \ --target main \ --title "$title" \ @@ -207,71 +207,3 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 - - reset: - name: Draft reset PR - if: ${{ github.event_name == 'release' }} - runs-on: ubuntu-22.04 - permissions: - contents: write - pull-requests: write - steps: - - - name: Checkout main branch - uses: actions/checkout@v3 - with: - ref: main - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: 3.8 - cache: 'pip' - cache-dependency-path: pyproject.toml - - - name: Install Python dependencies - run: | - pip install --upgrade pip - pip install . - pip install ".[lint, test]" - - - name: Get release tag - uses: oprypin/find-latest-tag@v1 - id: latest_tag - with: - repository: ${{ github.repository }} - releases-only: true - - - name: Draft pull request - env: - GITHUB_TOKEN: ${{ github.token }} - run: | - # create reset branch from main - reset_branch="post-release-${{ steps.latest_tag.outputs.tag }}-reset" - git switch -c $reset_branch - - # increment minor version - major_version=$(echo "${{ steps.latest_tag.outputs.tag }}" | cut -d. -f1) - minor_version=$(echo "${{ steps.latest_tag.outputs.tag }}" | cut -d. -f2) - patch_version=0 - version="$major_version.$((minor_version + 1)).$patch_version" - python scripts/update_version.py -v "$version" - - # format Python files - python scripts/pull_request_prepare.py - - # commit and push reset branch - git config core.sharedRepository true - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -A - git commit -m "ci(release): update to development version $version" - git push -u origin $reset_branch - - # create PR into develop - body=' - # Reinitialize for development - - Updates the `develop` branch from `main` following a successful release. Increments the minor version number. - ' - gh pr create -B "develop" -H "$reset_branch" --title "Reinitialize develop branch" --draft --body "$body" \ No newline at end of file diff --git a/CITATION.cff b/CITATION.cff index ccd7d09..21bd4a0 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,7 +3,7 @@ message: If you use this software, please cite both the article from preferred-c and the software itself. type: software title: MODFLOW API -version: 0.2.0 +version: 0.2.0.dev0 date-released: '2023-04-19' abstract: An extension to xmipy for the MODFLOW API. repository-artifact: https://pypi.org/project/modflowapi diff --git a/modflowapi/version.py b/modflowapi/version.py index be5ce0b..c16cb60 100644 --- a/modflowapi/version.py +++ b/modflowapi/version.py @@ -1,6 +1,3 @@ -# version file for modflowapi - -major = 0 -minor = 2 -micro = 0 -__version__ = f"{major}.{minor}.{micro}" +# modflowapi version file automatically created using...update_version.py +# created on...February 07, 2024 22:13:12 +__version__ = "0.2.0.dev0" diff --git a/scripts/update_version.py b/scripts/update_version.py index de8074b..efbf1ac 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -1,93 +1,51 @@ import argparse import textwrap from datetime import datetime -from enum import Enum -from os import PathLike +from os.path import basename from pathlib import Path -from typing import NamedTuple +from packaging.version import Version from filelock import FileLock _project_name = "modflowapi" _project_root_path = Path(__file__).parent.parent +_version_txt_path = _project_root_path / "version.txt" _version_py_path = _project_root_path / "modflowapi" / "version.py" _citation_cff_path = _project_root_path / "CITATION.cff" +_initial_version = Version("0.0.1") +_current_version = Version(_version_txt_path.read_text().strip()) -class Version(NamedTuple): - """Semantic version number""" - major: int = 0 - minor: int = 0 - patch: int = 0 +def log_update(path, version: Version): + print(f"Updated {path} with version {version}") - def __repr__(self): - return f"{self.major}.{self.minor}.{self.patch}" - @classmethod - def from_string(cls, version: str) -> "Version": - t = version.split(".") - - vmajor = int(t[0]) - vminor = int(t[1]) - vpatch = int(t[2]) - - return cls(major=vmajor, minor=vminor, patch=vpatch) - - @classmethod - def from_file(cls, path: PathLike) -> "Version": - lines = [ - line.rstrip("\n") - for line in open(Path(path).expanduser().absolute(), "r") - ] - vmajor = vminor = vpatch = None - for line in lines: - line = line.strip() - if not any(line): - continue - - def get_ver(l): - return l.split("=")[1] - - if "__version__" not in line: - if "major" in line: - vmajor = int(get_ver(line)) - elif "minor" in line: - vminor = int(get_ver(line)) - elif "patch" in line or "micro" in line: - vpatch = int(get_ver(line)) - - assert ( - vmajor is not None and vminor is not None and vpatch is not None - ), "version string must follow semantic version format: major.minor.patch" - return cls(major=vmajor, minor=vminor, patch=vpatch) - - -_initial_version = Version(0, 0, 1) -_current_version = Version.from_file(_version_py_path) +def update_version_txt(version: Version): + with open(_version_txt_path, "w") as f: + f.write(str(version)) + log_update(_version_txt_path, version) def update_version_py(timestamp: datetime, version: Version): with open(_version_py_path, "w") as f: f.write( - f"# {_project_name} version file automatically created using " - f"{Path(__file__).name} on {timestamp:%B %d, %Y %H:%M:%S}\n\n" + f"# {_project_name} version file automatically " + + f"created using...{basename(__file__)}\n" ) - f.write(f"major = {version.major}\n") - f.write(f"minor = {version.minor}\n") - f.write(f"micro = {version.patch}\n") - f.write("__version__ = f'{major}.{minor}.{micro}'\n") - print(f"Updated {_version_py_path} to version {version}") + f.write("# created on..." + f"{timestamp.strftime('%B %d, %Y %H:%M:%S')}\n") + f.write(f'__version__ = "{version}"\n') + log_update(_version_py_path, version) -def update_citation_cff(timestamp: datetime, version: Version): +def update_citation_cff(version: Version): lines = open(_citation_cff_path, "r").readlines() with open(_citation_cff_path, "w") as f: for line in lines: if line.startswith("version:"): line = f"version: {version}\n" f.write(line) - print(f"Updated {_citation_cff_path} to version {version}") + log_update(_citation_cff_path, version) def update_version( @@ -97,7 +55,7 @@ def update_version( lock_path = Path(_version_py_path.name + ".lock") try: lock = FileLock(lock_path) - previous = Version.from_file(_version_py_path) + previous = Version(_version_txt_path.read_text().strip()) version = ( version if version @@ -105,8 +63,9 @@ def update_version( ) with lock: + update_version_txt(version) update_version_py(timestamp, version) - update_citation_cff(timestamp, version) + update_citation_cff(version) finally: try: lock_path.unlink() @@ -148,7 +107,7 @@ def update_version( else: update_version( timestamp=datetime.now(), - version=Version.from_string(args.version) - if args.version - else _current_version, + version=( + Version(args.version) if args.version else _current_version + ), ) diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..9a058eb --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.2.0.dev0 \ No newline at end of file