|
| 1 | +name: _build |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + product: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + platform: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + method: |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + sanitizers: |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + description: "Space-separated list of sanitizers (asan, tsan, ubsan)" |
| 22 | + setup_command: |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + description: "Command to run before build (e.g., for setting up secrets or prerequisites)" |
| 26 | + xcode: |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + default: 'Xcode_16.4' |
| 30 | + os: |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + default: 'macos-15' |
| 34 | + timeout_minutes: |
| 35 | + required: false |
| 36 | + type: number |
| 37 | + default: 120 |
| 38 | + max_attempts: |
| 39 | + required: false |
| 40 | + type: number |
| 41 | + default: 3 |
| 42 | + |
| 43 | + # IMPORTANT: When adding new secrets to this workflow, update the |
| 44 | + # 'has_secrets' logic in the 'check_secrets' job to include the new secret. |
| 45 | + secrets: |
| 46 | + plist_secret: |
| 47 | + required: false |
| 48 | + |
| 49 | +jobs: |
| 50 | + check_secrets: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + outputs: |
| 53 | + should_run: ${{ steps.determine_run.outputs.should_run }} |
| 54 | + has_secrets: ${{ steps.determine_run.outputs.has_secrets }} |
| 55 | + env: |
| 56 | + plist_secret: ${{ secrets.plist_secret }} |
| 57 | + steps: |
| 58 | + - name: Determine if build should run and if secrets are present |
| 59 | + id: determine_run |
| 60 | + run: | |
| 61 | + # 1. Check for secrets. |
| 62 | + # - IMPORTANT: Extend this logic if adding new secrets. |
| 63 | + if [[ -n "$plist_secret" ]]; then |
| 64 | + has_secrets="true" |
| 65 | + else |
| 66 | + has_secrets="false" |
| 67 | + fi |
| 68 | + echo "has_secrets=$has_secrets" >> $GITHUB_OUTPUT |
| 69 | +
|
| 70 | + # 2. Determine if the build job should run. |
| 71 | + # - Skip if on a fork AND secrets are present. |
| 72 | + repo_full_name=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') |
| 73 | + if [[ "$repo_full_name" != "firebase/firebase-ios-sdk" && "$has_secrets" == "true" ]]; then |
| 74 | + echo "should_run=false" >> $GITHUB_OUTPUT |
| 75 | + else |
| 76 | + echo "should_run=true" >> $GITHUB_OUTPUT |
| 77 | + fi |
| 78 | +
|
| 79 | + build: |
| 80 | + needs: check_secrets |
| 81 | + # Run on the main repo's scheduled jobs or pull requests and manual workflow invocations. |
| 82 | + if: | |
| 83 | + needs.check_secrets.outputs.should_run == 'true' && |
| 84 | + ( |
| 85 | + (github.repository == 'firebase/firebase-ios-sdk' && github.event_name == 'schedule') || |
| 86 | + contains(fromJSON('["pull_request", "workflow_dispatch"]'), github.event_name) |
| 87 | + ) |
| 88 | + runs-on: ${{ inputs.os }} |
| 89 | + env: |
| 90 | + SANITIZERS: ${{ inputs.sanitizers }} |
| 91 | + plist_secret: ${{ secrets.plist_secret }} |
| 92 | + FIREBASECI_SECRETS_PRESENT: ${{ needs.check_secrets.outputs.has_secrets }} |
| 93 | + FIREBASECI_IS_TRUSTED_ENV: ${{ github.repository == 'firebase/firebase-ios-sdk' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} |
| 94 | + FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1 |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 97 | + - uses: ruby/setup-ruby@354a1ad156761f5ee2b7b13fa8e09943a5e8d252 # v1 |
| 98 | + if: inputs.method != 'spm' && inputs.method != 'spmbuildonly' && inputs.method != 'cmake' |
| 99 | + - name: Setup Bundler |
| 100 | + if: inputs.method != 'spm' && inputs.method != 'spmbuildonly' && inputs.method != 'cmake' |
| 101 | + uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3 |
| 102 | + with: |
| 103 | + timeout_minutes: 10 |
| 104 | + max_attempts: 5 |
| 105 | + retry_wait_seconds: 300 |
| 106 | + command: scripts/setup_bundler.sh |
| 107 | + - name: Xcode |
| 108 | + run: sudo xcode-select -s /Applications/${{ inputs.xcode }}.app/Contents/Developer |
| 109 | + - name: Install simulators |
| 110 | + if: inputs.platform != 'macOS' && inputs.platform != 'catalyst' |
| 111 | + uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3 |
| 112 | + with: |
| 113 | + timeout_minutes: 15 |
| 114 | + max_attempts: 5 |
| 115 | + retry_wait_seconds: 120 |
| 116 | + continue_on_error: true |
| 117 | + command: | |
| 118 | + if [[ "${{ inputs.platform }}" == "all" ]]; then |
| 119 | + xcodebuild -downloadAllPlatforms |
| 120 | + else |
| 121 | + xcodebuild -downloadPlatform ${{ inputs.platform }} |
| 122 | + fi |
| 123 | + - name: Run setup command |
| 124 | + if: inputs.setup_command != '' |
| 125 | + run: ${{ inputs.setup_command }} |
| 126 | + - name: Build |
| 127 | + uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3 |
| 128 | + with: |
| 129 | + timeout_minutes: ${{ inputs.timeout_minutes }} |
| 130 | + max_attempts: ${{ inputs.max_attempts }} |
| 131 | + retry_wait_seconds: 120 |
| 132 | + command: | |
| 133 | + scripts/build.sh "${{ inputs.product }}" "${{ inputs.platform }}" "${{ inputs.method }}" |
| 134 | + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 135 | + if: ${{ failure() }} |
| 136 | + with: |
| 137 | + name: xcodebuild-logs-${{ inputs.product }}-${{ inputs.platform }}-${{ inputs.method }} |
| 138 | + path: xcodebuild-*.log |
| 139 | + if-no-files-found: error |
0 commit comments