From b7085aaecaf623c4beb6c49ea61d5bbb60324215 Mon Sep 17 00:00:00 2001 From: mahee96 <47920326+mahee96@users.noreply.github.com> Date: Tue, 24 Feb 2026 18:54:41 +0530 Subject: [PATCH] ci: improve speed by caching brew install step and reading project settings from dumped xcodebuild -showProjectSettings instead of invoking each time. --- .github/workflows/alpha.yml | 17 ++++++++++--- .github/workflows/nightly.yml | 18 +++++++++++--- scripts/ci/generate_source_metadata.py | 1 - scripts/ci/workflow.py | 33 +++++++++++++++++++------- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 61a96900..ef7734b6 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -23,7 +23,17 @@ jobs: submodules: recursive fetch-depth: 0 - - run: brew install ldid xcbeautify + - uses: actions/cache@v4 + with: + path: | + /opt/homebrew/Cellar + /opt/homebrew/Homebrew + /opt/homebrew/Library + ~/Library/Caches/Homebrew + key: brew-${{ runner.os }}-ldid-xcbeautify-v1 + - run: | + brew list ldid >/dev/null 2>&1 || brew install ldid + brew list xcbeautify >/dev/null 2>&1 || brew install xcbeautify # -------------------------------------------------- # runtime env setup @@ -176,8 +186,9 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - PRODUCT_NAME=$(python3 scripts/ci/workflow.py get-product-name) - BUNDLE_ID=$(python3 scripts/ci/workflow.py get-bundle-id) + python3 scripts/ci/workflow.py dump-project-settings + PRODUCT_NAME=$(python3 scripts/ci/workflow.py read-product-name) + BUNDLE_ID=$(python3 scripts/ci/workflow.py read-bundle-id) SOURCE_JSON="_includes/source.json" IPA_NAME="$PRODUCT_NAME.ipa" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 19e8aeee..704c688e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -25,7 +25,18 @@ jobs: submodules: recursive fetch-depth: 0 - - run: brew install ldid xcbeautify + - uses: actions/cache@v4 + with: + path: | + /opt/homebrew/Cellar + /opt/homebrew/Homebrew + /opt/homebrew/Library + ~/Library/Caches/Homebrew + key: brew-${{ runner.os }}-ldid-xcbeautify-v1 + + - run: | + brew list ldid >/dev/null 2>&1 || brew install ldid + brew list xcbeautify >/dev/null 2>&1 || brew install xcbeautify # -------------------------------------------------- # runtime env setup @@ -178,8 +189,9 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - PRODUCT_NAME=$(python3 scripts/ci/workflow.py get-product-name) - BUNDLE_ID=$(python3 scripts/ci/workflow.py get-bundle-id) + python3 scripts/ci/workflow.py dump-project-settings + PRODUCT_NAME=$(python3 scripts/ci/workflow.py read-product-name) + BUNDLE_ID=$(python3 scripts/ci/workflow.py read-bundle-id) SOURCE_JSON="_includes/source.json" IPA_NAME="$PRODUCT_NAME.ipa" diff --git a/scripts/ci/generate_source_metadata.py b/scripts/ci/generate_source_metadata.py index c1e897e5..bea03b76 100644 --- a/scripts/ci/generate_source_metadata.py +++ b/scripts/ci/generate_source_metadata.py @@ -5,7 +5,6 @@ import json import subprocess from pathlib import Path import argparse -import textwrap import sys SCRIPT_DIR = Path(__file__).resolve().parent diff --git a/scripts/ci/workflow.py b/scripts/ci/workflow.py index eeb3f3e6..235f3103 100644 --- a/scripts/ci/workflow.py +++ b/scripts/ci/workflow.py @@ -6,12 +6,12 @@ import datetime from pathlib import Path import time import json -import inspect import re # REPO ROOT relative to script dir ROOT = Path(__file__).resolve().parents[2] SCRIPTS = ROOT / 'scripts/ci' +BUILD_SETTINGS_OUTFILE = "project-build-settings.txt" # ---------------------------------------------------------- # helpers @@ -127,23 +127,35 @@ def reserve_build_number(repo, max_attempts=5): # ---------------------------------------------------------- # PROJECT INFO # ---------------------------------------------------------- +def dump_project_settings(outdir=None): + outfile = Path(outdir).resolve() / BUILD_SETTINGS_OUTFILE if outdir else BUILD_SETTINGS_OUTFILE + run(f"xcodebuild -showBuildSettings 2>&1 > '{outfile}'") -def get_product_name(): - return runAndGet( - "xcodebuild -showBuildSettings " - "| grep PRODUCT_NAME " +def _extract_setting(cmd): + out = runAndGet(cmd + " || true").strip() # prevent grep failure from aborting + return out if out else None + +def _read_dumped_build_setting(name): + return _extract_setting( + f"cat '{BUILD_SETTINGS_OUTFILE}' " + f"| grep '{name} = ' " "| tail -1 " "| sed -e 's/.*= //g'" ) -def get_bundle_id(): - return runAndGet( - "xcodebuild -showBuildSettings 2>&1 " - "| grep 'PRODUCT_BUNDLE_IDENTIFIER = ' " +def query_build_setting(name): + return _extract_setting( + f"xcodebuild -showBuildSettings 2>&1 " + f"| grep '{name} = ' " "| tail -1 " "| sed -e 's/.*= //g'" ) +def get_product_name(): return query_build_setting("PRODUCT_NAME") +def get_bundle_id(): return query_build_setting("PRODUCT_BUNDLE_IDENTIFIER") +def read_product_name(): return _read_dumped_build_setting("PRODUCT_NAME") +def read_bundle_id(): return _read_dumped_build_setting("PRODUCT_BUNDLE_IDENTIFIER") + def get_marketing_version(): return runAndGet(f"grep MARKETING_VERSION {ROOT}/Build.xcconfig | sed -e 's/MARKETING_VERSION = //g'") @@ -462,6 +474,9 @@ COMMANDS = { "reserve_build_number" : (reserve_build_number, 1, ""), "get-product-name" : (get_product_name, 0, ""), "get-bundle-id" : (get_bundle_id, 0, ""), + "dump-project-settings" : (dump_project_settings, 0, ""), + "read-product-name" : (read_product_name, 0, ""), + "read-bundle-id" : (read_bundle_id, 0, ""), # ---------------------------------------------------------- # CLEAN