From 668d27eae9c7f3b4bd07b2a0b1a934231c774d16 Mon Sep 17 00:00:00 2001 From: Jackson Sui Date: Thu, 28 Dec 2023 10:35:11 -0800 Subject: [PATCH] Adds an iOS GitHub actions test. PiperOrigin-RevId: 594279952 --- .github/workflows/build.yaml | 43 ++++++++++++++++++++++++++++ .github/workflows/build/build.sh | 30 +++++++++++++++++++ .github/workflows/build/ios_build.sh | 29 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100755 .github/workflows/build/ios_build.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 47c9428..74d185e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/build/build.sh b/.github/workflows/build/build.sh index ebb1335..7462bd8 100755 --- a/.github/workflows/build/build.sh +++ b/.github/workflows/build/build.sh @@ -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 diff --git a/.github/workflows/build/ios_build.sh b/.github/workflows/build/ios_build.sh new file mode 100755 index 0000000..8ee3fc7 --- /dev/null +++ b/.github/workflows/build/ios_build.sh @@ -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