Skip to content

Commit 93abb99

Browse files
authored
Add simulator build step to iOS scripts workflow (#3965)
1 parent 08b863b commit 93abb99

File tree

3 files changed

+306
-9
lines changed

3 files changed

+306
-9
lines changed

.github/workflows/scripts-ios.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
paths:
66
- 'scripts/**'
7+
- '.github/workflows/scripts-ios.yml'
78
- 'BUILDING.md'
89
push:
910
branches: [ master ]
@@ -13,19 +14,43 @@ on:
1314
jobs:
1415
build-ios:
1516
runs-on: macos-15 # pinning macos-15 avoids surprises during the cutover window
16-
timeout-minutes: 25 # hard-stop the job after 25 minutes
17+
timeout-minutes: 60 # allow enough time for dependency installs and full build
1718
concurrency: # ensure only one mac build runs at once
1819
group: mac-ci
1920
cancel-in-progress: false # queue new ones instead of canceling in-flight
2021

2122
steps:
2223
- uses: actions/checkout@v4
2324

25+
- name: Ensure CocoaPods tooling
26+
run: |
27+
set -euo pipefail
28+
if ! command -v pod >/dev/null 2>&1; then
29+
sudo gem install cocoapods --no-document
30+
fi
31+
if ! ruby -rrubygems -e "exit(Gem::Specification::find_all_by_name('xcodeproj').empty? ? 1 : 0)"; then
32+
sudo gem install xcodeproj --no-document
33+
fi
34+
pod --version
35+
36+
- name: Restore cn1-binaries cache
37+
uses: actions/cache@v4
38+
with:
39+
path: ../cn1-binaries
40+
key: cn1-binaries-${{ runner.os }}-${{ hashFiles('scripts/setup-workspace.sh') }}
41+
restore-keys: |
42+
cn1-binaries-${{ runner.os }}-
43+
2444
- name: Setup workspace
2545
run: ./scripts/setup-workspace.sh -q -DskipTests
2646
# per-step timeout
27-
timeout-minutes: 15
47+
timeout-minutes: 25
2848

2949
- name: Build iOS port
3050
run: ./scripts/build-ios-port.sh -q -DskipTests
31-
timeout-minutes: 15
51+
timeout-minutes: 25
52+
53+
- name: Build sample iOS app and compile workspace
54+
run: ./scripts/build-ios-app.sh -q -DskipTests
55+
timeout-minutes: 30
56+

scripts/build-ios-app.sh

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
#!/usr/bin/env bash
2+
# Build a sample "Hello Codename One" iOS application using the locally-built Codename One iOS port
3+
set -euo pipefail
4+
5+
bia_log() { echo "[build-ios-app] $1"; }
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
TMPDIR="${TMPDIR:-/tmp}"; TMPDIR="${TMPDIR%/}"
12+
DOWNLOAD_DIR="${TMPDIR%/}/codenameone-tools"
13+
ENV_DIR="$DOWNLOAD_DIR/tools"
14+
EXTRA_MVN_ARGS=("$@")
15+
16+
ENV_FILE="$ENV_DIR/env.sh"
17+
bia_log "Loading workspace environment from $ENV_FILE"
18+
if [ -f "$ENV_FILE" ]; then
19+
# shellcheck disable=SC1090
20+
source "$ENV_FILE"
21+
bia_log "Loaded environment: JAVA_HOME=${JAVA_HOME:-<unset>} JAVA17_HOME=${JAVA17_HOME:-<unset>} MAVEN_HOME=${MAVEN_HOME:-<unset>}"
22+
else
23+
bia_log "Workspace tools not found. Run scripts/setup-workspace.sh before this script." >&2
24+
exit 1
25+
fi
26+
27+
# --- Tool validations ---
28+
if [ -z "${JAVA_HOME:-}" ] || [ ! -x "$JAVA_HOME/bin/java" ]; then
29+
bia_log "JAVA_HOME is not set correctly. Please run scripts/setup-workspace.sh first." >&2
30+
exit 1
31+
fi
32+
if [ -z "${JAVA17_HOME:-}" ] || [ ! -x "$JAVA17_HOME/bin/java" ]; then
33+
bia_log "JAVA17_HOME is not set correctly. Please run scripts/setup-workspace.sh first." >&2
34+
exit 1
35+
fi
36+
if [ -z "${MAVEN_HOME:-}" ] || [ ! -x "$MAVEN_HOME/bin/mvn" ]; then
37+
bia_log "Maven is not available. Please run scripts/setup-workspace.sh first." >&2
38+
exit 1
39+
fi
40+
if ! command -v xcodebuild >/dev/null 2>&1; then
41+
bia_log "xcodebuild not found. Install Xcode command-line tools." >&2
42+
exit 1
43+
fi
44+
if ! command -v pod >/dev/null 2>&1; then
45+
bia_log "CocoaPods (pod) command not found. Install cocoapods before running this script." >&2
46+
exit 1
47+
fi
48+
49+
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
50+
51+
bia_log "Using JAVA_HOME at $JAVA_HOME"
52+
bia_log "Using JAVA17_HOME at $JAVA17_HOME"
53+
bia_log "Using Maven installation at $MAVEN_HOME"
54+
bia_log "Using CocoaPods version $(pod --version 2>/dev/null || echo '<unknown>')"
55+
56+
CN1_VERSION=$(awk -F'[<>]' '/<version>/{print $3; exit}' maven/pom.xml)
57+
bia_log "Detected Codename One version $CN1_VERSION"
58+
59+
WORK_DIR="$TMPDIR/cn1-hello-ios"
60+
rm -rf "$WORK_DIR"; mkdir -p "$WORK_DIR"
61+
62+
GROUP_ID="com.codenameone.examples"
63+
ARTIFACT_ID="hello-codenameone-ios"
64+
MAIN_NAME="HelloCodenameOne"
65+
PACKAGE_NAME="$GROUP_ID"
66+
67+
SOURCE_PROJECT="$REPO_ROOT/Samples/SampleProjectTemplate"
68+
if [ ! -d "$SOURCE_PROJECT" ]; then
69+
bia_log "Source project template not found at $SOURCE_PROJECT" >&2
70+
exit 1
71+
fi
72+
bia_log "Using source project template at $SOURCE_PROJECT"
73+
74+
LOCAL_MAVEN_REPO="${LOCAL_MAVEN_REPO:-$HOME/.m2/repository}"
75+
bia_log "Using local Maven repository at $LOCAL_MAVEN_REPO"
76+
mkdir -p "$LOCAL_MAVEN_REPO"
77+
MAVEN_CMD=(
78+
"$MAVEN_HOME/bin/mvn" -B -ntp
79+
-Dmaven.repo.local="$LOCAL_MAVEN_REPO"
80+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
81+
)
82+
83+
# --- Generate app skeleton ---
84+
bia_log "Generating Codename One application skeleton via codenameone-maven-plugin"
85+
(
86+
cd "$WORK_DIR"
87+
"${MAVEN_CMD[@]}" -q \
88+
com.codenameone:codenameone-maven-plugin:7.0.204:generate-app-project \
89+
-DgroupId="$GROUP_ID" \
90+
-DartifactId="$ARTIFACT_ID" \
91+
-Dversion=1.0-SNAPSHOT \
92+
-DsourceProject="$SOURCE_PROJECT" \
93+
-Dcn1Version="$CN1_VERSION" \
94+
"${EXTRA_MVN_ARGS[@]}"
95+
)
96+
97+
APP_DIR="$WORK_DIR/$ARTIFACT_ID"
98+
[ -d "$APP_DIR" ] || { bia_log "Failed to create Codename One application project" >&2; exit 1; }
99+
[ -f "$APP_DIR/build.sh" ] && chmod +x "$APP_DIR/build.sh"
100+
101+
SETTINGS_FILE="$APP_DIR/common/codenameone_settings.properties"
102+
if [ ! -f "$SETTINGS_FILE" ]; then
103+
bia_log "codenameone_settings.properties not found at $SETTINGS_FILE" >&2
104+
exit 1
105+
fi
106+
107+
set_property() {
108+
local key="$1" value="$2"
109+
if grep -q "^${key}=" "$SETTINGS_FILE"; then
110+
if sed --version >/dev/null 2>&1; then
111+
sed -i -E "s|^${key}=.*$|${key}=${value}|" "$SETTINGS_FILE"
112+
else
113+
sed -i '' -E "s|^${key}=.*$|${key}=${value}|" "$SETTINGS_FILE"
114+
fi
115+
else
116+
printf '\n%s=%s\n' "$key" "$value" >> "$SETTINGS_FILE"
117+
fi
118+
}
119+
120+
set_property "codename1.packageName" "$PACKAGE_NAME"
121+
set_property "codename1.mainName" "$MAIN_NAME"
122+
123+
# Ensure trailing newline
124+
tail -c1 "$SETTINGS_FILE" | read -r _ || echo >> "$SETTINGS_FILE"
125+
126+
PACKAGE_PATH="${PACKAGE_NAME//.//}"
127+
JAVA_DIR="$APP_DIR/common/src/main/java/${PACKAGE_PATH}"
128+
mkdir -p "$JAVA_DIR"
129+
MAIN_FILE="$JAVA_DIR/${MAIN_NAME}.java"
130+
TEMPLATE="$SCRIPT_DIR/templates/HelloCodenameOne.java.tmpl"
131+
if [ ! -f "$TEMPLATE" ]; then
132+
bia_log "Template not found: $TEMPLATE" >&2
133+
exit 1
134+
fi
135+
136+
sed -e "s|@PACKAGE@|$PACKAGE_NAME|g" \
137+
-e "s|@MAIN_NAME@|$MAIN_NAME|g" \
138+
"$TEMPLATE" > "$MAIN_FILE"
139+
140+
bia_log "Wrote main application class to $MAIN_FILE"
141+
142+
# --- Build iOS project ---
143+
DERIVED_DATA_DIR="${TMPDIR}/codenameone-ios-derived"
144+
rm -rf "$DERIVED_DATA_DIR"
145+
mkdir -p "$DERIVED_DATA_DIR"
146+
147+
bia_log "Building iOS Xcode project using Codename One port"
148+
"${MAVEN_CMD[@]}" -q -f "$APP_DIR/pom.xml" package \
149+
-DskipTests \
150+
-Dcodename1.platform=ios \
151+
-Dcodename1.buildTarget=ios-source \
152+
-Dopen=false \
153+
-Dcodenameone.version="$CN1_VERSION" \
154+
"${EXTRA_MVN_ARGS[@]}"
155+
156+
IOS_TARGET_DIR="$APP_DIR/ios/target"
157+
if [ ! -d "$IOS_TARGET_DIR" ]; then
158+
bia_log "iOS target directory not found at $IOS_TARGET_DIR" >&2
159+
exit 1
160+
fi
161+
162+
PROJECT_DIR=""
163+
for candidate in "$IOS_TARGET_DIR"/*-ios-source; do
164+
if [ -d "$candidate" ]; then
165+
PROJECT_DIR="$candidate"
166+
break
167+
fi
168+
done
169+
if [ -z "$PROJECT_DIR" ]; then
170+
bia_log "Failed to locate generated iOS project under $IOS_TARGET_DIR" >&2
171+
find "$IOS_TARGET_DIR" -type d -print >&2 || true
172+
exit 1
173+
fi
174+
175+
bia_log "Found generated iOS project at $PROJECT_DIR"
176+
177+
if [ -f "$PROJECT_DIR/Podfile" ]; then
178+
bia_log "Installing CocoaPods dependencies"
179+
(
180+
cd "$PROJECT_DIR"
181+
if ! pod install --repo-update; then
182+
bia_log "pod install --repo-update failed; retrying without repo update"
183+
pod install
184+
fi
185+
)
186+
else
187+
bia_log "Podfile not found in generated project; skipping pod install"
188+
fi
189+
190+
WORKSPACE=""
191+
for candidate in "$PROJECT_DIR"/*.xcworkspace; do
192+
if [ -d "$candidate" ]; then
193+
WORKSPACE="$candidate"
194+
break
195+
fi
196+
done
197+
if [ -z "$WORKSPACE" ]; then
198+
bia_log "Failed to locate xcworkspace in $PROJECT_DIR" >&2
199+
ls "$PROJECT_DIR" >&2 || true
200+
exit 1
201+
fi
202+
203+
bia_log "Building workspace $WORKSPACE with scheme $MAIN_NAME"
204+
(
205+
cd "$PROJECT_DIR"
206+
xcodebuild \
207+
-workspace "$WORKSPACE" \
208+
-scheme "$MAIN_NAME" \
209+
-sdk iphonesimulator \
210+
-configuration Debug \
211+
-destination 'generic/platform=iOS Simulator' \
212+
-derivedDataPath "$DERIVED_DATA_DIR" \
213+
CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO \
214+
build
215+
)
216+
217+
PRODUCT_APP=""
218+
while IFS= read -r app_path; do
219+
PRODUCT_APP="$app_path"
220+
break
221+
done < <(find "$DERIVED_DATA_DIR" -type d -name '*.app' -print 2>/dev/null)
222+
if [ -n "$PRODUCT_APP" ]; then
223+
bia_log "Successfully built iOS simulator app at $PRODUCT_APP"
224+
fi
225+
226+
if [ -n "${GITHUB_OUTPUT:-}" ]; then
227+
{
228+
echo "workspace=$WORKSPACE"
229+
[ -n "$PRODUCT_APP" ] && echo "app_bundle=$PRODUCT_APP"
230+
} >> "$GITHUB_OUTPUT"
231+
fi
232+
233+
bia_log "iOS workspace build completed successfully"

scripts/setup-workspace.sh

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ DOWNLOAD_DIR="${TMPDIR%/}/codenameone-tools"
2121
ENV_DIR="$DOWNLOAD_DIR/tools"
2222
mkdir -p "$DOWNLOAD_DIR"
2323
mkdir -p "$ENV_DIR"
24-
mkdir -p ../cn1-binaries
25-
CN1_BINARIES="$(cd ../cn1-binaries && pwd -P)"
26-
rm -Rf ../cn1-binaries
24+
CN1_BINARIES_PARENT="$(cd .. && pwd -P)"
25+
CN1_BINARIES="${CN1_BINARIES_PARENT%/}/cn1-binaries"
26+
mkdir -p "$CN1_BINARIES_PARENT"
2727

2828
ENV_FILE="$ENV_DIR/env.sh"
2929

@@ -182,9 +182,48 @@ log "Maven version:"; "$MAVEN_HOME/bin/mvn" -version
182182

183183
PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
184184

185-
log "Cloning cn1-binaries"
186-
rm -Rf "$CN1_BINARIES"
187-
git clone https://github.com/codenameone/cn1-binaries "$CN1_BINARIES"
185+
log "Preparing cn1-binaries checkout"
186+
if [ -d "$CN1_BINARIES/.git" ]; then
187+
log "Found existing cn1-binaries repository at $CN1_BINARIES"
188+
if git -C "$CN1_BINARIES" remote get-url origin >/dev/null 2>&1; then
189+
if git -C "$CN1_BINARIES" fetch --depth=1 origin; then
190+
remote_head=$(git -C "$CN1_BINARIES" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true)
191+
if [ -z "$remote_head" ]; then
192+
current_branch=$(git -C "$CN1_BINARIES" rev-parse --abbrev-ref HEAD 2>/dev/null || true)
193+
if [ -n "$current_branch" ] && [ "$current_branch" != "HEAD" ]; then
194+
remote_head="origin/$current_branch"
195+
else
196+
remote_head="origin/master"
197+
fi
198+
fi
199+
if ! git -C "$CN1_BINARIES" rev-parse --verify "$remote_head" >/dev/null 2>&1; then
200+
if git -C "$CN1_BINARIES" rev-parse --verify origin/main >/dev/null 2>&1; then
201+
remote_head="origin/main"
202+
elif git -C "$CN1_BINARIES" rev-parse --verify origin/master >/dev/null 2>&1; then
203+
remote_head="origin/master"
204+
else
205+
log "Unable to determine remote head for cached cn1-binaries; removing checkout"
206+
rm -rf "$CN1_BINARIES"
207+
fi
208+
fi
209+
if [ -d "$CN1_BINARIES/.git" ]; then
210+
log "Updating cn1-binaries to $remote_head"
211+
git -C "$CN1_BINARIES" reset --hard "$remote_head"
212+
fi
213+
else
214+
log "Failed to fetch updates for cached cn1-binaries; removing checkout"
215+
rm -rf "$CN1_BINARIES"
216+
fi
217+
else
218+
log "Cached cn1-binaries checkout missing origin remote; removing"
219+
rm -rf "$CN1_BINARIES"
220+
fi
221+
fi
222+
223+
if [ ! -d "$CN1_BINARIES/.git" ]; then
224+
log "Cloning cn1-binaries"
225+
git clone --depth=1 --filter=blob:none https://github.com/codenameone/cn1-binaries "$CN1_BINARIES"
226+
fi
188227

189228
log "Building Codename One core modules"
190229
"$MAVEN_HOME/bin/mvn" -f maven/pom.xml -DskipTests -Djava.awt.headless=true -Dcn1.binaries="$CN1_BINARIES" -Dcodename1.platform=javase -P local-dev-javase,compile-android install "$@"

0 commit comments

Comments
 (0)