Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : Lou-Ka iOS10# File : Scripts/asc.py11# Description : état d'un build sur App Store Connect et groupes de test,12# avec la clé d'équipe déjà présente sur ce Mac13# (~/.appstoreconnect/private_keys). Aucun secret dans le14# dépôt. Lecture seule, sauf « group », qui rattache un15# build au groupe interne ; rien n'est jamais soumis à une16# revue. usage : asc.py build [numéro] | wait [numéro] |17# group [numéro] | status [numéro]18# Module : Scripts19# Repository : https://git.spboucher.ai/lou-ka-ios-v320# Project Website : https://www.lou-ka.com21# Created : 2026-11-2822# Last Modified : 2026-11-3023#24# =============================================================================25# AUTHOR & PROFESSIONAL AFFILIATION26# =============================================================================27#28# Author : Simon-Pierre Boucher29# Position : Professor of Finance30# Institution : Université du Québec en Outaouais (UQO)31# Department : Département des sciences administratives32# Organization : SP Boucher33#34# Website : https://spboucher.ai35# Git : https://git.spboucher.ai36#37# =============================================================================38# OFFICIAL CONTACT DIRECTORY39# =============================================================================40#41# General : info@spboucher.ai42# Professional : contact@spboucher.ai43# Direct : simon@spboucher.ai44# Research : research@spboucher.ai45# Development : dev@spboucher.ai46# Support : support@spboucher.ai47# Security/Admin : admin@spboucher.ai48# Notifications : notifications@spboucher.ai49#50# Preferred Contact: support@spboucher.ai51#52# =============================================================================53# COPYRIGHT & INTELLECTUAL PROPERTY54# =============================================================================55#56# Copyright (c) 202657# Simon-Pierre Boucher58#59# All rights reserved where applicable.60#61# This file is governed by the applicable project license,62# copyright notices, institutional agreements and relevant law.63#64# Unless expressly authorized by the applicable license or65# rights holder, copying, redistribution, sublicensing,66# publication and commercial exploitation are not permitted.67#68# Existing third-party rights and notices remain unaffected.69#70# =============================================================================71# CONFIDENTIALITY & SECURITY72# =============================================================================73#74# Classification : Public75# Distribution : Public repository; use is governed by the project license76# Security Contact : admin@spboucher.ai77#78# Access to this source does not independently grant permission79# to redistribute or disclose confidential materials.80#81# Do not embed credentials, private keys, access tokens,82# certificates or confidential personal information.83#84# =============================================================================85# LICENSE & MAINTENANCE86# =============================================================================87#88# License : None specified (no license file in this repository)89# Maintainer : Simon-Pierre Boucher90# Technical Contact: dev@spboucher.ai91#92# =============================================================================93# END OF SP BOUCHER SOURCE HEADER94# =============================================================================9596import json97import os98import sys99import time100import urllib.error101import urllib.request102103import jwt # PyJWT104105KEY_ID = os.environ.get("ASC_KEY_ID", "L379BDKR69")106ISSUER = os.environ.get("ASC_ISSUER_ID", "013e761f-e05c-4d93-a50b-f3d960adae4a")107APP = "6839382600" # « Lou-Ka v2 », com.spboucher.louka.v2108VERSION = os.environ.get("LOUKA_VERSION", "3.1.1")109110111def token():112 key = open(os.path.expanduser(f"~/.appstoreconnect/private_keys/AuthKey_{KEY_ID}.p8")).read()113 now = int(time.time())114 return jwt.encode({"iss": ISSUER, "iat": now, "exp": now + 900, "aud": "appstoreconnect-v1"}, key,115 algorithm="ES256", headers={"kid": KEY_ID})116117118def call(method, path, body=None):119 req = urllib.request.Request("https://api.appstoreconnect.apple.com" + path, method=method,120 data=json.dumps(body).encode() if body else None,121 headers={"Authorization": "Bearer " + token(), "Content-Type": "application/json"})122 try:123 with urllib.request.urlopen(req, timeout=40) as r:124 return r.status, json.loads(r.read() or b"{}")125 except urllib.error.HTTPError as e:126 return e.code, json.loads(e.read() or b"{}")127128129def build(number=None):130 q = f"/v1/builds?filter[app]={APP}&filter[preReleaseVersion.version]={VERSION}&sort=-uploadedDate&limit=5"131 if number:132 q += f"&filter[version]={number}"133 s, j = call("GET", q)134 data = j.get("data", [])135 return data[0] if data else None136137138def groups():139 s, j = call("GET", f"/v1/apps/{APP}/betaGroups?fields[betaGroups]=name,isInternalGroup,hasAccessToAllBuilds&limit=50")140 return j.get("data", [])141142143def describe(b):144 a = b["attributes"]145 return f"{b['id']} {VERSION} ({a['version']}) {a['processingState']} chiffrement={a.get('usesNonExemptEncryption')} iOS min={a.get('minOsVersion')} expire={a.get('expirationDate')}"146147148def main():149 cmd = sys.argv[1] if len(sys.argv) > 1 else "build"150 number = sys.argv[2] if len(sys.argv) > 2 else None151 if cmd == "build":152 b = build(number)153 print(describe(b) if b else f"aucun build {VERSION} {number or ''}")154 return 0 if b else 1155 if cmd == "wait":156 # le build apparaît quelques minutes après l'envoi, puis passe de PROCESSING à VALID157 for _ in range(90):158 b = build(number)159 state = b["attributes"]["processingState"] if b else "pas encore visible"160 print(time.strftime("%H:%M:%S"), state, flush=True)161 if state in ("VALID", "INVALID", "FAILED"):162 return 0 if state == "VALID" else 1163 time.sleep(20)164 return 1165 if cmd == "group":166 b = build(number)167 if not b:168 print("aucun build à rattacher")169 return 1170 internal = [g for g in groups() if g["attributes"]["isInternalGroup"]]171 if not internal:172 print("aucun groupe interne pour cette app")173 return 1174 for g in internal:175 a = g["attributes"]176 if a.get("hasAccessToAllBuilds"):177 print(f"groupe interne « {a['name']} » : accès à tous les builds, rien à rattacher")178 continue179 s, j = call("POST", f"/v1/betaGroups/{g['id']}/relationships/builds", {"data": [{"type": "builds", "id": b["id"]}]})180 print(f"groupe interne « {a['name']} » : build rattaché" if s < 300 else f"rattachement refusé : {s} {json.dumps(j, ensure_ascii=False)[:400]}")181 return 0182 if cmd == "status":183 b = build(number)184 if not b:185 print(f"aucun build {VERSION} {number or ''}")186 return 1187 print(describe(b))188 s, j = call("GET", f"/v1/builds/{b['id']}/buildBetaDetail")189 d = j.get("data", {}).get("attributes", {})190 print("test interne :", d.get("internalBuildState"), "| test externe :", d.get("externalBuildState"))191 s, j = call("GET", f"/v1/builds/{b['id']}/betaAppReviewSubmission")192 print("revue bêta :", (j.get("data") or {}).get("attributes", {}).get("betaReviewState", "aucune soumission"))193 for g in groups():194 a = g["attributes"]195 s, j = call("GET", f"/v1/betaGroups/{g['id']}/builds?limit=200&fields[builds]=version")196 has = any(x["id"] == b["id"] for x in j.get("data", []))197 s, t = call("GET", f"/v1/betaGroups/{g['id']}/betaTesters?limit=50")198 print(f"groupe « {a['name']} » ({'interne' if a['isInternalGroup'] else 'externe'}) : "199 f"{'tous les builds' if a.get('hasAccessToAllBuilds') else ('ce build y est' if has else 'ce build n\'y est pas')}, {len(t.get('data', []))} testeur(s)")200 return 0201 print("usage: asc.py build [numéro] | wait [numéro] | group [numéro] | status [numéro]")202 return 2203204205if __name__ == "__main__":206 sys.exit(main())207