mirror of
https://github.com/SideStore/SideStore.git
synced 2026-03-28 05:15:41 +01:00
Compare commits
3 Commits
3961688b73
...
85ff9b09ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85ff9b09ca | ||
|
|
4100e8b1b9 | ||
|
|
42fae569ca |
@@ -60,6 +60,7 @@ def short_commit():
|
|||||||
# ----------------------------------------------------------
|
# ----------------------------------------------------------
|
||||||
# BUILD NUMBER RESERVATION
|
# BUILD NUMBER RESERVATION
|
||||||
# ----------------------------------------------------------
|
# ----------------------------------------------------------
|
||||||
|
|
||||||
def reserve_build_number(repo, max_attempts=5):
|
def reserve_build_number(repo, max_attempts=5):
|
||||||
repo = Path(repo).resolve()
|
repo = Path(repo).resolve()
|
||||||
version_json = repo / "version.json"
|
version_json = repo / "version.json"
|
||||||
@@ -67,14 +68,9 @@ def reserve_build_number(repo, max_attempts=5):
|
|||||||
def utc_now():
|
def utc_now():
|
||||||
return datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
|
return datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
def current_branch():
|
def read():
|
||||||
return runAndGet("git rev-parse --abbrev-ref HEAD", cwd=repo)
|
branch = runAndGet("git rev-parse --abbrev-ref HEAD", cwd=repo)
|
||||||
|
|
||||||
def sync_with_remote(branch):
|
|
||||||
run(f"git fetch --depth=1 origin {branch}", check=False, cwd=repo)
|
|
||||||
run(f"git reset --hard origin/{branch}", check=False, cwd=repo)
|
|
||||||
|
|
||||||
def read(branch):
|
|
||||||
defaults = {
|
defaults = {
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"issued_at": utc_now(),
|
"issued_at": utc_now(),
|
||||||
@@ -86,10 +82,13 @@ def reserve_build_number(repo, max_attempts=5):
|
|||||||
else:
|
else:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
|
# fill missing fields
|
||||||
for k, v in defaults.items():
|
for k, v in defaults.items():
|
||||||
data.setdefault(k, v)
|
data.setdefault(k, v)
|
||||||
|
|
||||||
|
# ensure tag always tracks current branch
|
||||||
data["tag"] = branch
|
data["tag"] = branch
|
||||||
|
|
||||||
version_json.write_text(json.dumps(data, indent=2) + "\n")
|
version_json.write_text(json.dumps(data, indent=2) + "\n")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -97,23 +96,19 @@ def reserve_build_number(repo, max_attempts=5):
|
|||||||
version_json.write_text(json.dumps(data, indent=2) + "\n")
|
version_json.write_text(json.dumps(data, indent=2) + "\n")
|
||||||
|
|
||||||
for attempt in range(max_attempts):
|
for attempt in range(max_attempts):
|
||||||
branch = current_branch()
|
run("git fetch --depth=1 origin HEAD", check=False, cwd=repo)
|
||||||
sync_with_remote(branch)
|
run("git reset --hard FETCH_HEAD", check=False, cwd=repo)
|
||||||
|
|
||||||
data = read(branch)
|
data = read()
|
||||||
data["build"] += 1
|
data["build"] += 1
|
||||||
data["issued_at"] = utc_now()
|
data["issued_at"] = utc_now()
|
||||||
|
|
||||||
write(data)
|
write(data)
|
||||||
|
|
||||||
run("git add version.json", check=False, cwd=repo)
|
run("git add version.json", check=False, cwd=repo)
|
||||||
run(
|
run(f"git commit -m '{data['tag']} - build no: {data['build']}' || true", check=False, cwd=repo)
|
||||||
f"git commit -m '{branch} - build no: {data['build']}' || true",
|
|
||||||
check=False,
|
|
||||||
cwd=repo,
|
|
||||||
)
|
|
||||||
|
|
||||||
rc = subprocess.call(f"git push origin {branch}", shell=True, cwd=repo)
|
rc = subprocess.call("git push", shell=True, cwd=repo)
|
||||||
|
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
print(f"Reserved build #{data['build']}", file=sys.stderr)
|
print(f"Reserved build #{data['build']}", file=sys.stderr)
|
||||||
@@ -533,5 +528,6 @@ def main():
|
|||||||
sys.stdout.write(str(result))
|
sys.stdout.write(str(result))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user