Skip to content

Commit

Permalink
Merge pull request #714 from kloptops/main
Browse files Browse the repository at this point in the history
Fixed tools/build_release.py to allow ports to be moved easily between repos.
  • Loading branch information
kloptops authored Oct 1, 2024
2 parents 022943d + 3a37ff9 commit 8b3d79e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
id: ports-info
run: |
touch .github_check
wget -O releases/port_stats_raw.json "https://raw.githubusercontent.com/PortsMaster/PortMaster-Info/refs/heads/main/port_stats_raw.json"
python3 tools/build_data.py
python3 tools/build_release.py --do-check
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ jobs:
id: ports-info
run: |
touch .github_check
wget -O releases/port_stats_raw.json "https://raw.githubusercontent.com/PortsMaster/PortMaster-Info/refs/heads/main/port_stats_raw.json"
tools/prepare_restore_port.sh
python3 tools/build_data.py
python3 tools/build_release.py "${{steps.date.outputs.date}}"
rm -fv releases/.gitignore
rm -fv releases/port_stats_raw.json
- name: "Prepare Release"
uses: ncipollo/release-action@v1
Expand Down
3 changes: 3 additions & 0 deletions SOURCE_SETUP.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ REPO_NAME="PortMaster New Repo."
# For example "xmpl"
REPO_PREFIX="pm"

SPLIT_IMAGES="Y"

## This is only required by PortMaster-New Repo.
## --DEPRECATED--
PMGUI_RELEASE="8.6.1_0556"
1 change: 1 addition & 0 deletions releases/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ports_status.json
manifest.json
ports.json
gameinfo_status.json
port_stats_raw.json
64 changes: 53 additions & 11 deletions tools/build_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@

ROOT_DIR = Path('.')

CACHE_FILE = ROOT_DIR / '.hash_cache'
RELEASE_DIR = ROOT_DIR / 'releases'
RUNTIMES_DIR = ROOT_DIR / 'runtimes'
MANIFEST_FILE = RELEASE_DIR / 'manifest.json'
STATUS_FILE = RELEASE_DIR / 'ports_status.json'
PORTS_DIR = ROOT_DIR / 'ports'
CACHE_FILE = ROOT_DIR / '.hash_cache'
RELEASE_DIR = ROOT_DIR / 'releases'
RUNTIMES_DIR = ROOT_DIR / 'runtimes'
MANIFEST_FILE = RELEASE_DIR / 'manifest.json'
STATUS_FILE = RELEASE_DIR / 'ports_status.json'
PORTS_DIR = ROOT_DIR / 'ports'
PORT_STAT_RAW_FILE = RELEASE_DIR / 'port_stats_raw.json'

SPLIT_IMAGES = True
SPLIT_IMAGES = False

GITHUB_RUN = (ROOT_DIR / '.github_check').is_file()
GITHUB_RUN = (ROOT_DIR / '.github_check').is_file()

LARGEST_FILE = (1024 * 1024 * 90)
LARGEST_FILE = (1024 * 1024 * 90)

#############################################################################
"""
Expand Down Expand Up @@ -115,6 +116,7 @@
'RELEASE_REPO': None,
'REPO_NAME': None,
'REPO_PREFIX': None,
'SPLIT_IMAGES': "N",
}

with open('SOURCE_SETUP.txt', 'r') as fh:
Expand Down Expand Up @@ -148,6 +150,45 @@
#############################################################################


PORT_STAT_RAW_DATA = None
def get_historial_added_date(port_name, default=None):
"""
Uses port_stats_raw.json to get a historial release date if it is not found.
This is used to keep info sane when moving ports between github repos.
"""
global PORT_STAT_RAW_DATA

if PORT_STAT_RAW_DATA is None:
if not PORT_STAT_RAW_FILE.is_file():
return default

try:
with PORT_STAT_RAW_FILE.open('r') as fh:
PORT_STAT_RAW_DATA = json.load(fh)

if not isinstance(PORT_STAT_RAW_DATA, dict):
return default

except json.decoder.JSONDecodeError as err:
printf(f"Unable to load {str(PORT_STAT_RAW_FILE)}: {err}")
PORT_STAT_RAW_DATA = None
return default

if port_name not in PORT_STAT_RAW_DATA.get('ports', {}):
print(f"- {port_name} --> {default} (DEFAULT)")
return default

for release_id in sorted(PORT_STAT_RAW_DATA.get('releases', [])):
if port_name in PORT_STAT_RAW_DATA.get('release_data', {}).get(release_id, []):
added_date = release_id.split('_', 1)[0]
print(f"- {port_name} --> {added_date}")
return added_date

print(f"- {port_name} --> {default} (DEFAULT)")
return default


def current_release_url(release_id):
if release_id == 'latest':
return f"https://github.com/{REPO_CONFIG['RELEASE_ORG']}/{REPO_CONFIG['RELEASE_REPO']}/releases/latest/download/"
Expand Down Expand Up @@ -251,7 +292,7 @@ def load_port(port_dir, manifest, registered, port_status, quick_build=False, ha
port_data['files'][port_file.name] = port_file_type

if port_data['name'] not in port_status:
port_date = TODAY
port_date = get_historial_added_date(port_data['name'], TODAY)
else:
port_date = port_status[port_data['name']]['date_added']

Expand Down Expand Up @@ -783,6 +824,7 @@ def port_info(file_name, ports_json, ports_status):
}

if clean_name not in ports_status:
default_status['date_added'] = get_historial_added_date(clean_name, TODAY)
ports_status[clean_name] = default_status

elif ports_status[clean_name]['md5'] != file_md5:
Expand Down Expand Up @@ -946,7 +988,7 @@ def generate_ports_json(all_ports, port_status, old_manifest, new_manifest):
)

## Jank :|
if SPLIT_IMAGES:
if REPO_CONFIG.get('SPLIT_IMAGES', "N") == "Y":
build_new_images_zip(old_manifest, new_manifest, port_status)

utils = []
Expand Down
1 change: 1 addition & 0 deletions tools/prepare_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ wget "https://github.com/${RELEASE_ORG}/${RELEASE_REPO}/releases/latest/download
wget "https://github.com/${RELEASE_ORG}/${RELEASE_REPO}/releases/latest/download/ports_status.json"
wget "https://github.com/${RELEASE_ORG}/${RELEASE_REPO}/releases/latest/download/manifest.json"
wget "https://github.com/${RELEASE_ORG}/${RELEASE_REPO}/releases/latest/download/images.zip"
wget "https://raw.githubusercontent.com/PortsMaster/PortMaster-Info/refs/heads/main/port_stats_raw.json"
cd ..

python3 tools/build_data.py

0 comments on commit 8b3d79e

Please sign in to comment.