Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/objective-c-xcode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Xcode - Build and Analyze

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
name: Build and analyse default scheme using xcodebuild command
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Default Scheme
run: |
scheme_list=$(xcodebuild -list -json | tr -d "\n")
default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]")
echo $default | cat >default
echo Using default scheme: $default
Comment thread
wvnr5m6h4r-commits marked this conversation as resolved.
- name: Build
env:
scheme: ${{ 'default' }}
run: |
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild clean build analyze -scheme "$scheme" -"$filetype_parameter" "$file_to_build" | xcpretty && exit ${PIPESTATUS[0]}
Comment on lines +27 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Quote variables and simplify the workspace/project detection.

$scheme and $file_to_build are unquoted, risking word-splitting on paths with spaces. The one-liner on line 28 is hard to parse and will silently pick the first match if multiple .xcworkspace or .xcodeproj files exist.

🛡️ Proposed fix
         run: |
-          if [ $scheme = default ]; then scheme=$(cat default); fi
-          if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
-          file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
-          xcodebuild clean build analyze -scheme "$scheme" -"$filetype_parameter" "$file_to_build" | xcpretty && exit ${PIPESTATUS[0]}
+          if [ "$scheme" = "default" ]; then scheme=$(cat default); fi
+          if [ -n "$(ls -A | grep -i '\.xcworkspace$')" ]; then
+            filetype_parameter="workspace"
+            file_to_build="$(ls -A | grep -i '\.xcworkspace$' | head -1)"
+          else
+            filetype_parameter="project"
+            file_to_build="$(ls -A | grep -i '\.xcodeproj$' | head -1)"
+          fi
+          file_to_build="$(echo "$file_to_build" | awk '{$1=$1;print}')"
+          xcodebuild clean build analyze -scheme "$scheme" -"$filetype_parameter" "$file_to_build" | xcpretty && exit ${PIPESTATUS[0]}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild clean build analyze -scheme "$scheme" -"$filetype_parameter" "$file_to_build" | xcpretty && exit ${PIPESTATUS[0]}
if [ "$scheme" = "default" ]; then scheme=$(cat default); fi
if [ -n "$(ls -A | grep -i '\.xcworkspace$')" ]; then
filetype_parameter="workspace"
file_to_build="$(ls -A | grep -i '\.xcworkspace$' | head -1)"
else
filetype_parameter="project"
file_to_build="$(ls -A | grep -i '\.xcodeproj$' | head -1)"
fi
file_to_build="$(echo "$file_to_build" | awk '{$1=$1;print}')"
xcodebuild clean build analyze -scheme "$scheme" -"$filetype_parameter" "$file_to_build" | xcpretty && exit ${PIPESTATUS[0]}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/objective-c-xcode.yml around lines 27 - 30, In the
workflow’s scheme and build-file selection logic, quote all variable expansions,
especially in the `if` test and `file_to_build` handling, to preserve paths
containing spaces. Replace the dense workspace/project detection command with
clear, readable logic that explicitly selects the intended `.xcworkspace` or
`.xcodeproj` and fails when multiple or no matches exist; update the
`xcodebuild` invocation to use the quoted variables.