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

ci: remove code.json, update scripts, fix release workflow #190

Merged
merged 3 commits into from
Jun 17, 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
16 changes: 12 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ jobs:
pip install .
pip install ".[lint, test]"

- name: Make code.md
run: make-code-json
- name: Make metadata files
uses: nick-fields/retry@v3
with:
timeout_seconds: 10
max_attempts: 3
command: make-code-json

- name: Upload code.md
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -68,12 +72,16 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
run: |
ver="${{ steps.version.outputs.version }}"

# remove metadata files
rm code.json
rm code.md

# commit and push changes
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 pymake
git add -A
git commit -m "ci(release): set version to ${{ steps.version.outputs.version }}"
git push origin "${{ github.ref_name }}"

Expand Down Expand Up @@ -118,7 +126,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
version=$(python scripts/update_version.py -g)
version=$(cat version.txt)
title="pymake $version"
notes=$(cat code.md)
gh release create "$version" \
Expand Down
233 changes: 0 additions & 233 deletions code.json

This file was deleted.

48 changes: 9 additions & 39 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import json
import re
import textwrap
from datetime import datetime
Expand All @@ -8,14 +7,20 @@
from filelock import FileLock
from packaging.version import Version

_epilog = """\
Update version information stored in version.txt in the project root
and other files in the repository. If --version is not provided, the
version number will not be changed. The version tag must comply with
'<major>.<minor>.<patch>' format convention for semantic versioning.
To show the version without changing anything, use --get (short -g).
"""
_project_name = "mfpymake"
_project_root_path = Path(__file__).parent.parent
_version_txt_path = _project_root_path / "version.txt"
_version_py_path = _project_root_path / "pymake" / "config.py"

# file names and the path to the file relative to the repo root directory
file_paths_list = [
_project_root_path / "code.json",
_project_root_path / "README.md",
_project_root_path / "version.txt",
_project_root_path / "pymake" / "config.py",
Expand All @@ -28,7 +33,6 @@ def split_nonnumeric(s):
return [s[: match.start()], s[match.start() :]] if match else s


_initial_version = Version("0.0.1")
_current_version = Version(_version_txt_path.read_text().strip())


Expand Down Expand Up @@ -93,28 +97,6 @@ def update_readme_markdown(version: Version) -> None:
print(f"Updated {fpth} to version {version}")


def update_codejson(version: Version) -> None:
"""Update code.json

Parameters
----------
version : Version
version number
"""
# define json filename
json_fname = file_paths["code.json"]

# load and modify json file
data = json.loads(json_fname.read_text())

# rewrite the json file
with open(json_fname, "w", encoding="utf8") as f:
json.dump(data, f, indent=4)
f.write("\n")

print(f"Updated {json_fname} to version {version}")


def update_version(
timestamp: datetime = datetime.now(),
version: Version = None,
Expand Down Expand Up @@ -143,7 +125,6 @@ def update_version(
update_version_txt(version)
update_version_py(timestamp, version)
update_readme_markdown(version)
update_codejson(version)
finally:
try:
lock_path.unlink()
Expand All @@ -155,16 +136,7 @@ def update_version(
parser = argparse.ArgumentParser(
prog=f"Update {_project_name} version",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=textwrap.dedent(
"""\
Update version information stored in version.txt in the project
root, as well as several other files in the repository. If
--version is not provided, the version number will not be
changed. A file lock is held to synchronize file access. The
version tag must comply with standard '<major>.<minor>.<patch>'
format conventions for semantic versioning.
"""
),
epilog=textwrap.dedent(_epilog),
)
parser.add_argument(
"-v",
Expand All @@ -183,9 +155,7 @@ def update_version(
args = parser.parse_args()

if args.get:
print(
Version((_project_root_path / "version.txt").read_text().strip())
)
print(_current_version)
else:
update_version(
timestamp=datetime.now(),
Expand Down
Loading