Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : MacLustr Storage Node8# File : Scripts/testflight.py9# Description : TestFlight follow-up after Scripts/release.sh upload:10# reports build processing; with --apply, makes sure an11# internal group exists, receives the build, and has the12# account holder as tester. Touches only the app13# ai.spboucher.maclustr.storage. Prints no secret.14# Module : Scripts15# Repository : https://git.spboucher.ai/maclustr-storage-ios16# Project Website : https://storage.spboucher.ai17# Created : 2026-12-0118# Last Modified : 2026-12-0119#20# Author : Simon-Pierre Boucher21# Position : Professor of Finance22# Institution : Université du Québec en Outaouais (UQO)23# Organization : SP Boucher24# Website : https://spboucher.ai25# Git : https://git.spboucher.ai26#27# Preferred Contact: admin@spboucher.ai28# Technical Contact: dev@spboucher.ai29# Security/Admin : admin@spboucher.ai30#31# Copyright (c) 202632# Simon-Pierre Boucher33# All rights reserved where applicable. This file is governed by the34# applicable project license, copyright notices and relevant law.35# Existing third-party rights and notices remain unaffected.36#37# License : None specified (no license file in this repository)38#39# Do not embed credentials, private keys, access tokens,40# certificates or confidential personal information.41#42# =============================================================================43# END OF SP BOUCHER SOURCE HEADER44# =============================================================================4546import os, sys47sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))48import asc4950BUNDLE = "ai.spboucher.maclustr.storage"51apply = "--apply" in sys.argv5253def get(path):54 status, data = asc.call("GET", path)55 if status != 200: sys.exit(f"GET {path} -> {status} {str(data)[:300]}")56 return data5758def app_id(bundle):59 d = get(f"/v1/apps?filter[bundleId]={bundle}")["data"]60 return next((a["id"] for a in d if a["attributes"]["bundleId"] == bundle), None)6162app = app_id(BUNDLE)63if not app: sys.exit("app record not found")64builds = get(f"/v1/builds?filter[app]={app}&sort=-uploadedDate&limit=5")["data"]65for b in builds:66 a = b["attributes"]67 print(f"build {a['version']} {a['processingState']} uploaded {a['uploadedDate']} encryption declared: {a.get('usesNonExemptEncryption')}")68if not builds: print("no build visible yet (still being received by Apple)")6970groups = get(f"/v1/apps/{app}/betaGroups")["data"]71internal = next((g for g in groups if g["attributes"].get("isInternalGroup")), None)72print("internal group:", internal["attributes"]["name"] if internal else "none")73if not apply: sys.exit(0)7475if not internal:76 status, data = asc.call("POST", "/v1/betaGroups", {"data": {"type": "betaGroups", "attributes": {"name": "Test", "isInternalGroup": True, "hasAccessToAllBuilds": True},77 "relationships": {"app": {"data": {"type": "apps", "id": app}}}}})78 if status != 201: sys.exit(f"create group -> {status} {str(data)[:300]}")79 internal = data["data"]; print("created internal group Test")80gid = internal["id"]8182# The account holder becomes a tester of the internal group (the address comes from App Store Connect itself and goes nowhere else).83testers = get(f"/v1/betaGroups/{gid}/betaTesters?limit=50")["data"]84emails = {(t["attributes"].get("email") or "").lower() for t in testers}85for u in get("/v1/users?limit=200")["data"]:86 ua = u["attributes"]87 if "ACCOUNT_HOLDER" not in (ua.get("roles") or []): continue88 if (ua.get("username") or "").lower() in emails: print("account holder already a tester of the internal group"); continue89 status, data = asc.call("POST", "/v1/betaTesters", {"data": {"type": "betaTesters", "attributes": {"email": ua.get("username"), "firstName": ua.get("firstName"), "lastName": ua.get("lastName")},90 "relationships": {"betaGroups": {"data": [{"type": "betaGroups", "id": gid}]}}}})91 print("account holder added to the internal group:", status)9293valid = [b for b in builds if b["attributes"]["processingState"] == "VALID"]94if valid and not internal["attributes"].get("hasAccessToAllBuilds"):95 status, data = asc.call("POST", f"/v1/betaGroups/{gid}/relationships/builds", {"data": [{"type": "builds", "id": b["id"]} for b in valid]})96 print(f"added {len(valid)} build(s) to the group: {status}")97elif valid: print("the group receives every build automatically")98else: print("no VALID build yet: run again when processing is finished")99