Skip to content

Commit

Permalink
ci: remove code.json, update scripts, fix release workflow (#190)
Browse files Browse the repository at this point in the history
Fixes for the release automation

* don't version `code.json`, just generate when needed (and update `update_version.py`)
* add retries for metadata file gen in `release.yml` (USGS endpoints are unreliable)
* fix autocommit/pr contents: `version.txt`, `pymake/config.py`, and `README.md`
  • Loading branch information
wpbonelli committed Jun 17, 2024
1 parent 006b6ba commit 9aaef25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 276 deletions.
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

0 comments on commit 9aaef25

Please sign in to comment.