Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 8e003af

Browse files
authored
Refactor Xcode project generation with local build
Updated the Xcode project generation process to force local builds and override Homebrew bottle issues. Enhanced diagnostics and error handling for xcodegen execution.
1 parent 2d74669 commit 8e003af

1 file changed

Lines changed: 73 additions & 61 deletions

File tree

.github/workflows/build-unsigned-ipa.yml

Lines changed: 73 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -90,88 +90,100 @@ jobs:
9090
echo "project.yml (first 200 lines):"
9191
sed -n '1,200p' project.yml || true
9292
93-
- name: Generate Xcode Project (robust + diagnostics)
93+
- name: Generate Xcode Project (force local build + override Homebrew bottle)
9494
shell: /bin/bash {0}
9595
run: |
9696
set -euo pipefail
9797
98-
echo "=== diagnostic: PATH and which xcodegen ==="
98+
echo "=== diagnostics: PATH + which xcodegen ==="
9999
echo "PATH=$PATH"
100100
which xcodegen || true
101-
101+
xcodegen --version 2>/dev/null || true
102102
if command -v xcodegen >/dev/null 2>&1; then
103-
echo "=== xcodegen --version ==="
104-
xcodegen --version || true
105-
106-
echo "=== file info for xcodegen binary (arch info) ==="
103+
echo "xcodegen binary:"
107104
file "$(command -v xcodegen)" || true
108-
else
109-
echo "xcodegen not found — attempting to install via brew"
110-
if command -v brew >/dev/null 2>&1; then
111-
brew update || true
112-
brew install xcodegen || true
113-
fi
105+
spctl --assess -vv "$(command -v xcodegen)" 2>&1 || true
106+
xattr -l "$(command -v xcodegen)" 2>/dev/null || true
114107
fi
115108
116-
echo "=== running xcodegen generate --spec project.yml ==="
109+
echo "=== Attempt fast path: run preinstalled xcodegen ==="
117110
set +e
118111
xcodegen generate --spec project.yml
119112
rc=$?
120113
set -e
121114
122-
if [ $rc -ne 0 ]; then
123-
echo "❌ xcodegen exited with code $rc — collecting diagnostics..."
124-
125-
echo "---- macOS unified log for xcodegen (last 5m) ----"
126-
# safer predicate: search event messages for xcodegen (best-effort)
127-
log show --style syslog --predicate 'eventMessage CONTAINS "xcodegen"' --last 5m || true
115+
if [ $rc -eq 0 ]; then
116+
echo "✅ Fast path succeeded (preinstalled xcodegen)."
117+
sed -n '1,60p' prostore.xcodeproj/project.pbxproj || true
118+
exit 0
119+
fi
128120
129-
echo "---- Recent DiagnosticReports (possible crash logs) ----"
130-
ls -la ~/Library/Logs/DiagnosticReports | tail -n 20 || true
121+
echo "⚠️ Fast path failed (rc=$rc). Checking for AMFI/CT issues..."
131122
132-
echo "---- /var/log/system.log (tail) ----"
133-
sudo tail -n 200 /var/log/system.log || true
123+
# show kernel/AMFI lines for quick signal
124+
echo "---- recent AMFI / kernel messages (best-effort) ----"
125+
log show --style syslog --last 5m 2>/dev/null | egrep -i "AMFI|CodeSigning|CT|xcodegen" || true
134126
135-
if command -v brew >/dev/null 2>&1; then
136-
echo "Attempting: brew reinstall xcodegen (then retry once)..."
137-
brew reinstall xcodegen || brew install xcodegen || true
138-
139-
echo "Retrying xcodegen generate --spec project.yml (one retry)..."
140-
set +e
141-
xcodegen generate --spec project.yml
142-
retry_rc=$?
143-
set -e
144-
145-
if [ $retry_rc -eq 0 ]; then
146-
echo "✅ xcodegen succeeded on retry."
147-
echo "Generated project at: $(pwd)/prostore.xcodeproj"
148-
sed -n '1,60p' prostore.xcodeproj/project.pbxproj || true
149-
exit 0
150-
else
151-
echo "❌ Retry failed with exit code $retry_rc."
152-
fi
153-
fi
127+
# If Homebrew xcodegen is present, aggressively remove it to avoid re-using the bottle
128+
if command -v brew >/dev/null 2>&1 && command -v xcodegen >/dev/null 2>&1; then
129+
echo "Removing Homebrew xcodegen (to avoid poisoned bottle)…"
130+
brew uninstall --force xcodegen || true
131+
brew cleanup -s xcodegen || true
132+
fi
154133
155-
echo ""
156-
echo "Possible causes:"
157-
echo "- xcodegen invocation failed due to invalid flag or spec syntax (we removed the bad flag)."
158-
echo "- Architecture mismatch (xcodegen is ARM vs expecting x86_64) — unlikely now since binary is arm64."
159-
echo "- Corrupt install or runner environment oddness."
160-
echo ""
161-
echo "Quick checks you can find in the logs above:"
162-
echo " file $(which xcodegen) # binary arch"
163-
echo " xcodegen --version"
164-
echo ""
165-
echo "If you still hit issues, try:"
166-
echo " - Forcing x86_64: arch -x86_64 xcodegen generate --spec project.yml (only if Rosetta is available)"
167-
echo " - Switching runner image: runs-on: macos-latest (or macos-12)"
168-
echo ""
169-
exit $rc
134+
echo "Preparing to build XcodeGen from source (this bypasses bottle CT/AMFI issues)."
135+
mkdir -p "$HOME/.local/bin"
136+
TMPDIR=$(mktemp -d)
137+
echo "Cloning XcodeGen into $TMPDIR..."
138+
git clone --depth 1 https://github.com/yonaskolb/XcodeGen.git "$TMPDIR/XcodeGen" || { echo "git clone failed"; exit 20; }
139+
cd "$TMPDIR/XcodeGen"
140+
141+
echo "Swift toolchain:"
142+
swift --version || true
143+
144+
echo "Building xcodegen (swift build -c release)... this may take ~30-90s"
145+
# build for the runner architecture
146+
swift build -c release || { echo "swift build failed"; exit 21; }
147+
148+
BUILT_BIN="$(pwd)/.build/release/xcodegen"
149+
if [ ! -f "$BUILT_BIN" ]; then
150+
echo "ERROR: built binary not found at $BUILT_BIN"
151+
ls -la ./.build || true
152+
exit 22
170153
fi
171154
172-
echo "✅ Generated project at: $(pwd)/prostore.xcodeproj"
173-
echo "project.pbxproj header (first 60 lines):"
174-
sed -n '1,60p' prostore.xcodeproj/project.pbxproj || true
155+
echo "Installing built xcodegen to \$HOME/.local/bin"
156+
cp "$BUILT_BIN" "$HOME/.local/bin/xcodegen"
157+
chmod +x "$HOME/.local/bin/xcodegen"
158+
export PATH="$HOME/.local/bin:$PATH"
159+
160+
echo "Sanity check: which xcodegen -> $(which xcodegen)"
161+
file "$(which xcodegen)" || true
162+
spctl --assess -vv "$(which xcodegen)" 2>&1 || true
163+
xattr -l "$(which xcodegen)" 2>/dev/null || true
164+
165+
echo "Running xcodegen generate --spec project.yml with local-built binary..."
166+
set +e
167+
xcodegen generate --spec project.yml
168+
final_rc=$?
169+
set -e
170+
171+
if [ $final_rc -eq 0 ]; then
172+
echo "✅ Success: generated project using locally built xcodegen."
173+
sed -n '1,60p' prostore.xcodeproj/project.pbxproj || true
174+
exit 0
175+
else
176+
echo "❌ Failure even after building from source (rc=$final_rc). Dumping diagnostics:"
177+
echo "spctl --assess output for built binary:"
178+
spctl --assess -vv "$HOME/.local/bin/xcodegen" 2>&1 || true
179+
echo "xattr for built binary:"
180+
xattr -l "$HOME/.local/bin/xcodegen" 2>/dev/null || true
181+
echo "ls -la $HOME/.local/bin:"
182+
ls -la "$HOME/.local/bin" || true
183+
echo "Recent log grep (AMFI/CodeSigning/xcodegen):"
184+
log show --style syslog --last 10m 2>/dev/null | egrep -i "AMFI|CodeSigning|xcodegen" || true
185+
exit $final_rc
186+
fi
175187
176188
- name: Resolve Swift Packages
177189
run: |

0 commit comments

Comments
 (0)