forked from LawnchairLauncher/lawnicons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_previous_release.py
More file actions
62 lines (51 loc) · 2.32 KB
/
generate_previous_release.py
File metadata and controls
62 lines (51 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2025 Lawnchair Launcher
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import subprocess
# Config options
OUTPUT_DIRECTORY = "app/assets/"
OUTPUT_FILE = "appfilter_previous.xml"
CUSTOM_GIT_TAG = ""
def run_git_command(args):
command = ["git"] + args
try:
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
check=True)
print(f"Task `git {' '.join(args)}` completed")
return process.stdout.strip().splitlines()
except subprocess.CalledProcessError as e:
print(f"Failed to execute {' '.join(command)}: {e.stderr.strip()}")
return []
def write_previous_release(previous_app_filter_file, custom_tag=""):
run_git_command(["fetch", "--tags"]) # Fetch tags
tags_output = run_git_command(["tag", "--sort=-creatordate"])
latest_tag = custom_tag or next((tag for tag in tags_output if tag != "nightly"), None)
if not latest_tag:
print("No suitable tag found, falling back to main branch.")
lines = run_git_command(["show", "main:app/assets/appfilter.xml"])
if not lines:
raise RuntimeError("No tags found and could not retrieve from main.")
else:
lines = run_git_command(["show", f"{latest_tag}:app/assets/appfilter.xml"])
if lines:
try:
with open(previous_app_filter_file, "w") as f:
f.write("\n".join(lines))
print(f"Successfully wrote previous release appfilter to {previous_app_filter_file}")
except IOError as e:
print(f"Error writing to file {previous_app_filter_file}: {e}")
if __name__ == '__main__':
path = os.path.join(OUTPUT_DIRECTORY, OUTPUT_FILE)
print(f"Attempting to write previous release appfilter to: {path}")
write_previous_release(path, CUSTOM_GIT_TAG)