Skip to content

Commit

Permalink
Adds an iOS GitHub actions test.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 594279952
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Dec 28, 2023
1 parent d0fa4bf commit 668d27e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,46 @@ jobs:
env:
COMMIT_RANGE: ${{ env.COMMIT_RANGE }}
REGEX: ${{ matrix.regex }}

# Step 3: Build iOS sample
build:
name: Build
runs-on: macOS-latest
strategy:
fail-fast: false
matrix:
regex:
# copybara:strip_begin
# LINT.IfChange
# copybara:strip_end
- "ios"
# copybara:strip_begin
# LINT.ThenChange(//depot/google3/googlemac/iPhone/InteractiveMediaAds/IMA/ios/samples/clientSide/copy.bara.sky)
# copybara:strip_end
steps:
- name: Clone Repository
uses: actions/checkout@v1

- name: Xcode version
run: /usr/bin/xcodebuild -version

- name: Pod repo update
run: pod repo update

- name: Install xcpretty
run: sudo gem install xcpretty

- name: Set commit range (push to the main branch, for example, merge)
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: echo "COMMIT_RANGE="${{ github.event.before }}.."" >> $GITHUB_ENV

- name: Set commit range (pull request)
if: github.event_name == 'pull_request'
run: echo "COMMIT_RANGE="HEAD~.."" >> $GITHUB_ENV

- name: Build
run: .github/workflows/build/ios_build.sh
shell: bash
env:
COMMIT_RANGE: ${{ env.COMMIT_RANGE }}
REGEX: ${{ matrix.regex }}
30 changes: 30 additions & 0 deletions .github/workflows/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ do
popd;
fi
done

#!/bin/bash
# Script to build iOS sample app (Objective-C or Swift)
# $REGEX variable, using build.sh script.

set -eo pipefail

# An array that holds the google3 path to each example app
EXAMPLE_APPS_PATHS_ARRAY=()

while read -r line; do
app_path=$(dirname "${line}");
EXAMPLE_APPS_PATHS_ARRAY+=("${app_path#./}");
done < <(find . -name Podfile -type f -d | grep -E "${REGEX}")

for example_app_path in "${EXAMPLE_APPS_PATHS_ARRAY[@]}"
do
CHANGES="$(git --no-pager diff --name-only "${COMMIT_RANGE}")";
echo "Project dir: ${example_app_path}";
if [[ -n "$(grep -E "(${example_app_path}|\.github\/workflows)" <<< "${CHANGES}")" ]]; then
echo "Building for ${example_app_path}";
example_name=$(echo "${example_app_path}" | xargs -I{} basename {});
echo "::set-output name=building_app::Pod install for App (${example_name})";
pushd "${example_app_path}";
pod install --no-repo-update;
echo "::set-output name=building_app::Building App (${example_name})";
eval "xcodebuild -workspace ${example_name}.xcworkspace -scheme ${example_name} -sdk iphonesimulator -arch x86_64 | xcpretty";
popd;
fi
done
29 changes: 29 additions & 0 deletions .github/workflows/build/ios_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Script to build iOS sample app (Objective-C or Swift)
# $REGEX variable, using ios_build.sh script.

set -eo pipefail

# An array that holds the google3 path to each example app
EXAMPLE_APPS_PATHS_ARRAY=()

while read -r line; do
app_path=$(dirname "${line}");
EXAMPLE_APPS_PATHS_ARRAY+=("${app_path#./}");
done < <(find . -name Podfile -type f -d | grep -E "${REGEX}")

for example_app_path in "${EXAMPLE_APPS_PATHS_ARRAY[@]}"
do
CHANGES="$(git --no-pager diff --name-only "${COMMIT_RANGE}")";
echo "Project dir: ${example_app_path}";
if [[ -n "$(grep -E "(${example_app_path}|\.github\/workflows)" <<< "${CHANGES}")" ]]; then
echo "Building for ${example_app_path}";
example_name=$(echo "${example_app_path}" | xargs -I{} basename {});
echo "::set-output name=building_app::Pod install for App (${example_name})";
pushd "${example_app_path}";
pod install --no-repo-update;
echo "::set-output name=building_app::Building App (${example_name})";
eval "xcodebuild -workspace ${example_name}.xcworkspace -scheme ${example_name} -sdk iphonesimulator -arch x86_64 | xcpretty";
popd;
fi
done

0 comments on commit 668d27e

Please sign in to comment.