From 9aaef2544925d868b51959aae15cbf2da3fce295 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 17 Jun 2024 17:19:20 -0400 Subject: [PATCH] ci: remove code.json, update scripts, fix release workflow (#190) 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` --- .github/workflows/release.yml | 16 ++- code.json | 233 ---------------------------------- scripts/update_version.py | 48 ++----- 3 files changed, 21 insertions(+), 276 deletions(-) delete mode 100644 code.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0884e47..9e71263 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 }}" @@ -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" \ diff --git a/code.json b/code.json deleted file mode 100644 index a49cc53..0000000 --- a/code.json +++ /dev/null @@ -1,233 +0,0 @@ -{ - "crt": { - "current": true, - "dirname": "CRT_1.3.1", - "double_switch": false, - "shared_object": false, - "srcdir": "SOURCE", - "standard_switch": true, - "url": "https://water.usgs.gov/ogw/CRT/CRT_1.3.1.zip", - "url_download_asset_date": "04/11/2017", - "version": "1.3.1" - }, - "gridgen": { - "current": true, - "dirname": "gridgen.1.0.02", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/GRIDGEN/gridgen.1.0.02.zip", - "url_download_asset_date": "10/24/2018", - "version": "1.0.02" - }, - "libmf6": { - "current": true, - "dirname": "mf6.5.0_linux", - "double_switch": false, - "shared_object": true, - "srcdir": "srcbmi", - "standard_switch": true, - "url": "https://github.com/MODFLOW-USGS/modflow6/releases/download/6.5.0/mf6.5.0_linux.zip", - "url_download_asset_date": "05/23/2024", - "version": "6.5.0" - }, - "mf2000": { - "current": true, - "dirname": "mf2k.1_19", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/nrp/gwsoftware/modflow2000/mf2k1_19_01.tar.gz", - "url_download_asset_date": "03/30/2010", - "version": "1.19.01" - }, - "mf2005": { - "current": true, - "dirname": "MF2005.1_12u", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://github.com/MODFLOW-USGS/mf2005/releases/download/v.1.12.00/MF2005.1_12u.zip", - "url_download_asset_date": "12/07/2021", - "version": "1.12.00" - }, - "mf6": { - "current": true, - "dirname": "mf6.5.0_linux", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://github.com/MODFLOW-USGS/modflow6/releases/download/6.5.0/mf6.5.0_linux.zip", - "url_download_asset_date": "05/23/2024", - "version": "6.5.0" - }, - "mflgr": { - "current": true, - "dirname": "mflgr.2_0", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip", - "url_download_asset_date": "09/20/2013", - "version": "2.0.0" - }, - "mfnwt": { - "current": true, - "dirname": "MODFLOW-NWT", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/MODFLOW-NWT/MODFLOW-NWT_1.3.0.zip", - "url_download_asset_date": "09/07/2022", - "version": "1.3.0" - }, - "mfusg": { - "current": true, - "dirname": "mfusg1_5", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/MODFLOW-USG/mfusg1_5.zip", - "url_download_asset_date": "02/27/2019", - "version": "1.5" - }, - "mfusg_gsi": { - "current": true, - "dirname": "USGT-v2-3-0-Source", - "double_switch": false, - "shared_object": false, - "srcdir": ".", - "standard_switch": true, - "url": "https://www.gsienv.com/wp-content/uploads/2024/03/USG-Transport_Version-2.3.0.zip", - "url_download_asset_date": null, - "version": "2.3.0" - }, - "mp6": { - "current": true, - "dirname": "modpath.6_0", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/MODPATH/modpath.6_0_01.zip", - "url_download_asset_date": "10/23/2018", - "version": "6.0.1" - }, - "mp7": { - "current": true, - "dirname": "modpath_7_2_001", - "double_switch": false, - "shared_object": false, - "srcdir": "source", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/MODPATH/modpath_7_2_001.zip", - "url_download_asset_date": "10/23/2018", - "version": "7.2.001" - }, - "mt3dms": { - "current": true, - "dirname": "mt3dms-2.0", - "double_switch": false, - "shared_object": false, - "srcdir": "true-binary", - "standard_switch": true, - "url": "https://github.com/MODFLOW-USGS/mt3dms/releases/download/2.0/mt3dms-2.0.zip", - "url_download_asset_date": "07/05/2023", - "version": "5.3.0" - }, - "mt3dusgs": { - "current": true, - "dirname": "mt3dusgs1.1.0", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/MT3D-USGS/mt3dusgs1.1.0.zip", - "url_download_asset_date": "07/12/2019", - "version": "1.1.0" - }, - "sutra": { - "current": true, - "dirname": "SutraSuite", - "double_switch": false, - "shared_object": false, - "srcdir": "SUTRA_3_0/source", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/sutra/SUTRA_3_0_0.zip", - "url_download_asset_date": "08/20/2019", - "version": "3.0" - }, - "swtv4": { - "current": true, - "dirname": "swt_v4_00_05", - "double_switch": true, - "shared_object": false, - "srcdir": "source", - "standard_switch": false, - "url": "https://water.usgs.gov/water-resources/software/SEAWAT/swt_v4_00_05.zip", - "url_download_asset_date": "10/24/2018", - "version": "4.00.05" - }, - "triangle": { - "current": true, - "dirname": "triangle-1.0", - "double_switch": false, - "shared_object": false, - "srcdir": "src", - "standard_switch": true, - "url": "https://github.com/MODFLOW-USGS/triangle/releases/download/1.0/triangle-1.0.zip", - "url_download_asset_date": "07/05/2023", - "version": "1.6" - }, - "vs2dt": { - "current": true, - "dirname": "vs2dt3_3", - "double_switch": false, - "shared_object": false, - "srcdir": "include", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/VS2DI/vs2dt3_3.zip", - "url_download_asset_date": "04/02/2018", - "version": "3.3" - }, - "zbud6": { - "current": true, - "dirname": "mf6.5.0_linux", - "double_switch": false, - "shared_object": false, - "srcdir": "utils/zonebudget/src", - "standard_switch": true, - "url": "https://github.com/MODFLOW-USGS/modflow6/releases/download/6.5.0/mf6.5.0_linux.zip", - "url_download_asset_date": "05/23/2024", - "version": "6.5.0" - }, - "zonbud3": { - "current": true, - "dirname": "Zonbud.3_01", - "double_switch": false, - "shared_object": false, - "srcdir": "Src", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/ZONEBUDGET/zonbud3_01.exe", - "url_download_asset_date": "10/25/2018", - "version": "3.01" - }, - "zonbudusg": { - "current": true, - "dirname": "mfusg1_5", - "double_switch": false, - "shared_object": false, - "srcdir": "src/zonebudusg", - "standard_switch": true, - "url": "https://water.usgs.gov/water-resources/software/MODFLOW-USG/mfusg1_5.zip", - "url_download_asset_date": "02/27/2019", - "version": "1.5" - } -} diff --git a/scripts/update_version.py b/scripts/update_version.py index b797417..0d051fa 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -1,5 +1,4 @@ import argparse -import json import re import textwrap from datetime import datetime @@ -8,6 +7,13 @@ 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 +'..' 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" @@ -15,7 +21,6 @@ # 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", @@ -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()) @@ -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, @@ -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() @@ -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 '..' - format conventions for semantic versioning. - """ - ), + epilog=textwrap.dedent(_epilog), ) parser.add_argument( "-v", @@ -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(),