Skip to content

Commit

Permalink
Add build target to update files with configured version
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Mar 27, 2023
1 parent 88ce1fe commit 5cf5180
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Stage
run: |
python3 build.py stage-web
sed -i -e "s/\"asset-info\":\(.*\?\)\/master\//\"asset-info\":\1\/v${{ env.ver }}\//" build/web/script/config.js
sed -i -e "s/^config\[\"asset-info\"\] = \(.*\?\)\/master\//config\[\"asset-info\"\] = \1\/v${{ env.ver }}\//" build/web/script/config.js
- name: Publish
uses: peaceiris/actions-gh-pages@v3
Expand Down
29 changes: 28 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# ****************************************************


import codecs, errno, math, os, shutil, subprocess, sys, time
import codecs, errno, math, os, re, shutil, subprocess, sys, time

from urllib.error import HTTPError
from zipfile import ZipFile
Expand Down Expand Up @@ -393,7 +393,33 @@ def clean(_dir, verbose=False):
return
print("no files to remove")

def updateVersion(_dir, verbose=False):
app_ver = getConfig("version")

print("\nchargen version {}".format(app_ver))

file_config_js = os.path.join(_dir, "script", "config.js")
contents = readFile(file_config_js)
changes = re.sub(
r"^config\[\"version\"\] = .*;$",
"config[\"version\"] = \"{}\";".format(app_ver),
contents, 1, re.M)
if changes != contents:
writeFile(file_config_js, changes)
if verbose:
print("updated file '{}'".format(file_config_js))

file_changelog = os.path.join(_dir, "doc", "changelog.txt")
contents = readFile(file_changelog)
changes = re.sub(r"^next$", app_ver, contents, 1, re.M)
if changes != contents:
writeFile(file_changelog, changes)
if verbose:
print("updated file '{}'".format(file_changelog))

def stageWeb(_dir, verbose=False):
targets.run("update-version", _dir, verbose)

print("\nstaging web files ...")

dir_web = os.path.join(_dir, "build", "web")
Expand Down Expand Up @@ -621,6 +647,7 @@ def printChanges(_dir, verbose=False):
print("\n".join(lines))

targets.add("clean", clean)
targets.add("update-version", updateVersion)
targets.add("stage-web", stageWeb)
targets.add("dist-web", distWeb)
targets.add("stage-desktop", stageDesktop)
Expand Down
9 changes: 4 additions & 5 deletions script/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"use strict";


export const config = {
"version": "0.2",
"git-repo": "https://github.com/AntumDeluge/chargen",
"asset-info": "https://github.com/AntumDeluge/chargen/blob/master/assets/README.md"
};
export const config = {};
config["version"] = "0.2";
config["git-repo"] = "https://github.com/AntumDeluge/chargen";
config["asset-info"] = config["git-repo"] + "/blob/master/assets/README.md"

0 comments on commit 5cf5180

Please sign in to comment.