Skip to content

Commit

Permalink
Add release info JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Feb 14, 2024
1 parent dda16b5 commit 9a6d8bc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

make html
make clean html
rsync -avPh --delete build/html/ novelwriter.io:www/
21 changes: 21 additions & 0 deletions source/_extra/release-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"release": {
"version": "2.2.1",
"major": 2,
"minor": 2,
"patch": 1,
"info": {
"name": "Version 2.2.1",
"date": "2024-01-27T15:41:44Z",
"url": "https://github.com/vkbo/novelWriter/releases/tag/v2.2.1",
"assets": {
"appimage": "https://github.com/vkbo/novelWriter/releases/download/v2.2.1/novelWriter-2.2.1.AppImage",
"debian": "https://github.com/vkbo/novelWriter/releases/download/v2.2.1/novelwriter_2.2.1_all.deb",
"winexe": "https://github.com/vkbo/novelWriter/releases/download/v2.2.1/novelwriter-2.2.1-amd64-setup.exe",
"macdmg": "https://github.com/vkbo/novelWriter/releases/download/v2.2.1/novelWriter-2.2.1.dmg",
"zipball": "https://api.github.com/repos/vkbo/novelWriter/zipball/v2.2.1",
"tarball": "https://api.github.com/repos/vkbo/novelWriter/tarball/v2.2.1"
}
}
}
}
53 changes: 52 additions & 1 deletion update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
from tools import DownloadAssets, Documentation, AssetType


def updateSetting(name, value):
def hexToInt(value: str, default: int = 0) -> int:
"""Convert a hex string to an integer."""
if isinstance(value, str):
try:
return int(value, 16)
except Exception:
return default
return default


def updateSetting(name: str, value: str) -> None:
"""Update a setting in the settings.json file."""
setFile = Path("source/settings.json")
if setFile.exists():
Expand All @@ -30,6 +40,31 @@ def updateSetting(name, value):
return


def writeReleaseInfo(version: str, force: bool, info: dict[str, str]) -> None:
"""Write the release info file."""
relFile = Path("source/_extra/release-latest.json")
current = json.loads(relFile.read_text(encoding="utf-8")) if relFile.exists() else {}
release = current.get("release", {})
numeric = tuple(int(x) for x in f"{version}.0.0.0".split(".")[:3])
previous = (release.get("major", 0), release.get("minor", 0), release.get("patch", 0))
if previous > numeric and not force:
print(("Current release info is for %s, not updating. "
"Use --force to override.") % release.get("version", "0"))
return
relFile.write_text(
json.dumps({
"release": {
"version": version,
"major": numeric[0],
"minor": numeric[1],
"patch": numeric[2],
"info": info,
}
}, indent=2), encoding="utf-8"
)
return


def processReleaseNotes(text):
"""Format the release notes text."""
def ghLinks(x):
Expand Down Expand Up @@ -174,6 +209,21 @@ def pullRelease(args):
})

else:
# Write the release-info.json file
writeReleaseInfo(shortVersion, args.force, {
"name": releaseVersion,
"date": releaseDate,
"url": releaseUrl,
"assets": {
"appimage": aAppImg.assetUrl,
"debian": aDebian.assetUrl,
"winexe": aWinExe.assetUrl,
"macdmg": aMacDmg.assetUrl,
"zipball": zipBall,
"tarball": tarBall,
}
})

# Updating Latest Release Info
buildFromTemplate("download_block.rst", "download_block.rst", {
"release_version": releaseVersion,
Expand Down Expand Up @@ -242,6 +292,7 @@ def buildFromTemplate(name, output, data):
pRelease = subParsers.add_parser("release", help="Update release")
pRelease.add_argument("--tag", type=str, help="Pull release info from a specific tag")
pRelease.add_argument("--remove-pre", action="store_true", help="Remove pre release")
pRelease.add_argument("--force", action="store_true", help="Force update of release info")
pRelease.set_defaults(func=pullRelease)

args = parser.parse_args()
Expand Down

0 comments on commit 9a6d8bc

Please sign in to comment.